mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-06-02 10:57:49 +08:00
优化验证逻辑
This commit is contained in:
@@ -26,7 +26,9 @@ import org.hswebframework.web.controller.message.ResponseMessage;
|
||||
import org.hswebframework.web.logging.AccessLogger;
|
||||
import org.hswebframework.web.service.CreateEntityService;
|
||||
import org.hswebframework.web.service.InsertService;
|
||||
import org.hswebframework.web.validator.group.CreateGroup;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
@@ -40,6 +40,11 @@
|
||||
<artifactId>hsweb-easy-orm-rdb</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hswebframework.web</groupId>
|
||||
<artifactId>hsweb-boost-validator-group</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hswebframework</groupId>
|
||||
<artifactId>hsweb-utils</artifactId>
|
||||
|
||||
@@ -20,7 +20,6 @@ package org.hswebframework.web.controller.authorization;
|
||||
import org.hswebframework.web.authorization.Permission;
|
||||
import org.hswebframework.web.authorization.annotation.Authorize;
|
||||
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
|
||||
import org.hswebframework.web.controller.GenericEntityController;
|
||||
import org.hswebframework.web.controller.SimpleGenericEntityController;
|
||||
import org.hswebframework.web.controller.message.ResponseMessage;
|
||||
import org.hswebframework.web.entity.authorization.AuthorizationSettingEntity;
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.hswebframework.web.controller.message.ResponseMessage;
|
||||
import org.hswebframework.web.entity.authorization.MenuEntity;
|
||||
import org.hswebframework.web.entity.authorization.UserMenuEntity;
|
||||
import org.hswebframework.web.logging.AccessLogger;
|
||||
import org.hswebframework.web.service.authorization.MenuGroupService;
|
||||
import org.hswebframework.web.service.authorization.MenuService;
|
||||
import org.hswebframework.web.service.authorization.UserMenuManagerService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
*/
|
||||
package org.hswebframework.web.entity.authorization;
|
||||
|
||||
import org.hibernate.validator.constraints.NotBlank;
|
||||
import org.hswebframework.web.commons.entity.GenericEntity;
|
||||
import org.hswebframework.web.validator.group.CreateGroup;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -57,6 +59,7 @@ public interface AuthorizationSettingDetailEntity extends GenericEntity<String>,
|
||||
/**
|
||||
* @return 权限id
|
||||
*/
|
||||
@NotBlank(groups = CreateGroup.class)
|
||||
String getPermissionId();
|
||||
|
||||
/**
|
||||
@@ -67,6 +70,7 @@ public interface AuthorizationSettingDetailEntity extends GenericEntity<String>,
|
||||
/**
|
||||
* @return 设置id
|
||||
*/
|
||||
@NotBlank(groups = CreateGroup.class)
|
||||
String getSettingId();
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
*/
|
||||
package org.hswebframework.web.entity.authorization;
|
||||
|
||||
import org.hibernate.validator.constraints.NotBlank;
|
||||
import org.hswebframework.web.commons.entity.GenericEntity;
|
||||
import org.hswebframework.web.validator.group.CreateGroup;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -49,6 +51,7 @@ public interface AuthorizationSettingEntity extends GenericEntity<String> {
|
||||
/**
|
||||
* @return 类型
|
||||
*/
|
||||
@NotBlank(groups = CreateGroup.class)
|
||||
String getType();
|
||||
|
||||
/**
|
||||
@@ -59,6 +62,7 @@ public interface AuthorizationSettingEntity extends GenericEntity<String> {
|
||||
/**
|
||||
* @return 设置给谁
|
||||
*/
|
||||
@NotBlank(groups = CreateGroup.class)
|
||||
String getSettingFor();
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.List;
|
||||
*/
|
||||
public interface MenuEntity
|
||||
extends TreeSortSupportEntity<String> {
|
||||
|
||||
String getName();
|
||||
|
||||
void setName(String name);
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.hswebframework.web.service.DefaultDSLQueryService;
|
||||
import org.hswebframework.web.service.GenericEntityService;
|
||||
import org.hswebframework.web.service.authorization.*;
|
||||
import org.hswebframework.web.service.authorization.AuthorizationSettingTypeSupplier.SettingInfo;
|
||||
import org.hswebframework.web.validator.group.CreateGroup;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
@@ -128,7 +129,7 @@ public class SimpleAuthorizationSettingService extends GenericEntityService<Auth
|
||||
}
|
||||
if (entity.getDetails() != null) {
|
||||
for (AuthorizationSettingDetailEntity detail : entity.getDetails()) {
|
||||
tryValidate(detail);
|
||||
tryValidate(detail, CreateGroup.class);
|
||||
detail.setId(getIDGenerator().generate());
|
||||
detail.setSettingId(id);
|
||||
detail.setStatus(STATUS_ENABLED);
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.hswebframework.web.service.DefaultDSLUpdateService;
|
||||
import org.hswebframework.web.service.authorization.*;
|
||||
import org.hswebframework.web.validate.ValidationException;
|
||||
import org.hswebframework.utils.ListUtils;
|
||||
import org.hswebframework.web.validator.group.CreateGroup;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
@@ -112,7 +113,7 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
|
||||
userEntity.setSalt(IDGenerator.RANDOM.generate());
|
||||
userEntity.setStatus(DataStatus.STATUS_ENABLED);
|
||||
//验证其他属性
|
||||
tryValidate(userEntity);
|
||||
tryValidate(userEntity, CreateGroup.class);
|
||||
//密码MD5
|
||||
userEntity.setPassword(encodePassword(userEntity.getPassword(), userEntity.getSalt()));
|
||||
//创建用户
|
||||
|
||||
@@ -69,7 +69,6 @@ public class AuthorizationSettingTests extends SimpleWebApplicationTests {
|
||||
//todo 修改测试属性
|
||||
AuthorizationSettingEntity newEntity = entityFactory.newInstance(AuthorizationSettingEntity.class);
|
||||
newEntity.setId("test");
|
||||
|
||||
newEntity.setDescribe("测试2");
|
||||
result = testPut("/autz-setting/" + id)
|
||||
.setUp(setup ->
|
||||
|
||||
Reference in New Issue
Block a user