zhou-hao преди 7 години
родител
ревизия
2842f49d0d

+ 6 - 0
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-controller/src/main/java/org/hswebframework/web/controller/authorization/UserController.java

@@ -19,6 +19,7 @@ package org.hswebframework.web.controller.authorization;
 
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import org.hswebframework.web.AopUtils;
 import org.hswebframework.web.authorization.Authentication;
 import org.hswebframework.web.authorization.Permission;
 import org.hswebframework.web.authorization.annotation.Authorize;
@@ -77,6 +78,11 @@ public class UserController implements
                 .exclude(UserEntity.class, "password", "salt");
     }
 
+    public static void main(String[] args) throws NoSuchMethodException {
+        System.out.println(AopUtils
+                .findMethodAnnotation(UserController.class,UserController.class.getMethod("list",QueryParamEntity.class),Authorize.class));
+    }
+
     @Override
     @SuppressWarnings("all")
     public ResponseMessage<UserEntity> getByPrimaryKey(@PathVariable String id) {

+ 7 - 2
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/events/UserPasswordModifiedEvent.java

@@ -2,6 +2,7 @@ package org.hswebframework.web.service.authorization.events;
 
 import lombok.AllArgsConstructor;
 import lombok.Getter;
+import org.hswebframework.web.entity.authorization.UserEntity;
 
 /**
  * 用户密码发生修改时事件
@@ -13,6 +14,10 @@ import lombok.Getter;
  */
 @AllArgsConstructor
 @Getter
-public class UserPasswordModifiedEvent {
-    private String userId;
+public class UserModifiedEvent {
+    private UserEntity userEntity;
+
+    private boolean passwordModified;
+
+    private boolean roleModified;
 }

+ 12 - 9
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleUserService.java

@@ -15,7 +15,7 @@ import org.hswebframework.web.service.AbstractService;
 import org.hswebframework.web.service.DefaultDSLQueryService;
 import org.hswebframework.web.service.DefaultDSLUpdateService;
 import org.hswebframework.web.service.authorization.*;
-import org.hswebframework.web.service.authorization.events.UserPasswordModifiedEvent;
+import org.hswebframework.web.service.authorization.events.UserModifiedEvent;
 import org.hswebframework.web.validate.ValidationException;
 import org.hswebframework.utils.ListUtils;
 import org.hswebframework.web.validator.group.CreateGroup;
@@ -25,13 +25,13 @@ import org.springframework.cache.annotation.Caching;
 import org.springframework.context.ApplicationEventPublisher;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.Assert;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 
 import java.util.*;
 import java.util.stream.Collectors;
 
+import static org.hswebframework.web.service.DefaultDSLUpdateService.*;
 import static org.hswebframework.web.service.authorization.simple.CacheConstants.USER_AUTH_CACHE_NAME;
 import static org.hswebframework.web.service.authorization.simple.CacheConstants.USER_CACHE_NAME;
 
@@ -172,6 +172,8 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
         userEntity.setId(userId);
         UserEntity oldUser = selectByPk(userId);
         assertNotNull(oldUser);
+        boolean roleModified = false;
+        boolean passwordModified = false;
         //判断用户是否存在
         boolean userExists = createQuery().where()
                 .is(UserEntity.username, userEntity.getUsername())
@@ -186,10 +188,10 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
             //密码MD5
             userEntity.setPassword(encodePassword(userEntity.getPassword(), oldUser.getSalt()));
             updateProperties.add(UserEntity.password);
-
+            passwordModified = true;
         }
         //修改数据
-        DefaultDSLUpdateService.createUpdate(getDao(), userEntity)
+        createUpdate(getDao(), userEntity)
                 .includes(updateProperties.toArray(new String[updateProperties.size()]))
                 .where(GenericEntity.id, userEntity.getId())
                 .exec();
@@ -199,15 +201,16 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
             userRoleDao.deleteByUserId(bindRoleUserEntity.getId());
             //同步角色信息
             trySyncUserRole(userEntity.getId(), bindRoleUserEntity.getRoles());
+            roleModified = true;
         }
         if (updateProperties.contains(UserEntity.password)) {
-            publisher.publishEvent(new UserPasswordModifiedEvent(userId));
+            publisher.publishEvent(new UserModifiedEvent(userEntity, passwordModified, roleModified));
         }
     }
 
     @Override
     public boolean enable(String userId) {
-        return DefaultDSLUpdateService.createUpdate(getDao())
+        return createUpdate(getDao())
                 .set(UserEntity.status, DataStatus.STATUS_ENABLED)
                 .where(GenericEntity.id, userId)
                 .exec() > 0;
@@ -215,7 +218,7 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
 
     @Override
     public boolean disable(String userId) {
-        return DefaultDSLUpdateService.createUpdate(getDao())
+        return createUpdate(getDao())
                 .set(UserEntity.status, DataStatus.STATUS_DISABLED)
                 .where(GenericEntity.id, userId)
                 .exec() > 0;
@@ -232,11 +235,11 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
         tryValidateProperty(passwordStrengthValidator, UserEntity.password, newPassword);
 
         newPassword = encodePassword(newPassword, userEntity.getSalt());
-        DefaultDSLUpdateService.createUpdate(getDao())
+        createUpdate(getDao())
                 .set(UserEntity.password, newPassword)
                 .where(GenericEntity.id, userId)
                 .exec();
-        publisher.publishEvent(new UserPasswordModifiedEvent(userId));
+        publisher.publishEvent(new UserModifiedEvent(userEntity, true, false));
     }