|
@@ -4,6 +4,8 @@ import org.hswebframework.web.authorization.Authentication;
|
|
import org.hswebframework.web.authorization.Dimension;
|
|
import org.hswebframework.web.authorization.Dimension;
|
|
import org.hswebframework.web.authorization.Permission;
|
|
import org.hswebframework.web.authorization.Permission;
|
|
import org.hswebframework.web.authorization.events.AuthorizationSuccessEvent;
|
|
import org.hswebframework.web.authorization.events.AuthorizationSuccessEvent;
|
|
|
|
+import org.hswebframework.web.authorization.exception.AccessDenyException;
|
|
|
|
+import org.jetlinks.community.auth.service.UserDetailService;
|
|
import org.springframework.context.event.EventListener;
|
|
import org.springframework.context.event.EventListener;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
@@ -17,16 +19,26 @@ import java.util.stream.Collectors;
|
|
*/
|
|
*/
|
|
@Component
|
|
@Component
|
|
public class LoginEvent {
|
|
public class LoginEvent {
|
|
|
|
+ private final UserDetailService detailService;
|
|
|
|
+
|
|
|
|
+ public LoginEvent(UserDetailService detailService) {
|
|
|
|
+ this.detailService = detailService;
|
|
|
|
+ }
|
|
|
|
+
|
|
@EventListener
|
|
@EventListener
|
|
- public void handleLoginSuccess(AuthorizationSuccessEvent event){
|
|
|
|
|
|
+ public void handleLoginSuccess(AuthorizationSuccessEvent event) {
|
|
Map<String, Object> result = event.getResult();
|
|
Map<String, Object> result = event.getResult();
|
|
Authentication authentication = event.getAuthentication();
|
|
Authentication authentication = event.getAuthentication();
|
|
List<Dimension> dimensions = authentication.getDimensions();
|
|
List<Dimension> dimensions = authentication.getDimensions();
|
|
|
|
|
|
- result.put("permissions",authentication.getPermissions());
|
|
|
|
- result.put("roles",dimensions);
|
|
|
|
- result.put("user",authentication.getUser());
|
|
|
|
- result.put("currentAuthority",authentication.getPermissions().stream().map(Permission::getId).collect(Collectors.toList()));
|
|
|
|
|
|
+ result.put("permissions", authentication.getPermissions());
|
|
|
|
+ result.put("roles", dimensions);
|
|
|
|
+ result.put("currentAuthority", authentication.getPermissions().stream().map(Permission::getId).collect(Collectors.toList()));
|
|
|
|
|
|
|
|
+ event.async(
|
|
|
|
+ detailService
|
|
|
|
+ .findUserDetail(event.getAuthentication().getUser().getId())
|
|
|
|
+ .doOnNext(detail -> result.put("user", detail))
|
|
|
|
+ );
|
|
}
|
|
}
|
|
}
|
|
}
|