|
@@ -39,6 +39,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import java.util.Map;
|
|
import java.util.function.Function;
|
|
import java.util.function.Function;
|
|
|
|
|
|
import static org.hswebframework.web.controller.message.ResponseMessage.ok;
|
|
import static org.hswebframework.web.controller.message.ResponseMessage.ok;
|
|
@@ -61,7 +62,7 @@ public class AuthorizationController {
|
|
// private AuthenticationInitializeService authenticationInitializeService;
|
|
// private AuthenticationInitializeService authenticationInitializeService;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- private AuthenticationManager authenticationManager;
|
|
|
|
|
|
+ private AuthenticationManager authenticationManager;
|
|
@Autowired
|
|
@Autowired
|
|
private AuthorizationListenerDispatcher authorizationListenerDispatcher;
|
|
private AuthorizationListenerDispatcher authorizationListenerDispatcher;
|
|
|
|
|
|
@@ -82,9 +83,9 @@ public class AuthorizationController {
|
|
|
|
|
|
@PostMapping(value = "/login")
|
|
@PostMapping(value = "/login")
|
|
@ApiOperation("用户名密码登录")
|
|
@ApiOperation("用户名密码登录")
|
|
- public ResponseMessage<String> authorize(@RequestParam @ApiParam("用户名") String username,
|
|
|
|
- @RequestParam @ApiParam("密码") String password,
|
|
|
|
- @ApiParam(hidden = true) HttpServletRequest request) {
|
|
|
|
|
|
+ public ResponseMessage<Map<String, Object>> authorize(@RequestParam @ApiParam("用户名") String username,
|
|
|
|
+ @RequestParam @ApiParam("密码") String password,
|
|
|
|
+ @ApiParam(hidden = true) HttpServletRequest request) {
|
|
|
|
|
|
AuthorizationFailedEvent.Reason reason = AuthorizationFailedEvent.Reason.OTHER;
|
|
AuthorizationFailedEvent.Reason reason = AuthorizationFailedEvent.Reason.OTHER;
|
|
Function<String, Object> parameterGetter = request::getParameter;
|
|
Function<String, Object> parameterGetter = request::getParameter;
|
|
@@ -113,11 +114,12 @@ public class AuthorizationController {
|
|
// 验证通过
|
|
// 验证通过
|
|
Authentication authentication = authenticationManager.getByUserId(entity.getId());
|
|
Authentication authentication = authenticationManager.getByUserId(entity.getId());
|
|
AuthorizationSuccessEvent event = new AuthorizationSuccessEvent(authentication, parameterGetter);
|
|
AuthorizationSuccessEvent event = new AuthorizationSuccessEvent(authentication, parameterGetter);
|
|
|
|
+ event.getResult().put("userId", entity.getId());
|
|
int size = authorizationListenerDispatcher.doEvent(event);
|
|
int size = authorizationListenerDispatcher.doEvent(event);
|
|
if (size == 0) {
|
|
if (size == 0) {
|
|
logger.warn("not found any AuthorizationSuccessEvent,access control maybe disabled!");
|
|
logger.warn("not found any AuthorizationSuccessEvent,access control maybe disabled!");
|
|
}
|
|
}
|
|
- return ok(entity.getId());
|
|
|
|
|
|
+ return ok(event.getResult());
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
AuthorizationFailedEvent failedEvent = new AuthorizationFailedEvent(username, password, parameterGetter, reason);
|
|
AuthorizationFailedEvent failedEvent = new AuthorizationFailedEvent(username, password, parameterGetter, reason);
|
|
failedEvent.setException(e);
|
|
failedEvent.setException(e);
|