瀏覽代碼

增加用户详情

zhou-hao 4 年之前
父節點
當前提交
68bed142fe

+ 17 - 5
jetlinks-standalone/src/main/java/org/jetlinks/community/standalone/authorize/LoginEvent.java

@@ -4,6 +4,8 @@ import org.hswebframework.web.authorization.Authentication;
 import org.hswebframework.web.authorization.Dimension;
 import org.hswebframework.web.authorization.Permission;
 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.stereotype.Component;
 
@@ -17,16 +19,26 @@ import java.util.stream.Collectors;
  */
 @Component
 public class LoginEvent {
+    private final UserDetailService detailService;
+
+    public LoginEvent(UserDetailService detailService) {
+        this.detailService = detailService;
+    }
+
     @EventListener
-    public void handleLoginSuccess(AuthorizationSuccessEvent event){
+    public void handleLoginSuccess(AuthorizationSuccessEvent event) {
         Map<String, Object> result = event.getResult();
         Authentication authentication = event.getAuthentication();
         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))
+        );
     }
 }