优化swagger

This commit is contained in:
zhou-hao
2017-11-30 00:31:35 +08:00
parent 735710b054
commit 92455015b2
61 changed files with 412 additions and 1077 deletions

View File

@@ -48,22 +48,18 @@ import static org.hswebframework.web.controller.message.ResponseMessage.ok;
*/
public interface CreateController<E, PK, M> {
@Authorize(ignore = true)
<S extends InsertService<E, PK> & CreateEntityService<E>> S getService();
@Authorize(action = Permission.ACTION_ADD)
@PostMapping
@AccessLogger("{action_add}")
@ResponseStatus(HttpStatus.CREATED)
@ApiOperation(value = "创建数据", responseReference = "add")
@ApiResponses({
@ApiResponse(code = 201, message = "创建成功,返回创建数据的ID"),
@ApiResponse(code = 401, message = "未授权"),
@ApiResponse(code = 403, message = "无权限")
})
@ApiOperation(value = "新增")
default ResponseMessage<PK> add(@RequestBody M data) {
E entity = getService().createEntity();
return ok(getService().insert(modelToEntity(data, entity)));
}
@Authorize(ignore = true)
E modelToEntity(M model, E entity);
}

View File

@@ -18,6 +18,7 @@
package org.hswebframework.web.controller;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.commons.entity.Entity;
import org.hswebframework.web.service.CrudService;
import org.springframework.beans.BeanUtils;
@@ -41,9 +42,11 @@ public interface CrudController<E, PK, Q extends Entity, M>
@Override
@SuppressWarnings("unchecked")
@Authorize(ignore = true)
CrudService<E, PK> getService();
@Override
@Authorize(ignore = true)
default E modelToEntity(M model, E entity) {
BeanUtils.copyProperties(model, entity);
return entity;

View File

@@ -37,18 +37,12 @@ import static org.hswebframework.web.controller.message.ResponseMessage.ok;
*/
public interface DeleteController<PK> {
@Authorize(ignore = true)
DeleteService<PK> getService();
@Authorize(action = Permission.ACTION_DELETE)
@DeleteMapping(path = "/{id:.+}")
@AccessLogger("{delete_by_primary_key}")
@ApiOperation("根据ID删除数据")
@ApiResponses({
@ApiResponse(code = 200, message = "删除成功"),
@ApiResponse(code = 401, message = "未授权"),
@ApiResponse(code = 403, message = "无权限"),
@ApiResponse(code = 404, message = "要删除的数据不存在")
})
@ApiOperation("删除数据")
default ResponseMessage deleteByPrimaryKey(@PathVariable PK id) {
return ok(getService().deleteByPk(id));
}

View File

@@ -18,6 +18,7 @@
package org.hswebframework.web.controller;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.commons.entity.Entity;
import org.hswebframework.web.commons.entity.GenericEntity;
import org.hswebframework.web.service.CrudService;
@@ -34,6 +35,7 @@ public interface GenericEntityController<E extends GenericEntity<PK>, PK, Q exte
extends CrudController<E, PK, Q, M> {
@Override
@Authorize(ignore = true)
CrudService<E, PK> getService();
}

View File

@@ -18,8 +18,6 @@
package org.hswebframework.web.controller;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.hswebframework.web.NotFoundException;
import org.hswebframework.web.authorization.Permission;
import org.hswebframework.web.authorization.annotation.Authorize;
@@ -27,7 +25,6 @@ import org.hswebframework.web.commons.entity.Entity;
import org.hswebframework.web.commons.entity.PagerResult;
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
import org.hswebframework.web.controller.message.ResponseMessage;
import org.hswebframework.web.logging.AccessLogger;
import org.hswebframework.web.service.QueryByEntityService;
import org.hswebframework.web.service.QueryService;
import org.springframework.web.bind.annotation.GetMapping;
@@ -56,6 +53,7 @@ public interface QueryController<E, PK, Q extends Entity> {
* @param <T> 服务类泛型
* @return 服务类实例
*/
@Authorize(ignore = true)
<T extends QueryByEntityService<E> & QueryService<E, PK>> T getService();
/**
@@ -70,24 +68,21 @@ public interface QueryController<E, PK, Q extends Entity> {
*/
@Authorize(action = Permission.ACTION_QUERY)
@GetMapping
@AccessLogger("{dynamic_query}")
@ApiOperation(value = "根据动态条件查询数据", responseReference = "get")
@ApiOperation(value = "根据动态条件查询", responseReference = "get")
default ResponseMessage<PagerResult<E>> list(Q param) {
return ok(getService().selectPager(param));
}
@Authorize(action = Permission.ACTION_QUERY)
@GetMapping("/no-paging")
@AccessLogger("{dynamic_query}")
@ApiOperation(value = "不分页动态查询数据", responseReference = "get")
@ApiOperation(value = "不分页动态查询", responseReference = "get")
default ResponseMessage<List<E>> listNoPaging(Q param) {
return ok(getService().select(param));
}
@Authorize(action = Permission.ACTION_QUERY)
@GetMapping("/count")
@AccessLogger("{dynamic_query}")
@ApiOperation(value = "根据动态条件统计数据", responseReference = "get")
@ApiOperation(value = "根据动态条件统计", responseReference = "get")
default ResponseMessage<Integer> count(Q param) {
return ok(getService().count(param));
}
@@ -95,20 +90,19 @@ public interface QueryController<E, PK, Q extends Entity> {
@Authorize(action = Permission.ACTION_GET)
@GetMapping(path = "/{id:.+}")
@AccessLogger("{get_by_id}")
@ApiOperation("根据主键查询数据")
@ApiOperation("根据主键查询")
default ResponseMessage<E> getByPrimaryKey(@PathVariable PK id) {
return ok(assertNotNull(getService().selectByPk(id)));
}
@Authorize(action = Permission.ACTION_GET)
@GetMapping(path = "/ids")
@AccessLogger("{get_by_id}")
@ApiOperation("根据主键查询多个数据")
@ApiOperation("根据主键查询多条记录")
default ResponseMessage<List<E>> getByPrimaryKey(@RequestParam List<PK> ids) {
return ok(assertNotNull(getService().selectByPk(ids)));
}
@Authorize(ignore = true)
static <T> T assertNotNull(T obj) {
if (null == obj) {
throw new NotFoundException("{data_not_exist}");

View File

@@ -18,6 +18,7 @@
package org.hswebframework.web.controller;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.commons.entity.Entity;
import org.hswebframework.web.service.CrudService;
import org.springframework.beans.BeanUtils;
@@ -41,9 +42,11 @@ public interface SimpleCrudController<E, PK, Q extends Entity>
@Override
@SuppressWarnings("unchecked")
@Authorize(ignore = true)
CrudService<E, PK> getService();
@Override
@Authorize(ignore = true)
default E modelToEntity(E model, E entity) {
// model = entity
return model;

View File

@@ -18,6 +18,7 @@
package org.hswebframework.web.controller;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.commons.entity.Entity;
import org.hswebframework.web.commons.entity.GenericEntity;
import org.hswebframework.web.service.CrudService;
@@ -34,6 +35,7 @@ public interface SimpleGenericEntityController<E extends GenericEntity<PK>, PK,
extends SimpleCrudController<E, PK, Q> {
@Override
@Authorize(ignore = true)
CrudService<E, PK> getService();

View File

@@ -43,8 +43,7 @@ public interface UpdateController<E, PK, M> {
@Authorize(action = Permission.ACTION_UPDATE)
@PutMapping(path = "/{id}")
@AccessLogger("{update_by_primary_key}")
@ApiOperation("根据ID修改数据")
@ApiOperation("修改数据")
default ResponseMessage<Integer> updateByPrimaryKey(@PathVariable PK id, @RequestBody M data) {
E entity = getService().createEntity();
return ResponseMessage.ok(getService().updateByPk(id, modelToEntity(data, entity)));
@@ -52,14 +51,12 @@ public interface UpdateController<E, PK, M> {
@Authorize(action = {Permission.ACTION_UPDATE, Permission.ACTION_ADD}, logical = Logical.AND)
@PatchMapping
@AccessLogger("{save_or_update}")
@ApiOperation("保存数据,如果数据不存在则新增一条数据")
@ApiOperation("新增或者修改")
default ResponseMessage<PK> saveOrUpdate(@RequestBody M data) {
E entity = getService().createEntity();
return ResponseMessage.ok(getService().saveOrUpdate(modelToEntity(data, entity)));
}
/**
* 将model转为entity
*
@@ -69,5 +66,6 @@ public interface UpdateController<E, PK, M> {
* @see org.hswebframework.web.commons.model.Model
* @see org.hswebframework.web.commons.entity.Entity
*/
@Authorize(ignore = true)
E modelToEntity(M model, E entity);
}

View File

@@ -70,8 +70,7 @@ public class OAuth2SSOAuthorizingListener
.get().onError(OAuth2Response.throwOnError)
.as(Authentication.class);
HttpSession httpSession = WebUtil
.getHttpServletRequest()
HttpSession httpSession = WebUtil.getHttpServletRequest()
.getSession();
userTokenManager.signIn(httpSession.getId(), "sessionId",authentication.getUser().getId(), 60 * 60 * 1000);

View File

@@ -15,21 +15,5 @@
```
3. 测试
使用Postman之类的http测试工具请求:
```bash
# 登录
HTTP POST : http://localhost:8081/authorize/login?username=admin&password=admin
# 测试数据权限控制-查询
HTTP GET : http://localhost:8081/test/testQuery
```
如果不想使用权限控制,请注释掉 pom.xml的
```xml
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-authorization-shiro</artifactId>
<version>${project.version}</version>
</dependency>
```
## 测试
打开页面: `http://localhost:8081/swagger-ui.html`

View File

@@ -145,6 +145,16 @@
<artifactId>hsweb-system-dynamic-form-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-system-oauth2-client-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-system-oauth2-server-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>

View File

@@ -25,6 +25,7 @@ import org.hswebframework.web.authorization.access.DataAccessConfig;
import org.hswebframework.web.authorization.basic.aop.AopMethodAuthorizeDefinitionCustomizerParser;
import org.hswebframework.web.authorization.basic.configuration.EnableAopAuthorize;
import org.hswebframework.web.authorization.basic.define.EmptyAuthorizeDefinition;
import org.hswebframework.web.authorization.define.AuthorizeDefinitionInitializedEvent;
import org.hswebframework.web.authorization.simple.SimpleFieldFilterDataAccessConfig;
import org.hswebframework.web.commons.entity.DataStatus;
import org.hswebframework.web.commons.entity.factory.EntityFactory;
@@ -45,6 +46,7 @@ import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
@@ -83,13 +85,13 @@ import java.util.stream.Stream;
@EnableAccessLogger
@EnableAopAuthorize
public class SpringBootExample
implements CommandLineRunner {
implements CommandLineRunner ,ApplicationListener<AuthorizeDefinitionInitializedEvent>{
@Bean
public AopMethodAuthorizeDefinitionCustomizerParser customizerParser(){
//自定义权限声明
//所有控制都通过
return context -> EmptyAuthorizeDefinition.instance;
return (type,method,context) -> EmptyAuthorizeDefinition.instance;
}
@Bean
@@ -306,4 +308,9 @@ public class SpringBootExample
// .getRelations("person","王伟")
// .findRev("直属上级");
}
@Override
public void onApplicationEvent(AuthorizeDefinitionInitializedEvent event) {
System.out.println(event.getAllDefinition());
}
}

View File

@@ -21,6 +21,7 @@ hsweb:
allowed-methods: "*"
allowed-headers: "*"
authorize:
auto-parse: true
jwt:
id: test
secret: dGVzdA==

View File

@@ -7,6 +7,7 @@ import org.hswebframework.web.boost.aop.context.MethodInterceptorHolder;
import org.hswebframework.web.logging.AccessLogger;
import org.hswebframework.web.logging.LoggerDefine;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.util.StringUtils;
import java.lang.reflect.Method;
@@ -22,10 +23,14 @@ public class SwaggerAccessLoggerParser implements AccessLoggerParser {
@Override
public LoggerDefine parse(MethodInterceptorHolder holder) {
Api api = holder.findAnnotation(Api.class);
ApiOperation operation = holder.findAnnotation(ApiOperation.class);
String action = "";
if (api != null) {
action = action.concat(api.value());
}
if (null != operation) {
action = operation.value();
action = StringUtils.isEmpty(action) ? operation.value() : action + "-" + operation.value();
}
return new LoggerDefine(action, "");
}

View File

@@ -49,11 +49,9 @@ import static org.hswebframework.web.controller.message.ResponseMessage.ok;
@RestController
@RequestMapping("${hsweb.web.mappings.authorize:authorize}")
@AccessLogger("授权")
@Api(tags = "hsweb-authorization", description = "提供基本的授权功能")
@Api(tags = "权限-用户授权", value = "授权")
public class AuthorizationController {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private UserService userService;

View File

@@ -17,6 +17,8 @@
package org.hswebframework.web.controller.authorization;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.hswebframework.web.authorization.Permission;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
@@ -38,8 +40,8 @@ import org.springframework.web.bind.annotation.RestController;
*/
@RestController
@RequestMapping("${hsweb.web.mappings.autz-setting:autz-setting}")
@Authorize(permission = "autz-setting")
@AccessLogger("权限设置")
@Authorize(permission = "autz-setting",description = "权限设置")
@Api(tags = "权限-权限设置",value = "权限设置")
public class AuthorizationSettingController implements SimpleGenericEntityController<AuthorizationSettingEntity, String, QueryParamEntity> {
private AuthorizationSettingService authorizationSettingService;
@@ -56,7 +58,7 @@ public class AuthorizationSettingController implements SimpleGenericEntityContro
@GetMapping("/{type}/{settingFor}")
@Authorize(action = Permission.ACTION_GET)
@AccessLogger("根据type和settingFor获取配置")
@ApiOperation("根据type和settingFor获取配置")
public ResponseMessage<AuthorizationSettingEntity> select(@PathVariable String type, @PathVariable String settingFor) {
return ResponseMessage.ok(authorizationSettingService.select(type, settingFor));
}

View File

@@ -47,9 +47,8 @@ import static org.hswebframework.web.controller.message.ResponseMessage.ok;
*/
@RestController
@RequestMapping("${hsweb.web.mappings.menu:menu}")
@Authorize(permission = "menu")
@AccessLogger("菜单")
@Api(value = "menu-manager", description = "系统菜单管理")
@Authorize(permission = "menu",description = "菜单管理")
@Api(value = "系统菜单管理",tags = "权限-菜单管理")
public class MenuController implements SimpleGenericEntityController<MenuEntity, String, QueryParamEntity> {
private MenuService menuService;

View File

@@ -17,6 +17,8 @@
package org.hswebframework.web.controller.authorization;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
import org.hswebframework.web.controller.GenericEntityController;
@@ -32,10 +34,10 @@ import org.springframework.web.bind.annotation.RestController;
*
* @author hsweb-generator-online
*/
@RestController
@RequestMapping("${hsweb.web.mappings.menu-group:menu-group}")
@Authorize(permission = "menu-group")
@AccessLogger("菜单分组")
//@RestController
//@RequestMapping("${hsweb.web.mappings.menu-group:menu-group}")
//@Authorize(permission = "menu-group",description = "菜单分组管理")
//@Api(tags = "权限-菜单分组",value = "菜单分组")
public class MenuGroupController implements GenericEntityController<MenuGroupEntity, String, QueryParamEntity, MenuGroupEntity> {
private MenuGroupService menuGroupService;

View File

@@ -36,9 +36,8 @@ import org.springframework.web.bind.annotation.RestController;
*/
@RestController
@RequestMapping("${hsweb.web.mappings.permission:permission}")
@AccessLogger("{permission_manager}")
@Authorize(permission = "permission")
@Api(tags = "permission-manager", description = "权限管理")
@Authorize(permission = "permission", description = "权限管理")
@Api(value = "权限管理",tags = "权限-权限管理")
public class PermissionController implements SimpleGenericEntityController<PermissionEntity, String, QueryParamEntity> {
private PermissionService permissionService;

View File

@@ -43,9 +43,8 @@ import static org.hswebframework.web.controller.message.ResponseMessage.ok;
*/
@RestController
@RequestMapping("${hsweb.web.mappings.role:role}")
@AccessLogger("{role_manager}")
@Authorize(permission = "role")
@Api(tags = "role-manager", description = "角色管理")
@Authorize(permission = "role", description = "角色管理")
@Api(value = "角色管理",tags = "权限-角色管理")
public class RoleController implements SimpleGenericEntityController<RoleEntity, String, QueryParamEntity> {
@Autowired
@@ -58,7 +57,6 @@ public class RoleController implements SimpleGenericEntityController<RoleEntity,
@PutMapping("/disable/{id:.+}")
@Authorize(action = Permission.ACTION_DISABLE)
@AccessLogger("{disable}")
@ApiOperation("禁用角色")
public ResponseMessage disable(@PathVariable String id) {
roleService.disable(id);
@@ -67,7 +65,6 @@ public class RoleController implements SimpleGenericEntityController<RoleEntity,
@PutMapping("/enable/{id}")
@Authorize(action = Permission.ACTION_ENABLE)
@AccessLogger("{disable}")
@ApiOperation("启用角色")
public ResponseMessage enable(@PathVariable String id) {
roleService.enable(id);

View File

@@ -50,17 +50,14 @@ import static org.hswebframework.web.controller.message.ResponseMessage.ok;
*/
@RestController
@RequestMapping("${hsweb.web.mappings.user:user}")
@Authorize(permission = "user")
@AccessLogger("用户管理")
@Api(tags = "user-manager", description = "用户基本信息管理")
@Authorize(permission = "user", description = "用户管理")
@Api(value = "用户管理",tags = "权限-用户管理")
public class UserController implements
QueryController<UserEntity, String, QueryParamEntity>,
CreateController<BindRoleUserEntity, String, BindRoleUserEntity> {
private UserService userService;
private UserTokenManager userTokenManager;
@Override
@SuppressWarnings("unchecked")
public UserService getService() {
@@ -72,33 +69,6 @@ public class UserController implements
this.userService = userService;
}
@Autowired(required = false)
public void setUserTokenManager(UserTokenManager userTokenManager) {
this.userTokenManager = userTokenManager;
}
@GetMapping("/tokens")
@Authorize(action = Permission.ACTION_QUERY)
@AccessLogger("获取所有已登录用户的信息")
public ResponseMessage<List<UserToken>> userTokens() {
if (userTokenManager == null) {
throw new UnsupportedOperationException("userTokenManager is null");
}
return ok(userTokenManager.allLoggedUser());
}
@PutMapping("/tokens/{token}/{state}")
@Authorize(action = "change-state")
@AccessLogger("修改token的状态")
public ResponseMessage<List<UserToken>> makeOffline(@PathVariable String token, @PathVariable TokenState state) {
if (userTokenManager == null) {
throw new UnsupportedOperationException("userTokenManager is null");
}
userTokenManager.changeTokenState(token, state);
return ok();
}
@Override
public ResponseMessage<PagerResult<UserEntity>> list(QueryParamEntity param) {
param.excludes("password", "salt");
@@ -112,9 +82,8 @@ public class UserController implements
.exclude(UserEntity.class, "password", "salt");
}
@Authorize(action = "update")
@Authorize(action = Permission.ACTION_UPDATE)
@PutMapping(path = "/{id:.+}")
@AccessLogger("{update_by_primary_key}")
@ApiOperation("根据ID修改用户信息")
public ResponseMessage<Void> updateByPrimaryKey(@PathVariable String id,
@RequestBody BindRoleUserEntity userModel) {
@@ -124,8 +93,7 @@ public class UserController implements
@Authorize(merge = false)
@PutMapping(path = "/password")
@AccessLogger("{update_password_login_user}")
@ApiOperation("修改当前用户的密码")
@ApiOperation("修改当前登录用户的密码")
public ResponseMessage<Void> updateLoginUserPassword(@RequestParam String password,
@RequestParam String oldPassword) {
@@ -136,7 +104,6 @@ public class UserController implements
@Authorize(action = Permission.ACTION_UPDATE)
@PutMapping(path = "/password/{id:.+}")
@AccessLogger("{update_password_by_id}")
@ApiOperation("修改指定用户的密码")
public ResponseMessage<Void> updateByPasswordPrimaryKey(@PathVariable String id,
@RequestParam String password,
@@ -154,17 +121,15 @@ public class UserController implements
return CreateController.super.add(data);
}
@Authorize(action = "enable")
@Authorize(action = Permission.ACTION_ENABLE)
@PutMapping(path = "/{id}/enable")
@AccessLogger("{enable_user}")
@ApiOperation("启用用户")
public ResponseMessage<Boolean> enable(@PathVariable String id) {
return ok(getService().enable(id));
}
@Authorize(action = "disable")
@Authorize(action = Permission.ACTION_DISABLE)
@PutMapping(path = "/{id}/disable")
@AccessLogger("{disable_user}")
@ApiOperation("禁用用户")
public ResponseMessage<Boolean> disable(@PathVariable String id) {
return ok(getService().disable(id));

View File

@@ -1,5 +1,8 @@
package org.hswebframework.web.controller.authorization;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.hswebframework.web.authorization.Permission;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.authorization.token.TokenState;
@@ -15,8 +18,8 @@ import java.util.List;
@RestController
@RequestMapping("${hsweb.web.mappings.user-token:user-token}")
@AccessLogger("token信息")
@Authorize(permission = "user-token")
@Api(value = "用户令牌", tags = "权限-用户令牌管理")
@Authorize(permission = "user-token", description = "用户令牌管理")
public class UserTokenInfoController {
@Autowired
@@ -24,43 +27,50 @@ public class UserTokenInfoController {
@GetMapping("/token/total")
@Authorize(merge = false)
@ApiOperation("获取已授权令牌的总数")
public ResponseMessage<Long> allLoginToken() {
return ResponseMessage.ok(userTokenManager.totalToken());
}
@GetMapping("/user/total")
@Authorize(merge = false)
@ApiOperation("获取已授权用户的总数")
public ResponseMessage<Long> allUserToken() {
return ResponseMessage.ok(userTokenManager.totalUser());
}
@GetMapping("/reset")
@Authorize(merge = false)
@ApiOperation("重置当前用户的令牌")
public ResponseMessage<Boolean> resetToken() {
UserToken token= UserTokenHolder.currentToken();
if(token!=null){
UserToken token = UserTokenHolder.currentToken();
if (token != null) {
userTokenManager.signOutByToken(token.getToken());
}
return ResponseMessage.ok(true);
}
@GetMapping("/token/all")
@ApiOperation("获取所有令牌")
@Authorize(action = Permission.ACTION_GET)
public ResponseMessage<List<UserToken>> allTokenInfo() {
return ResponseMessage.ok(userTokenManager.allLoggedUser());
}
@PutMapping("/token/{token}/{state}")
@ApiOperation("修改令牌状态")
@Authorize(action = Permission.ACTION_UPDATE)
public ResponseMessage<Void> changeTokenState(@PathVariable String token, @PathVariable TokenState state) {
userTokenManager.changeTokenState(token,state);
public ResponseMessage<Void> changeTokenState(@ApiParam("令牌") @PathVariable String token, @ApiParam("要修改的状态") @PathVariable TokenState state) {
userTokenManager.changeTokenState(token, state);
return ResponseMessage.ok();
}
@PutMapping("/user/{userId}/{state}")
@ApiOperation("修改用户状态")
@Authorize(action = Permission.ACTION_GET)
public ResponseMessage<Void> changeUserState(@PathVariable String userId, @PathVariable TokenState state) {
userTokenManager.changeUserState(userId,state);
public ResponseMessage<Void> changeUserState(@ApiParam("用户ID") @PathVariable String userId, @ApiParam("要修改的状态") @PathVariable TokenState state) {
userTokenManager.changeUserState(userId, state);
return ResponseMessage.ok();
}

View File

@@ -1,77 +0,0 @@
package org.hswebframework.web.service.authorization;
import org.hswebframework.web.commons.entity.Entity;
import org.hswebframework.web.entity.authorization.MenuEntity;
import org.hswebframework.web.entity.authorization.MenuGroupEntity;
import java.util.List;
import java.util.Set;
/**
* TODO 完成注释
*
* @author zhouhao
*/
public class PermissionSettingDTO implements Entity {
//配置类型,如 role,user,position,person等
private String type;
//配置给谁,为type对应数据的主键
private String settingFor;
private String describe;
private List<PermissionSettingDetailDTO> details;
private Set<MenuEntity> menus;
private Set<MenuGroupEntity> menuGroups;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getSettingFor() {
return settingFor;
}
public void setSettingFor(String settingFor) {
this.settingFor = settingFor;
}
public String getDescribe() {
return describe;
}
public void setDescribe(String describe) {
this.describe = describe;
}
public List<PermissionSettingDetailDTO> getDetails() {
return details;
}
public void setDetails(List<PermissionSettingDetailDTO> details) {
this.details = details;
}
public Set<MenuEntity> getMenus() {
return menus;
}
public void setMenus(Set<MenuEntity> menus) {
this.menus = menus;
}
public Set<MenuGroupEntity> getMenuGroups() {
return menuGroups;
}
public void setMenuGroups(Set<MenuGroupEntity> menuGroups) {
this.menuGroups = menuGroups;
}
}

View File

@@ -1,44 +0,0 @@
package org.hswebframework.web.service.authorization;
import org.hswebframework.web.commons.entity.Entity;
import org.hswebframework.web.entity.authorization.DataAccessEntity;
import java.util.Set;
/**
* TODO 完成注释
*
* @author zhouhao
*/
public class PermissionSettingDetailDTO implements Entity {
private String permissionId;
private Set<String> actions;
private Set<DataAccessEntity> dataAccesses;
public String getPermissionId() {
return permissionId;
}
public void setPermissionId(String permissionId) {
this.permissionId = permissionId;
}
public Set<String> getActions() {
return actions;
}
public void setActions(Set<String> actions) {
this.actions = actions;
}
public Set<DataAccessEntity> getDataAccesses() {
return dataAccesses;
}
public void setDataAccesses(Set<DataAccessEntity> dataAccesses) {
this.dataAccesses = dataAccesses;
}
}

View File

@@ -5,8 +5,6 @@ import org.hswebframework.web.entity.authorization.UserMenuEntity;
import java.util.List;
/**
* TODO 完成注释
*
* @author zhouhao
*/
public interface UserMenuManagerService {

View File

@@ -1,5 +1,6 @@
package org.hswebframework.web.controller.datasource;
import io.swagger.annotations.Api;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
import org.hswebframework.web.controller.SimpleGenericEntityController;
@@ -16,9 +17,9 @@ import org.springframework.web.bind.annotation.RestController;
* @author hsweb-generator-online
*/
@RestController
@RequestMapping("${hsweb.web.mappings.dataSourceConfig:dataSourceConfig}")
@Authorize(permission = "dataSourceConfig")
@AccessLogger("数据源配置")
@RequestMapping("datasource/config")
@Authorize(permission = "data-source-config",description = "动态数据源管理")
@Api(value = "数据源配置",tags = "动态数据源-数据源配置")
public class DataSourceConfigController implements SimpleGenericEntityController<DataSourceConfigEntity, String, QueryParamEntity> {
private DataSourceConfigService dataSourceConfigService;

View File

@@ -17,6 +17,7 @@
package org.hswebframework.web.controller.dictionary;
import io.swagger.annotations.Api;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
import org.hswebframework.web.controller.GenericEntityController;
@@ -35,8 +36,8 @@ import org.springframework.web.bind.annotation.RestController;
*/
@RestController
@RequestMapping("${hsweb.web.mappings.dictionary:dictionary}")
@Authorize(permission = "dictionary")
@AccessLogger("数据字典")
@Authorize(permission = "dictionary",description = "数据字典管理")
@Api(value = "数据字典",tags = "数据字典-字典配置")
public class DictionaryController implements GenericEntityController<DictionaryEntity, String, QueryParamEntity, DictionaryEntity> {
private DictionaryService dictionaryService;

View File

@@ -17,6 +17,7 @@
package org.hswebframework.web.controller.dictionary;
import io.swagger.annotations.Api;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
import org.hswebframework.web.controller.GenericEntityController;
@@ -34,8 +35,8 @@ import org.springframework.web.bind.annotation.RestController;
*/
@RestController
@RequestMapping("${hsweb.web.mappings.dictionary-parser:dictionary-parser}")
@Authorize(permission = "dictionary-parser")
@AccessLogger("数据字典解析配置")
@Authorize(permission = "dictionary-parser", description = "数据字典解析配置")
@Api(value = "数据字典解析配置", tags = "数据字典-字典解析配置")
public class DictionaryParserController implements GenericEntityController<DictionaryParserEntity, String, QueryParamEntity, DictionaryParserEntity> {
private DictionaryParserService dictionaryParserService;

View File

@@ -22,9 +22,8 @@ import java.util.List;
*/
@RestController
@RequestMapping("${hsweb.web.mappings.dynamic/form/column:dynamic/form/column}")
@Authorize(permission = "dynamic-form")
@AccessLogger("动态表单")
@Api(tags = "dynamic-form", value = "动态表单")
@Authorize(permission = "dynamic-form", description = "动态表单管理")
@Api(value = "动态表单管理",tags = "动态表单-表单管理")
public class DynamicFormColumnController {
private DynamicFormService dynamicFormService;
@@ -36,7 +35,6 @@ public class DynamicFormColumnController {
@PatchMapping("/batch")
@Authorize(action = Permission.ACTION_ADD)
@AccessLogger("保存多个表单列")
@ApiOperation("保存多个表单列")
public ResponseMessage<List<String>> add(@RequestBody List<DynamicFormColumnEntity> columnEntities) {
return ResponseMessage.ok(dynamicFormService.saveOrUpdateColumn(columnEntities));
@@ -44,7 +42,6 @@ public class DynamicFormColumnController {
@PatchMapping
@Authorize(action = Permission.ACTION_ADD)
@AccessLogger("保存表单列")
@ApiOperation("保存表单列")
public ResponseMessage<String> add(@RequestBody DynamicFormColumnEntity columnEntity) {
return ResponseMessage.ok(dynamicFormService.saveOrUpdateColumn(columnEntity));
@@ -52,7 +49,6 @@ public class DynamicFormColumnController {
@DeleteMapping
@Authorize(action = Permission.ACTION_DELETE)
@AccessLogger("删除列")
@ApiOperation("删除列")
public ResponseMessage<List<DynamicFormColumnEntity>> delete(@ApiParam(value = "要删除的列id,多个列以,分割", example = "1,2,3")
@RequestParam String ids) {
@@ -61,7 +57,6 @@ public class DynamicFormColumnController {
@GetMapping("/{formId}")
@Authorize(action = Permission.ACTION_GET)
@AccessLogger("获取表单的所有列")
@ApiOperation("获取表单的所有列")
public ResponseMessage<List<DynamicFormColumnEntity>> getByFormId(@PathVariable String formId) {
return ResponseMessage.ok(dynamicFormService.selectColumnsByFormId(formId));

View File

@@ -1,6 +1,7 @@
package org.hswebframework.web.controller.form;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.hswebframework.web.authorization.Authentication;
import org.hswebframework.web.authorization.Permission;
import org.hswebframework.web.authorization.annotation.Authorize;
@@ -24,9 +25,8 @@ import java.util.Objects;
*/
@RestController
@RequestMapping("${hsweb.web.mappings.dynamic/form:dynamic/form}")
@Authorize(permission = "dynamic-form")
@AccessLogger("动态表单")
@Api(tags = "dynamic-form", value = "动态表单")
@Authorize(permission = "dynamic-form", description = "动态表单管理")
@Api(value = "动态表单管理",tags = "动态表单-表单管理")
public class DynamicFormController implements SimpleGenericEntityController<DynamicFormEntity, String, QueryParamEntity> {
private DynamicFormService dynamicFormService;
@@ -43,7 +43,7 @@ public class DynamicFormController implements SimpleGenericEntityController<Dyna
@PatchMapping("/bind")
@AccessLogger("同时保存表单和字段")
@ApiOperation("同时保存表单和字段")
@Authorize(action = {Permission.ACTION_ADD, Permission.ACTION_UPDATE}, logical = Logical.OR)
public ResponseMessage<String> saveOrUpdateFormAndColumn(@RequestBody DynamicFormColumnBindEntity bindEntity) {
Authentication authentication = Authentication.current().orElse(null);
@@ -69,38 +69,38 @@ public class DynamicFormController implements SimpleGenericEntityController<Dyna
}
@PutMapping("/{id}/deploy")
@Authorize(action = "deploy")
@AccessLogger("发布表单")
@Authorize(action = "deploy", description = "发布表单")
@ApiOperation("发布表单")
public ResponseMessage<Void> deploy(@PathVariable String id) {
dynamicFormService.deploy(id);
return ResponseMessage.ok();
}
@PutMapping("/{id}/un-deploy")
@Authorize(action = "deploy")
@AccessLogger("取消发布表单")
@Authorize(action = "deploy", description = "发布表单")
@ApiOperation("取消发布表单")
public ResponseMessage<Void> unDeploy(@PathVariable String id) {
dynamicFormService.unDeploy(id);
return ResponseMessage.ok();
}
@GetMapping("/{id}/editing")
@Authorize(action = "get")
@AccessLogger("获取当前正在编辑的表单")
@Authorize(action = Permission.ACTION_GET)
@ApiOperation("获取当前正在编辑的表单")
public ResponseMessage<DynamicFormColumnBindEntity> getEditing(@PathVariable String id) {
return ResponseMessage.ok(dynamicFormService.selectEditing(id));
}
@GetMapping("/{id}/latest")
@Authorize(action = "get")
@AccessLogger("获取最新发布的表单")
@Authorize(action = Permission.ACTION_GET)
@ApiOperation("获取最新发布的表单")
public ResponseMessage<DynamicFormColumnBindEntity> selectDeployed(@PathVariable String id) {
return ResponseMessage.ok(dynamicFormService.selectLatestDeployed(id));
}
@GetMapping("/{id}/{version:\\d+}")
@Authorize(action = "get")
@AccessLogger("获取指定版本的表单")
@Authorize(action = Permission.ACTION_GET)
@ApiOperation("获取指定版本的表单")
public ResponseMessage<DynamicFormColumnBindEntity> selectDeployed(@PathVariable String id, @PathVariable int version) {
return ResponseMessage.ok(dynamicFormService.selectDeployed(id, version));
}

View File

@@ -1,11 +1,14 @@
package org.hswebframework.web.controller.form;
import io.swagger.annotations.Api;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
import org.hswebframework.web.controller.QueryController;
import org.hswebframework.web.controller.SimpleGenericEntityController;
import org.hswebframework.web.controller.message.ResponseMessage;
import org.hswebframework.web.entity.form.DynamicFormDeployLogEntity;
import org.hswebframework.web.logging.AccessLogger;
import org.hswebframework.web.service.QueryByEntityService;
import org.hswebframework.web.service.form.DynamicFormDeployLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
@@ -22,9 +25,9 @@ import java.util.List;
*/
@RestController
@RequestMapping("${hsweb.web.mappings.dynamicFormDeployLog:dynamic/form-deploy-log}")
@Authorize(permission = "form-deploy-log")
@AccessLogger("表单发布日志")
public class DynamicFormDeployLogController implements SimpleGenericEntityController<DynamicFormDeployLogEntity, String, QueryParamEntity> {
@Authorize(permission = "form-deploy-log",description = "表单发布日志")
@Api(value = "表单发布日志",tags = "动态表单-发布日志")
public class DynamicFormDeployLogController implements QueryController<DynamicFormDeployLogEntity, String, QueryParamEntity> {
private DynamicFormDeployLogService dynamicFormDeployLogService;
@@ -34,6 +37,7 @@ public class DynamicFormDeployLogController implements SimpleGenericEntityContro
}
@Override
@SuppressWarnings("unchecked")
public DynamicFormDeployLogService getService() {
return dynamicFormDeployLogService;
}

View File

@@ -1,5 +1,9 @@
package org.hswebframework.web.controller.form;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.hswebframework.web.authorization.Permission;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.commons.entity.PagerResult;
import org.hswebframework.web.commons.entity.param.DeleteParamEntity;
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
@@ -19,8 +23,9 @@ import java.util.Map;
* @since 3.0
*/
@RestController
@AccessLogger("动态表单操作")
@Api(value = "动态表单操作",tags = "动态表单-数据操作")
@RequestMapping("/dynamic/form/operation")
@Authorize(permission = "dynamic-form-operation", description = "动态表单数据操作")
public class DynamicFormOperationController {
private DynamicFormOperationService dynamicFormOperationService;
@@ -31,27 +36,30 @@ public class DynamicFormOperationController {
}
@GetMapping("/{formId}")
@AccessLogger("查询")
// @Authorize(action = Permission.ACTION_QUERY)
@ApiOperation("动态查询")
@Authorize(action = Permission.ACTION_GET)
public ResponseMessage<PagerResult<Object>> selectPager(@PathVariable String formId, QueryParamEntity paramEntity) {
return ResponseMessage.ok(dynamicFormOperationService.selectPager(formId, paramEntity));
}
@PostMapping("/{formId}")
@AccessLogger("新增")
@ApiOperation("新增")
@Authorize(action = Permission.ACTION_ADD)
public ResponseMessage<Map<String, Object>> add(@PathVariable String formId, @RequestBody Map<String, Object> data) {
dynamicFormOperationService.insert(formId, data);
return ResponseMessage.ok(data);
}
@PutMapping("/{formId}")
@AccessLogger("修改")
@ApiOperation("动态修改")
@Authorize(action = Permission.ACTION_UPDATE)
public ResponseMessage<Integer> update(@PathVariable String formId, @RequestBody UpdateParamEntity<Map<String, Object>> paramEntity) {
return ResponseMessage.ok(dynamicFormOperationService.update(formId, paramEntity));
}
@DeleteMapping("/{formId}")
@AccessLogger("删除")
@ApiOperation("动态删除")
@Authorize(action = Permission.ACTION_DELETE)
public ResponseMessage<Integer> delete(@PathVariable String formId, DeleteParamEntity paramEntity) {
return ResponseMessage.ok(dynamicFormOperationService.delete(formId, paramEntity));
}

View File

@@ -1,6 +1,8 @@
package org.hswebframework.web.controller.file;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.*;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.fileupload.ParameterParser;
import org.hswebframework.expands.compress.Compress;
import org.hswebframework.expands.compress.zip.ZIPWriter;
@@ -26,6 +28,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.activation.MimetypesFileTypeMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
@@ -49,8 +52,8 @@ import static java.util.Optional.ofNullable;
*/
@RestController
@RequestMapping("${hsweb.web.mappings.file:file}")
@Authorize(permission = "file")
@AccessLogger("文件")
@Authorize(permission = "file", description = "文件管理")
@Api(value = "文件管理",tags = "文件管理-文件操作")
@SuppressWarnings("all")
public class FileController {
@@ -72,6 +75,10 @@ public class FileController {
this.fileInfoService = fileInfoService;
}
public static void main(String[] args) {
System.out.println(Base64.encodeBase64String("hello".getBytes()));
}
/**
* 构建并下载zip文件.仅支持POST请求
*
@@ -82,17 +89,33 @@ public class FileController {
* @throws RuntimeException 构建zip文件错误
*/
@RequestMapping(value = "/download-zip/{name:.+}", method = {RequestMethod.POST})
@AccessLogger("下载zip文件")
@Authorize(action = "download")
public void downloadZip(@PathVariable("name") String name,
@RequestParam("data") String dataStr,
@ApiOperation("构建zip文件并下载")
@Authorize(action = "download", description = "下载文件")
public void downloadZip(@ApiParam("zip文件名") @PathVariable("name") String name,
@ApiParam(value = "zip文件内容", example = "[" +
"{\"name\":\"textFile.txt\",\"text\":\"fileText\"}," +
"{\"name\":\"uploadedFile.png\",\"file\":\"fileId or file md5\"}" +
"{\"name\":\"base64File.text\",\"base64\":\"aGVsbG8=\"}" +
"]") @RequestParam("data") String dataStr,
HttpServletResponse response) throws IOException {
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(name, "utf-8"));
ZIPWriter writer = Compress.zip();
List<Map<String, String>> data = (List) JSON.parseArray(dataStr, Map.class);
data.forEach(map -> writer.addTextFile(map.get("name"), map.get("text")));
data.forEach(map -> {
String entryName = map.get("name");
String text = map.get("text");
String file = map.get("file");
String fileBase64 = map.get("base64");
if (text != null) {
writer.addTextFile(map.get("name"), text);
} else if (file != null) {
writer.addFile(entryName, fileService.readFile(file));
} else if (fileBase64 != null) {
writer.addFile(entryName, new ByteArrayInputStream(Base64.decodeBase64(fileBase64)));
}
});
writer.write(response.getOutputStream());
}
@@ -105,10 +128,10 @@ public class FileController {
* @throws IOException 写出文本内容错误
*/
@RequestMapping(value = "/download-text/{name:.+}", method = {RequestMethod.GET, RequestMethod.POST})
@AccessLogger("下载text文件")
@Authorize(action = "download")
public void downloadTxt(@PathVariable("name") String name,
@RequestParam("text") String text,
@ApiOperation("构建文本文件并下载")
@Authorize(action = "download", description = "下载文件")
public void downloadTxt(@ApiParam("文件名") @PathVariable("name") String name,
@ApiParam("文本内容") @RequestParam("text") String text,
HttpServletResponse response) throws IOException {
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(name, "utf-8"));
@@ -128,12 +151,12 @@ public class FileController {
* @throws NotFoundException 文件不存在
*/
@RequestMapping(value = "/download/{id}/{name:.+}", method = RequestMethod.GET)
@AccessLogger("下载文件")
@Authorize(action = "download")
public void restDownLoad(@PathVariable("id") String id,
@PathVariable("name") String name,
HttpServletResponse response,
HttpServletRequest request) throws IOException {
@ApiOperation("指定文件名下载文件")
@Authorize(action = "download", description = "下载文件")
public void restDownLoad(@ApiParam("文件的id或者md5") @PathVariable("id") String id,
@ApiParam("文件名") @PathVariable("name") String name,
@ApiParam(hidden = true) HttpServletResponse response,
@ApiParam(hidden = true) HttpServletRequest request) throws IOException {
downLoad(id, name, response, request);
}
@@ -151,11 +174,11 @@ public class FileController {
* @throws org.hswebframework.web.NotFoundException 文件不存在
*/
@GetMapping(value = "/download/{id}")
@AccessLogger("下载文件")
@Authorize(action = "download")
public void downLoad(@PathVariable("id") String idOrMd5,
@RequestParam(value = "name", required = false) String name,
HttpServletResponse response, HttpServletRequest request)
@ApiOperation("下载文件")
@Authorize(action = "download", description = "下载文件")
public void downLoad(@ApiParam("文件的id或者md5") @PathVariable("id") String idOrMd5,
@ApiParam(value = "文件名,如果未指定,默认为上传时的文件名", required = false) @RequestParam(value = "name", required = false) String name,
@ApiParam(hidden = true) HttpServletResponse response, @ApiParam(hidden = true) HttpServletRequest request)
throws IOException {
FileInfoEntity fileInfo = fileInfoService.selectByIdOrMd5(idOrMd5);
if (fileInfo == null || !DataStatus.STATUS_ENABLED.equals(fileInfo.getStatus())) {
@@ -209,8 +232,8 @@ public class FileController {
* @return 文件上传结果.
*/
@PostMapping(value = "/upload-multi")
@AccessLogger("上传多个文件")
@Authorize(action = "upload")
@ApiOperation("上传多个文件")
@Authorize(action = "upload", description = "上传文件")
public ResponseMessage<List<FileInfoEntity>> upload(@RequestParam("files") MultipartFile[] files) {
return ResponseMessage.ok(Stream.of(files)
.map(this::upload)
@@ -231,8 +254,8 @@ public class FileController {
* @return 上传结果
*/
@PostMapping(value = "/upload")
@AccessLogger("上传文件")
@Authorize(action = "upload")
@AccessLogger("上传单个文件")
@Authorize(action = "upload", description = "上传文件")
public ResponseMessage<FileInfoEntity> upload(@RequestParam("file") MultipartFile file) {
List<FileInfoEntity> fileInfoList = new LinkedList<>();
Authentication authentication = Authentication.current().orElse(null);
@@ -249,7 +272,7 @@ public class FileController {
if (params.get("charset") == null) {
try {
fileName = new String(file.getOriginalFilename().getBytes("ISO-8859-1"), "utf-8");
} catch (@SuppressWarnings("all")UnsupportedEncodingException ignore) {
} catch (@SuppressWarnings("all") UnsupportedEncodingException ignore) {
}
}
if (logger.isInfoEnabled()) {
@@ -272,8 +295,8 @@ public class FileController {
}
@PostMapping(value = "/upload-static")
@AccessLogger("上传静态文件")
@Authorize(action = "static")
@ApiOperation(value = "上传静态文件", notes = "上传后响应结果的result字段为文件的访问地址")
@Authorize(action = "static", description = "上传静态文件")
public ResponseMessage<String> uploadStatic(@RequestParam("file") MultipartFile file) throws IOException {
if (file.isEmpty()) {
return ResponseMessage.ok();
@@ -282,7 +305,7 @@ public class FileController {
}
@GetMapping(value = "/md5/{md5}")
@AccessLogger("根据MD5获取文件信息")
@ApiOperation("根据MD5获取文件信息")
public ResponseMessage<FileInfoEntity> uploadStatic(@PathVariable String md5) throws IOException {
return ofNullable(fileInfoService.selectByMd5(md5))
.map(ResponseMessage::ok)

View File

@@ -1,7 +1,9 @@
package org.hswebframework.web.controller.file;
import io.swagger.annotations.Api;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
import org.hswebframework.web.controller.QueryController;
import org.hswebframework.web.controller.SimpleGenericEntityController;
import org.hswebframework.web.entity.file.FileInfoEntity;
import org.hswebframework.web.logging.AccessLogger;
@@ -17,9 +19,9 @@ import org.springframework.web.bind.annotation.RestController;
*/
@RestController
@RequestMapping("${hsweb.web.mappings.file-info:file-info}")
@Authorize(permission = "file-info")
@AccessLogger("文件信息")
public class FileInfoController implements SimpleGenericEntityController<FileInfoEntity, String, QueryParamEntity> {
@Authorize(permission = "file-info", description = "文件信息管理")
@Api(value = "文件信息管理",tags = "文件管理-文件信息管理")
public class FileInfoController implements QueryController<FileInfoEntity, String, QueryParamEntity> {
private FileInfoService fileInfoService;
@@ -29,6 +31,7 @@ public class FileInfoController implements SimpleGenericEntityController<FileInf
}
@Override
@SuppressWarnings("all")
public FileInfoService getService() {
return fileInfoService;
}

View File

@@ -18,6 +18,8 @@
package org.hswebframework.web.authorization.oauth2.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.hswebframework.web.WebUtil;
import org.hswebframework.web.authorization.oauth2.client.OAuth2Constants;
import org.hswebframework.web.authorization.oauth2.client.OAuth2RequestService;
@@ -42,6 +44,7 @@ import java.net.URLEncoder;
*/
@Controller
@RequestMapping("${hsweb.web.mappings.oauth2-client-callback:oauth2}")
@Api(tags = "OAuth2.0-客户端请求", value = "OAuth2.0客户端")
public class OAuth2ClientController {
private OAuth2RequestService oAuth2RequestService;
@@ -62,6 +65,7 @@ public class OAuth2ClientController {
@GetMapping("/state")
@ResponseBody
@ApiOperation("申请一个state")
public ResponseMessage<String> requestState(HttpSession session) {
String state = IDGenerator.RANDOM.generate();
session.setAttribute(STATE_SESSION_KEY, state);
@@ -69,6 +73,7 @@ public class OAuth2ClientController {
}
@GetMapping("/boot/{serverId}")
@ApiOperation("跳转至OAuth2.0服务授权页面")
public RedirectView boot(@PathVariable String serverId,
@RequestParam(defaultValue = "/") String redirect,
HttpServletRequest request,
@@ -90,6 +95,7 @@ public class OAuth2ClientController {
}
@GetMapping("/callback/{serverId}")
@ApiOperation(value = "OAuth2.0授权完成后回调", hidden = true)
public RedirectView callback(@RequestParam(defaultValue = "/") String redirect,
@PathVariable String serverId,
@RequestParam String code,
@@ -98,9 +104,9 @@ public class OAuth2ClientController {
HttpSession session) throws UnsupportedEncodingException {
try {
String cachedState = (String) session.getAttribute(STATE_SESSION_KEY);
// TODO: 2017/11/29 未验证state
// if (!state.equals(cachedState)) throw new BusinessException("state error");
oAuth2RequestService.doEvent(serverId, new OAuth2CodeAuthBeforeEvent(code, state, request::getParameter));
// TODO: 17-4-7 验证并解码redirect
return new RedirectView(URLDecoder.decode(redirect, "UTF-8"));
} finally {
session.removeAttribute(STATE_SESSION_KEY);

View File

@@ -18,6 +18,7 @@
package org.hswebframework.web.authorization.oauth2.controller;
import io.swagger.annotations.Api;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
import org.hswebframework.web.controller.GenericEntityController;
@@ -36,7 +37,7 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("${hsweb.web.mappings.oauth2-server-config:oauth2-server-config}")
@Authorize(permission = "oauth2-server-config")
@AccessLogger("OAuth2服务配置")
@Api(tags = "OAuth2.0-服务配置")
public class OAuth2ServerConfigController implements GenericEntityController<OAuth2ServerConfigEntity, String, QueryParamEntity, OAuth2ServerConfigEntity> {
private OAuth2ServerConfigService oAuth2ServerConfigService;

View File

@@ -18,6 +18,7 @@
package org.hswebframework.web.authorization.oauth2.controller;
import io.swagger.annotations.Api;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
import org.hswebframework.web.controller.GenericEntityController;
@@ -37,7 +38,7 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("${hsweb.web.mappings.oauth2-user-token:oauth2-user-token}")
@Authorize(permission = "oauth2-user-token")
@AccessLogger("OAuth2用户授权信息")
@Api(tags = "OAuth2.0-客户端用户授权信息",value = "OAuth2.0客户端授权信息")
public class OAuth2UserTokenController
implements QueryController<OAuth2UserTokenEntity, String, QueryParamEntity> {

View File

@@ -39,12 +39,10 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
/**
* TODO 完成注释
*
* @author zhouhao
*/
@RestController
@Api(tags = "hsweb-oauth2", description = "OAuth2授权", hidden = true)
@Api(tags = "OAuth2.0-授权", value = "OAuth2.0")
@RequestMapping("${hsweb.web.mappings.authorize-oauth2:oauth2/authorize}")
public class OAuth2AuthorizeController {
@@ -54,9 +52,8 @@ public class OAuth2AuthorizeController {
@Resource
private OAuth2Granter oAuth2Granter;
@GetMapping(params = "response_type=code")
@ApiOperation("登录用户获取OAuth2.0授权码")
@ApiOperation("获取当前登录用户OAuth2.0授权码")
@Authorize
public AuthorizationCodeModel requestCode(
@RequestParam("redirect_uri") String redirectUri,
@@ -77,7 +74,7 @@ public class OAuth2AuthorizeController {
@GetMapping(params = "response_type=token")
@ApiOperation("implicit方式授权")
@ApiOperation(value = "implicit方式授权",tags = "OAuth2.0-申请token")
public ImplicitAccessTokenModel authorizeByImplicit(
@RequestParam(value = "redirect_uri") String redirect_uri,
@RequestParam(value = "state") String state,

View File

@@ -18,7 +18,7 @@
package org.hswebframework.web.authorization.oauth2.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.*;
import org.hswebframework.web.authorization.oauth2.server.OAuth2AccessToken;
import org.hswebframework.web.authorization.oauth2.server.exception.GrantTokenException;
import org.hswebframework.web.authorization.oauth2.server.support.OAuth2Granter;
@@ -29,6 +29,7 @@ import org.hswebframework.web.authorization.oauth2.server.support.password.HttpP
import org.hswebframework.web.authorization.oauth2.server.support.refresh.HttpRefreshTokenRequest;
import org.hswebframework.web.oauth2.core.ErrorType;
import org.hswebframework.web.oauth2.core.GrantType;
import org.hswebframework.web.oauth2.core.OAuth2Constants;
import org.hswebframework.web.oauth2.model.AccessTokenModel;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -37,12 +38,13 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
/**
* @author zhouhao
*/
@RestController
@Api(tags = "hsweb-oauth2", description = "OAuth2授权token获取", hidden = true)
@Api(tags = "OAuth2.0-申请token", value = "OAuth2.0")
@RequestMapping("${hsweb.web.mappings.authorize-oauth2:oauth2/token}")
public class OAuth2TokenController {
@@ -50,8 +52,20 @@ public class OAuth2TokenController {
private OAuth2Granter oAuth2Granter;
@PostMapping
@ApiOperation(value = "申请token", notes = "具体请求方式请参照: http://www.ruanyifeng.com/blog/2014/05/oauth_2_0.html")
@ApiImplicitParams(
{
@ApiImplicitParam(paramType = "query", name = OAuth2Constants.client_id),
@ApiImplicitParam(paramType = "query", name = OAuth2Constants.client_secret),
@ApiImplicitParam(paramType = "query", name = OAuth2Constants.refresh_token),
@ApiImplicitParam(paramType = "query", name = OAuth2Constants.code),
@ApiImplicitParam(paramType = "query", name = OAuth2Constants.scope, example = "user-info:get,share:add"),
@ApiImplicitParam(paramType = "header", name = OAuth2Constants.authorization, example = "Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW")
}
)
public AccessTokenModel requestToken(
@RequestParam("grant_type") String grant_type,
@RequestParam("grant_type"
) @ApiParam(allowableValues = GrantType.authorization_code + "," + GrantType.client_credentials + "," + GrantType.password + "," + GrantType.refresh_token + "," + GrantType.implicit) String grant_type,
HttpServletRequest request) {
OAuth2AccessToken accessToken = null;
switch (grant_type) {

View File

@@ -22,6 +22,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.hswebframework.web.authorization.Authentication;
import org.hswebframework.web.authorization.AuthenticationHolder;
import org.hswebframework.web.authorization.exception.AccessDenyException;
import org.hswebframework.web.authorization.exception.UnAuthorizedException;
import org.hswebframework.web.authorization.oauth2.server.OAuth2AccessToken;
import org.hswebframework.web.authorization.oauth2.server.exception.GrantTokenException;
@@ -36,7 +37,7 @@ import javax.annotation.Resource;
* @author zhouhao
*/
@RestController
@Api(tags = "hsweb-oauth2", description = "OAuth2授权", hidden = true)
@Api(tags = "OAuth2.0-获取用户信息", value = "OAuth2.0")
@RequestMapping("${hsweb.web.mappings.oauth2-auth-info:oauth2/user-auth-info}")
public class OAuth2UserInfoController {
@@ -45,7 +46,7 @@ public class OAuth2UserInfoController {
private AccessTokenService accessTokenService;
@GetMapping
@ApiOperation("根据accessToken获取用户信息")
@ApiOperation("根据accessToken获取对应用户信息")
public ResponseMessage<Authentication> getLoginUser(@RequestParam("access_token") String access_token) {
OAuth2AccessToken auth2AccessEntity = accessTokenService.getTokenByAccessToken(access_token);
if (null == auth2AccessEntity) {
@@ -55,7 +56,7 @@ public class OAuth2UserInfoController {
}
@GetMapping("/{userId}")
@ApiOperation("根据accessToken获取用户信息")
@ApiOperation("根据accessToken获取特定的用户信息")
public ResponseMessage<Authentication> getUserById(
@PathVariable("userId") String userId,
@RequestParam("access_token") String access_token) {
@@ -63,6 +64,9 @@ public class OAuth2UserInfoController {
if (null == auth2AccessEntity) {
throw new GrantTokenException(ErrorType.EXPIRED_TOKEN);
}
if (auth2AccessEntity.getScope() == null || !auth2AccessEntity.getScope().contains("user-info")) {
throw new GrantTokenException(ErrorType.UNSUPPORTED_GRANT_TYPE);
}
return ResponseMessage.ok(AuthenticationHolder.get(userId));
}

View File

@@ -21,8 +21,6 @@ package org.hswebframework.web.oauth2.model;
import org.hswebframework.web.commons.model.Model;
/**
* TODO 完成注释
*
* @author zhouhao
*/
public class AccessTokenModel implements Model {

View File

@@ -21,11 +21,10 @@ package org.hswebframework.web.oauth2.model;
import org.hswebframework.web.commons.model.Model;
/**
* TODO 完成注释
*
* @author zhouhao
*/
public class ImplicitAccessTokenModel implements Model {
private static final long serialVersionUID = -8797158129087670407L;
private String access_token;
private String token_type;

View File

@@ -17,6 +17,7 @@
package org.hswebframework.web.controller.organizational;
import io.swagger.annotations.Api;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.authorization.annotation.RequiresDataAccess;
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
@@ -35,9 +36,8 @@ import org.springframework.web.bind.annotation.RestController;
*/
@RestController
@RequestMapping("${hsweb.web.mappings.department:department}")
@Authorize(permission = "department")
@RequiresDataAccess
@AccessLogger("部门管理")
@Authorize(permission = "department", description = "部门管理", dataAccess = @RequiresDataAccess)
@Api(value = "部门管理",tags = "组织架构-部门管理")
public class DepartmentController implements SimpleGenericEntityController<DepartmentEntity, String, QueryParamEntity> {
private DepartmentService departmentService;

View File

@@ -1,5 +1,7 @@
package org.hswebframework.web.controller.organizational;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.hswebframework.web.authorization.Permission;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
@@ -21,8 +23,8 @@ import java.util.List;
*/
@RestController
@RequestMapping("${hsweb.web.mappings.district:district}")
@Authorize(permission = "district")
@AccessLogger("行政区域")
@Authorize(permission = "district", description = "行政区划管理")
@Api(value = "行政区划管理",tags = "组织架构-行政区划管理")
public class DistrictController implements SimpleGenericEntityController<DistrictEntity, String, QueryParamEntity> {
private DistrictService districtService;
@@ -39,21 +41,21 @@ public class DistrictController implements SimpleGenericEntityController<Distric
@GetMapping("/code/{code}")
@Authorize(action = Permission.ACTION_QUERY)
@AccessLogger("根据行政区划代码获取")
@ApiOperation("根据行政区划代码获取")
public ResponseMessage<DistrictEntity> getByCode(@PathVariable String code) {
return ResponseMessage.ok(districtService.selectByCode(code));
}
@GetMapping("/all")
@Authorize(action = Permission.ACTION_QUERY)
@AccessLogger("获取全部行政区划")
@ApiOperation("获取全部行政区划")
public ResponseMessage<List<DistrictEntity>> all() {
return ResponseMessage.ok(districtService.select());
}
@PatchMapping("/batch")
@Authorize(action = Permission.ACTION_UPDATE)
@AccessLogger("批量修改数据")
@ApiOperation("批量修改数据")
public ResponseMessage<Void> updateBatch(@RequestBody List<DistrictEntity> batch) {
districtService.updateBatch(batch);
return ResponseMessage.ok();
@@ -61,7 +63,7 @@ public class DistrictController implements SimpleGenericEntityController<Distric
@PutMapping("/{id}/disable")
@Authorize(action = Permission.ACTION_DISABLE)
@AccessLogger("禁用机构")
@ApiOperation("禁用机构")
public ResponseMessage<Boolean> disable(@PathVariable String id) {
districtService.disable(id);
return ResponseMessage.ok();
@@ -69,7 +71,7 @@ public class DistrictController implements SimpleGenericEntityController<Distric
@PutMapping("/{id}/enable")
@Authorize(action = Permission.ACTION_ENABLE)
@AccessLogger("启用机构")
@ApiOperation("启用机构")
public ResponseMessage<Boolean> enable(@PathVariable String id) {
districtService.enable(id);
return ResponseMessage.ok();

View File

@@ -17,6 +17,8 @@
package org.hswebframework.web.controller.organizational;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.hswebframework.web.authorization.Permission;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.authorization.annotation.RequiresDataAccess;
@@ -42,9 +44,8 @@ import java.util.List;
*/
@RestController
@RequestMapping("${hsweb.web.mappings.organizational:organizational}")
@Authorize(permission = "organizational")
@RequiresDataAccess
@AccessLogger("组织管理")
@Authorize(permission = "organizational",description = "机构管理",dataAccess = @RequiresDataAccess)
@Api(value = "机构管理",tags = "组织架构-机构管理")
public class OrganizationalController implements SimpleGenericEntityController<OrganizationalEntity, String, QueryParamEntity> {
private OrganizationalService organizationalService;
@@ -61,7 +62,7 @@ public class OrganizationalController implements SimpleGenericEntityController<O
@PatchMapping("/batch")
@Authorize(action = Permission.ACTION_UPDATE)
@AccessLogger("批量修改数据")
@ApiOperation("批量修改数据")
public ResponseMessage<Void> updateBatch(@RequestBody List<OrganizationalEntity> batch) {
organizationalService.updateBatch(batch);
return ResponseMessage.ok();
@@ -69,7 +70,7 @@ public class OrganizationalController implements SimpleGenericEntityController<O
@PutMapping("/{id}/disable")
@Authorize(action = Permission.ACTION_DISABLE)
@AccessLogger("禁用机构")
@ApiOperation("禁用机构")
public ResponseMessage<Boolean> disable(@PathVariable String id) {
organizationalService.disable(id);
return ResponseMessage.ok();
@@ -77,7 +78,7 @@ public class OrganizationalController implements SimpleGenericEntityController<O
@PutMapping("/{id}/enable")
@Authorize(action = Permission.ACTION_ENABLE)
@AccessLogger("启用机构")
@ApiOperation("启用机构")
public ResponseMessage<Boolean> enable(@PathVariable String id) {
organizationalService.enable(id);
return ResponseMessage.ok();

View File

@@ -17,6 +17,8 @@
package org.hswebframework.web.controller.organizational;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.hswebframework.web.NotFoundException;
import org.hswebframework.web.authorization.Permission;
import org.hswebframework.web.authorization.annotation.Authorize;
@@ -46,8 +48,8 @@ import java.util.List;
*/
@RestController
@RequestMapping("${hsweb.web.mappings.person:person}")
@Authorize(permission = "person")
@AccessLogger("人员")
@Authorize(permission = "person",description = "人员管理")
@Api(value = "人员管理",tags = "组织架构-人员管理")
public class PersonController implements SimpleGenericEntityController<PersonEntity, String, QueryParamEntity> {
private PersonService personService;
@@ -68,7 +70,7 @@ public class PersonController implements SimpleGenericEntityController<PersonEnt
}
@GetMapping("/me")
@AccessLogger("查看当前登录用户的人员信息")
@ApiOperation("查看当前登录用户的人员信息")
@Authorize(merge = false)
public ResponseMessage<PersonAuthBindEntity> getLoginUserPerson() {
PersonnelAuthorization authorization = PersonnelAuthorization
@@ -78,7 +80,7 @@ public class PersonController implements SimpleGenericEntityController<PersonEnt
}
@PutMapping("/me")
@AccessLogger("修改个人信息")
@ApiOperation("修改个人信息")
@Authorize(merge = false)
public ResponseMessage<String> updateMePersonInfo(@RequestBody PersonAuthBindEntity bindEntity) {
PersonnelAuthorization authorization = PersonnelAuthorization
@@ -100,7 +102,7 @@ public class PersonController implements SimpleGenericEntityController<PersonEnt
}
@GetMapping("/me/authorization")
@AccessLogger("查看当前登录用户的人员权限信息")
@ApiOperation("查看当前登录用户的人员权限信息")
@Authorize(merge = false)
public ResponseMessage<PersonnelAuthorization> getLoginUserPersonDetail() {
PersonnelAuthorization authorization = PersonnelAuthorization
@@ -110,14 +112,14 @@ public class PersonController implements SimpleGenericEntityController<PersonEnt
}
@GetMapping("/{id}/detail")
@AccessLogger("查看人员详情")
@ApiOperation("查看人员详情")
@Authorize(action = Permission.ACTION_GET)
public ResponseMessage<PersonAuthBindEntity> getDetail(@PathVariable String id) {
return ResponseMessage.ok(personService.selectAuthBindByPk(id));
}
@PostMapping("/detail")
@AccessLogger("新增人员信息,并关联用户信息")
@ApiOperation("新增人员信息,并关联用户信息")
@Authorize(action = Permission.ACTION_ADD)
@ResponseStatus(HttpStatus.CREATED)
public ResponseMessage<String> getDetail(@RequestBody PersonAuthBindEntity bindEntity) {
@@ -125,7 +127,7 @@ public class PersonController implements SimpleGenericEntityController<PersonEnt
}
@PutMapping("/{id}/detail")
@AccessLogger("修改人员信息,并关联用户信息")
@ApiOperation("修改人员信息,并关联用户信息")
@Authorize(action = Permission.ACTION_UPDATE)
public ResponseMessage<String> getDetail(@PathVariable String id, @RequestBody PersonAuthBindEntity bindEntity) {
bindEntity.setId(id);
@@ -134,7 +136,7 @@ public class PersonController implements SimpleGenericEntityController<PersonEnt
}
@GetMapping("/in-position/{positionId}")
@AccessLogger("获取指定岗位的人员")
@ApiOperation("获取指定岗位的人员")
@Authorize(action = Permission.ACTION_GET)
public ResponseMessage<List<PersonEntity>> getByPositionId(@PathVariable String positionId) {
return ResponseMessage.ok(personService.selectByPositionId(positionId));

View File

@@ -17,17 +17,12 @@
package org.hswebframework.web.controller.organizational;
import org.hswebframework.web.authorization.Permission;
import io.swagger.annotations.Api;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.authorization.annotation.RequiresDataAccess;
import org.hswebframework.web.commons.entity.PagerResult;
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.organizational.DepartmentEntity;
import org.hswebframework.web.entity.organizational.PositionEntity;
import org.hswebframework.web.logging.AccessLogger;
import org.hswebframework.web.service.organizational.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -40,9 +35,8 @@ import org.springframework.web.bind.annotation.RestController;
*/
@RestController
@RequestMapping("${hsweb.web.mappings.position:position}")
@Authorize(permission = "position")
@RequiresDataAccess
@AccessLogger("职位管理")
@Authorize(permission = "position",description = "职位管理",dataAccess = @RequiresDataAccess)
@Api(value = "职位管理",tags = "组织架构-职位管理")
public class PositionController implements SimpleGenericEntityController<PositionEntity, String, QueryParamEntity> {
private PositionService positionService;

View File

@@ -1,5 +1,6 @@
package org.hswebframework.web.controller.organizational;
import io.swagger.annotations.Api;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
import org.hswebframework.web.controller.SimpleGenericEntityController;
@@ -17,8 +18,8 @@ import org.springframework.web.bind.annotation.RestController;
*/
@RestController
@RequestMapping("${hsweb.web.mappings.relationDefine:relation/define}")
@Authorize(permission = "relation-define")
@AccessLogger("关系定义")
@Authorize(permission = "relation-define",description = "关系定义管理")
@Api(value = "关系定义管理",tags = "组织架构-关系定义管理")
public class RelationDefineController implements SimpleGenericEntityController<RelationDefineEntity, String, QueryParamEntity> {
private RelationDefineService relationDefineService;

View File

@@ -1,33 +1,34 @@
package org.hswebframework.web.controller.organizational;
import io.swagger.annotations.Api;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
import org.hswebframework.web.controller.SimpleGenericEntityController;
import org.hswebframework.web.entity.organizational.RelationInfoEntity;
import org.hswebframework.web.logging.AccessLogger;
import org.hswebframework.web.service.organizational.RelationInfoService;
import org.hswebframework.web.service.organizational.RelationInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 关系信息
* 关系信息
*
* @author hsweb-generator-online
*/
@RestController
@RequestMapping("${hsweb.web.mappings.relationInfo:relation/info}")
@Authorize(permission = "relation/info")
@AccessLogger("关系信息")
@Authorize(permission = "relation/info", description = "关系管理")
@Api(value = "关系管理",tags = "组织架构-关系管理")
public class RelationInfoController implements SimpleGenericEntityController<RelationInfoEntity, String, QueryParamEntity> {
private RelationInfoService relationInfoService;
@Autowired
public void setRelationInfoService(RelationInfoService relationInfoService) {
this.relationInfoService = relationInfoService;
}
@Override
public RelationInfoService getService() {
return relationInfoService;

View File

@@ -3,11 +3,10 @@ package org.hswebframework.web.entity.organizational;
import org.hswebframework.web.commons.entity.Entity;
/**
* TODO 完成注释
*
* @author zhouhao
*/
public class PersonUserEntity implements Entity {
private static final long serialVersionUID = -2619415787107625818L;
private String username;
private String password;

View File

@@ -16,6 +16,7 @@
*/
package org.hswebframework.web.entity.organizational;
import lombok.*;
import org.hswebframework.web.commons.entity.SimpleTreeSortSupportEntity;
import java.util.List;
@@ -25,7 +26,13 @@ import java.util.List;
*
* @author hsweb-generator-online
*/
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SimpleDepartmentEntity extends SimpleTreeSortSupportEntity<String> implements DepartmentEntity {
private static final long serialVersionUID = -2137579829759620323L;
//名称
private String name;
//所在组织id
@@ -37,72 +44,4 @@ public class SimpleDepartmentEntity extends SimpleTreeSortSupportEntity<String>
private List<DepartmentEntity> children;
/**
* @return 名称
*/
@Override
public String getName() {
return this.name;
}
/**
* 设置 名称
*/
@Override
public void setName(String name) {
this.name = name;
}
/**
* @return 所在组织id
*/
@Override
public String getOrgId() {
return this.orgId;
}
/**
* 设置 所在组织id
*/
@Override
public void setOrgId(String orgId) {
this.orgId = orgId;
}
/**
* @return 部门编码
*/
@Override
public String getCode() {
return this.code;
}
/**
* 设置 部门编码
*/
@Override
public void setCode(String code) {
this.code = code;
}
@Override
public Byte getStatus() {
return status;
}
@Override
public void setStatus(Byte status) {
this.status = status;
}
@Override
@SuppressWarnings("unchecked")
public List<DepartmentEntity> getChildren() {
return children;
}
@Override
public void setChildren(List<DepartmentEntity> children) {
this.children = children;
}
}

View File

@@ -1,6 +1,6 @@
package org.hswebframework.web.entity.organizational;
import org.hswebframework.web.commons.entity.SimpleGenericEntity;
import lombok.*;
import org.hswebframework.web.commons.entity.SimpleTreeSortSupportEntity;
import java.util.List;
@@ -10,6 +10,10 @@ import java.util.List;
*
* @author hsweb-generator-online
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class SimpleDistrictEntity extends SimpleTreeSortSupportEntity<String> implements DistrictEntity {
//区域名称,如重庆市
private String name;
@@ -24,129 +28,7 @@ public class SimpleDistrictEntity extends SimpleTreeSortSupportEntity<String> im
//说明
private String describe;
//状态
private Byte status;
private Byte status;
private List<DistrictEntity> children;
/**
* @return 区域名称, 如重庆市
*/
@Override
public String getName() {
return this.name;
}
/**
* @param name 区域名称,如重庆市
*/
@Override
public void setName(String name) {
this.name = name;
}
/**
* @return 区域全称, 如重庆市江津区
*/
@Override
public String getFullName() {
return this.fullName;
}
/**
* @param fullName 区域全称,如重庆市江津区
*/
@Override
public void setFullName(String fullName) {
this.fullName = fullName;
}
/**
* @return 区域级别名称, 如:省
*/
@Override
public String getLevelName() {
return this.levelName;
}
/**
* @param levelName 区域级别名称,如:省
*/
@Override
public void setLevelName(String levelName) {
this.levelName = levelName;
}
/**
* @return 区域级别编码, 如:province
*/
@Override
public String getLevelCode() {
return this.levelCode;
}
/**
* @param levelCode 区域级别编码,如:province
*/
@Override
public void setLevelCode(String levelCode) {
this.levelCode = levelCode;
}
/**
* @return 行政区域代码, 如:500000
*/
@Override
public String getCode() {
return this.code;
}
/**
* @param code 行政区域代码,如:500000
*/
@Override
public void setCode(String code) {
this.code = code;
}
/**
* @return 说明
*/
@Override
public String getDescribe() {
return this.describe;
}
/**
* @param describe 说明
*/
@Override
public void setDescribe(String describe) {
this.describe = describe;
}
/**
* @return 状态
*/
@Override
public Byte getStatus() {
return this.status;
}
/**
* @param status 状态
*/
@Override
public void setStatus(Byte status) {
this.status = status;
}
@Override
public List<DistrictEntity> getChildren() {
return children;
}
@Override
public void setChildren(List<DistrictEntity> children) {
this.children = children;
}
}

View File

@@ -16,6 +16,10 @@
*/
package org.hswebframework.web.entity.organizational;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hswebframework.web.commons.entity.SimpleTreeSortSupportEntity;
import java.util.List;
@@ -25,22 +29,28 @@ import java.util.List;
*
* @author hsweb-generator-online
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class SimpleOrganizationalEntity extends SimpleTreeSortSupportEntity<String> implements OrganizationalEntity {
private static final long serialVersionUID = -1610547249282278768L;
//名称
private String name;
private String name;
//全称
private String fullName;
private String fullName;
//机构编码
private String code;
private String code;
//可选角色
private java.util.List<String> optionalRoles;
private java.util.List<String> optionalRoles;
//是否启用
private Byte status;
private Byte status;
//子级组织
private List<OrganizationalEntity> children;
private String areaId;
@Override
public String getDistrictId() {
return areaId;
@@ -48,91 +58,6 @@ public class SimpleOrganizationalEntity extends SimpleTreeSortSupportEntity<Stri
@Override
public void setDistrictId(String districtId) {
this.areaId = districtId;
}
/**
* @return 名称
*/
@Override
public String getName() {
return this.name;
}
/**
* 设置 名称
*/
@Override
public void setName(String name) {
this.name = name;
}
/**
* @return 全称
*/
@Override
public String getFullName() {
return this.fullName;
}
/**
* 设置 全称
*/
@Override
public void setFullName(String fullName) {
this.fullName = fullName;
}
/**
* @return 机构编码
*/
@Override
public String getCode() {
return this.code;
}
/**
* 设置 机构编码
*/
@Override
public void setCode(String code) {
this.code = code;
}
/**
* @return 可选角色
*/
@Override
public java.util.List<String> getOptionalRoles() {
return this.optionalRoles;
}
/**
* 设置 可选角色
*/
@Override
public void setOptionalRoles(java.util.List<String> optionalRoles) {
this.optionalRoles = optionalRoles;
}
@Override
@SuppressWarnings("unchecked")
public List<OrganizationalEntity> getChildren() {
return children;
}
@Override
public void setChildren(List<OrganizationalEntity> children) {
this.children = children;
}
@Override
public Byte getStatus() {
return status;
}
@Override
public void setStatus(Byte status) {
this.status = status;
setAreaId(districtId);
}
}

View File

@@ -3,8 +3,6 @@ package org.hswebframework.web.entity.organizational;
import java.util.Set;
/**
* TODO 完成注释
*
* @author zhouhao
*/
public class SimplePersonAuthBindEntity extends SimplePersonEntity implements PersonAuthBindEntity {

View File

@@ -16,23 +16,30 @@
*/
package org.hswebframework.web.entity.organizational;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotBlank;
import org.hswebframework.web.commons.entity.SimpleGenericEntity;
import java.util.Set;
/**
* 人员
*
* @author hsweb-generator-online
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class SimplePersonEntity extends SimpleGenericEntity<String> implements PersonEntity {
private static final long serialVersionUID = -4232153898188508965L;
//姓名
@NotBlank
private String name;
//性别
private Byte sex;
private Byte sex;
//电子邮箱
@Email
private String email;
@@ -43,136 +50,9 @@ public class SimplePersonEntity extends SimpleGenericEntity<String> implements P
//关联用户id
private String userId;
//状态
private Byte status;
private Byte status;
//备注
private String remark;
/**
* @return 姓名
*/
@Override
public String getName() {
return this.name;
}
/**
* 设置 姓名
*/
@Override
public void setName(String name) {
this.name = name;
}
/**
* @return 性别
*/
@Override
public Byte getSex() {
return this.sex;
}
/**
* 设置 性别
*/
@Override
public void setSex(Byte sex) {
this.sex = sex;
}
/**
* @return 电子邮箱
*/
@Override
public String getEmail() {
return this.email;
}
/**
* 设置 电子邮箱
*/
@Override
public void setEmail(String email) {
this.email = email;
}
/**
* @return 联系电话
*/
@Override
public String getPhone() {
return this.phone;
}
/**
* 设置 联系电话
*/
@Override
public void setPhone(String phone) {
this.phone = phone;
}
/**
* @return 照片
*/
@Override
public String getPhoto() {
return this.photo;
}
/**
* 设置 照片
*/
@Override
public void setPhoto(String photo) {
this.photo = photo;
}
/**
* @return 关联用户id
*/
@Override
public String getUserId() {
return this.userId;
}
/**
* 设置 关联用户id
*/
@Override
public void setUserId(String userId) {
this.userId = userId;
}
/**
* @return 状态
*/
@Override
public Byte getStatus() {
return this.status;
}
/**
* 设置 状态
*/
@Override
public void setStatus(Byte status) {
this.status = status;
}
/**
* @return 备注
*/
@Override
public String getRemark() {
return this.remark;
}
/**
* 设置 备注
*/
@Override
public void setRemark(String remark) {
this.remark = remark;
}
}

View File

@@ -16,6 +16,10 @@
*/
package org.hswebframework.web.entity.organizational;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hswebframework.web.commons.entity.SimpleGenericEntity;
/**
@@ -23,42 +27,15 @@ import org.hswebframework.web.commons.entity.SimpleGenericEntity;
*
* @author hsweb-generator-online
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class SimplePersonPositionEntity extends SimpleGenericEntity<String> implements PersonPositionEntity {
private static final long serialVersionUID = -7102840729564722732L;
//人员id
private String personId;
//职位id
private String positionId;
/**
* @return 人员id
*/
@Override
public String getPersonId() {
return this.personId;
}
/**
* 设置 人员id
*/
@Override
public void setPersonId(String personId) {
this.personId = personId;
}
/**
* @return 职位id
*/
@Override
public String getPositionId() {
return this.positionId;
}
/**
* 设置 职位id
*/
@Override
public void setPositionId(String positionId) {
this.positionId = positionId;
}
}

View File

@@ -16,6 +16,10 @@
*/
package org.hswebframework.web.entity.organizational;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hswebframework.web.commons.entity.SimpleTreeSortSupportEntity;
import java.util.List;
@@ -25,84 +29,21 @@ import java.util.List;
*
* @author hsweb-generator-online
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class SimplePositionEntity extends SimpleTreeSortSupportEntity<String> implements PositionEntity {
private static final long serialVersionUID = -8912215943657734192L;
//职位名称
private String name;
private String name;
//部门id
private String departmentId;
private String departmentId;
//持有的角色
private List<String> roles;
//备注
private String remark;
private String remark;
private List<PositionEntity> children;
@Override
@SuppressWarnings("unchecked")
public List<PositionEntity> getChildren() {
return children;
}
@Override
public void setChildren(List<PositionEntity> children) {
this.children = children;
}
/**
* @return 职位名称
*/
@Override
public String getName() {
return this.name;
}
/**
* 设置 职位名称
*/
@Override
public void setName(String name) {
this.name = name;
}
/**
* @return 部门id
*/
@Override
public String getDepartmentId() {
return this.departmentId;
}
/**
* 设置 部门id
*/
@Override
public void setDepartmentId(String departmentId) {
this.departmentId = departmentId;
}
@Override
public List<String> getRoles() {
return roles;
}
@Override
public void setRoles(List<String> roles) {
this.roles = roles;
}
/**
* @return 备注
*/
@Override
public String getRemark() {
return this.remark;
}
/**
* 设置 备注
*/
@Override
public void setRemark(String remark) {
this.remark = remark;
}
}

View File

@@ -1,61 +1,26 @@
package org.hswebframework.web.entity.organizational;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hswebframework.web.commons.entity.SimpleGenericEntity;
/**
* 关系定义
* @author hsweb-generator-online
*/
public class SimpleRelationDefineEntity extends SimpleGenericEntity<String> implements RelationDefineEntity{
//关系名称
private String name;
//关系类型ID
private String typeId;
//状态
private Byte status;
/**
* @return 关系名称
*/
@Override
public String getName(){
return this.name;
}
/**
* @param name 关系名称
*/
@Override
public void setName(String name){
this.name=name;
}
/**
* @return 关系类型ID
*/
@Override
public String getTypeId(){
return this.typeId;
}
/**
* @param typeId 关系类型ID
*/
@Override
public void setTypeId(String typeId){
this.typeId=typeId;
}
/**
* @return 状态
*/
@Override
public Byte getStatus(){
return this.status;
}
/**
* @param status 状态
*/
@Override
public void setStatus(Byte status){
this.status=status;
}
* 关系定义
*
* @author hsweb-generator-online
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class SimpleRelationDefineEntity extends SimpleGenericEntity<String> implements RelationDefineEntity {
private static final long serialVersionUID = -8372686525577214172L;
//关系名称
private String name;
//关系类型ID
private String typeId;
//状态
private Byte status;
}

View File

@@ -1,112 +1,32 @@
package org.hswebframework.web.entity.organizational;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hswebframework.web.commons.entity.SimpleGenericEntity;
/**
* 关系信息
* @author hsweb-generator-online
*/
public class SimpleRelationInfoEntity extends SimpleGenericEntity<String> implements RelationInfoEntity{
//关系从
private String relationFrom;
//关系定义id
private String relationId;
//关系至
private String relationTo;
//关系类型从,如:人员
private String relationTypeFrom;
//关系类型至,如:部门
private String relationTypeTo;
//状态
private Byte status;
/**
* @return 关系从
*/
@Override
public String getRelationFrom(){
return this.relationFrom;
}
/**
* @param relationFrom 关系从
*/
@Override
public void setRelationFrom(String relationFrom){
this.relationFrom=relationFrom;
}
/**
* @return 关系定义id
*/
@Override
public String getRelationId(){
return this.relationId;
}
/**
* @param relationId 关系定义id
*/
@Override
public void setRelationId(String relationId){
this.relationId=relationId;
}
/**
* @return 关系至
*/
@Override
public String getRelationTo(){
return this.relationTo;
}
/**
* @param relationTo 关系至
*/
@Override
public void setRelationTo(String relationTo){
this.relationTo=relationTo;
}
/**
* @return 关系类型从,如:人员
*/
@Override
public String getRelationTypeFrom(){
return this.relationTypeFrom;
}
/**
* @param relationTypeFrom 关系类型从,如:人员
*/
@Override
public void setRelationTypeFrom(String relationTypeFrom){
this.relationTypeFrom=relationTypeFrom;
}
/**
* @return 关系类型至,如:部门
*/
@Override
public String getRelationTypeTo(){
return this.relationTypeTo;
}
/**
* @param relationTypeTo 关系类型至,如:部门
*/
@Override
public void setRelationTypeTo(String relationTypeTo){
this.relationTypeTo=relationTypeTo;
}
/**
* @return 状态
*/
@Override
public Byte getStatus(){
return this.status;
}
/**
* @param status 状态
*/
@Override
public void setStatus(Byte status){
this.status=status;
}
* 关系信息
*
* @author hsweb-generator-online
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class SimpleRelationInfoEntity extends SimpleGenericEntity<String> implements RelationInfoEntity {
private static final long serialVersionUID = -7285786918328019221L;
//关系
private String relationFrom;
//关系定义id
private String relationId;
//关系至
private String relationTo;
//关系类型从,如:人员
private String relationTypeFrom;
//关系类型至,如:部门
private String relationTypeTo;
//状态
private Byte status;
}

View File

@@ -1,12 +1,13 @@
package org.hswebframework.web.controller.schedule;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.SimpleGenericEntityController;
import org.hswebframework.web.controller.message.ResponseMessage;
import org.hswebframework.web.entity.schedule.ScheduleJobEntity;
import org.hswebframework.web.logging.AccessLogger;
import org.hswebframework.web.service.schedule.ScheduleJobExecutor;
import org.hswebframework.web.service.schedule.ScheduleJobService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -21,8 +22,8 @@ import java.util.Map;
*/
@RestController
@RequestMapping("${hsweb.web.mappings.scheduleJob:schedule/job}")
@Authorize(permission = "schedule-job")
@AccessLogger("调度任务")
@Authorize(permission = "schedule-job", description = "定时调度管理")
@Api(value = "定时调度管理",tags = "定时调度管理")
public class ScheduleJobController implements SimpleGenericEntityController<ScheduleJobEntity, String, QueryParamEntity> {
private ScheduleJobService scheduleJobService;
@@ -30,11 +31,13 @@ public class ScheduleJobController implements SimpleGenericEntityController<Sche
private ScheduleJobExecutor scheduleJobExecutor;
@Autowired
@Authorize(ignore = true)
public void setScheduleJobExecutor(ScheduleJobExecutor scheduleJobExecutor) {
this.scheduleJobExecutor = scheduleJobExecutor;
}
@Autowired
@Authorize(ignore = true)
public void setScheduleJobService(ScheduleJobService scheduleJobService) {
this.scheduleJobService = scheduleJobService;
}
@@ -46,7 +49,7 @@ public class ScheduleJobController implements SimpleGenericEntityController<Sche
@PutMapping("/{id}/enable")
@Authorize(action = Permission.ACTION_ENABLE)
@AccessLogger("启用")
@ApiOperation("启用任务")
public ResponseMessage<Void> enable(@PathVariable String id) {
scheduleJobService.enable(id);
return ResponseMessage.ok();
@@ -54,15 +57,15 @@ public class ScheduleJobController implements SimpleGenericEntityController<Sche
@PutMapping("/{id}/disable")
@Authorize(action = Permission.ACTION_DISABLE)
@AccessLogger("禁用")
@ApiOperation("禁用任务")
public ResponseMessage<Void> disable(@PathVariable String id) {
scheduleJobService.disable(id);
return ResponseMessage.ok();
}
@PostMapping("/{id}/execute")
@Authorize(action = "execute")
@AccessLogger("执行")
@Authorize(action = "execute", description = "执行任务")
@ApiOperation("执行任务")
public ResponseMessage<Object> execute(@PathVariable String id, @RequestBody Map<String, Object> args) {
return ResponseMessage.ok(scheduleJobExecutor.doExecuteJob(id, args));
}

View File

@@ -1,5 +1,7 @@
package org.hswebframework.web.controller.script;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
import org.hswebframework.web.controller.SimpleGenericEntityController;
@@ -21,8 +23,8 @@ import java.util.Map;
*/
@RestController
@RequestMapping("${hsweb.web.mappings.script:script}")
@Authorize(permission = "script")
@AccessLogger("动态脚本")
@Authorize(permission = "script", description = "动态脚本管理")
@Api("动态脚本")
public class ScriptController implements SimpleGenericEntityController<ScriptEntity, String, QueryParamEntity> {
private ScriptService scriptService;
@@ -46,8 +48,8 @@ public class ScriptController implements SimpleGenericEntityController<ScriptEnt
@GetMapping("/{id}/execute")
@AccessLogger("执行脚本")
@Authorize(action = "execute")
@ApiOperation("执行脚本")
@Authorize(action = "execute", description = "执行脚本")
public ResponseMessage<Object> executeForGet(@PathVariable String id, @RequestParam(required = false) Map<String, Object> parameters) throws Exception {
if (parameters == null) {
parameters = new HashMap<>();
@@ -58,8 +60,8 @@ public class ScriptController implements SimpleGenericEntityController<ScriptEnt
@RequestMapping(value = "/{id}/execute", method = {RequestMethod.POST, RequestMethod.PUT})
@AccessLogger("执行脚本")
@Authorize(action = "execute")
@Authorize(action = "execute", description = "执行脚本")
@ApiOperation("执行脚本")
public ResponseMessage<Object> executeFotPostAndPut(@PathVariable String id,
@RequestBody(required = false) Map<String, Object> parameters) throws Exception {
return ResponseMessage.ok(executeForGet(id, parameters));