From 8718506433d2447b530780f0c1345d7368d05135 Mon Sep 17 00:00:00 2001 From: godchao Date: Thu, 13 Jun 2019 10:09:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=A8=A1=E5=9D=97=E7=BB=93?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AuthTokenController.java | 11 +- .../example/controller/SysUserController.java | 69 ++++++++++ .../com/diboot/shiro/config/ShiroConfig.java | 8 +- .../controller/PermissionController.java | 121 ++++++++++++++++++ .../java/com/diboot/shiro/entity/SysUser.java | 4 + .../BaseJwtAuthenticationFilter.java | 5 +- .../{ => jwt}/BaseJwtAuthenticationToken.java | 2 +- .../diboot/shiro/{ => jwt}/BaseJwtRealm.java | 27 +--- .../diboot/shiro/service/AuthWayService.java | 2 +- .../com/diboot/shiro/service/RoleService.java | 12 ++ .../shiro/service/impl/RoleServiceImpl.java | 42 ++++++ .../UsernamePasswordAuthWayServiceImpl.java | 3 +- .../com/diboot/shiro/util/AuthHelper.java | 44 +++++++ .../com/diboot/shiro/vo/PermissionVO.java | 20 +++ .../main/java/com/diboot/shiro/vo/RoleVO.java | 1 + 15 files changed, 328 insertions(+), 43 deletions(-) create mode 100644 diboot-example/src/main/java/com/diboot/example/controller/SysUserController.java create mode 100644 diboot-shiro/src/main/java/com/diboot/shiro/controller/PermissionController.java rename diboot-shiro/src/main/java/com/diboot/shiro/{ => jwt}/BaseJwtAuthenticationFilter.java (97%) rename diboot-shiro/src/main/java/com/diboot/shiro/{ => jwt}/BaseJwtAuthenticationToken.java (99%) rename diboot-shiro/src/main/java/com/diboot/shiro/{ => jwt}/BaseJwtRealm.java (78%) create mode 100644 diboot-shiro/src/main/java/com/diboot/shiro/util/AuthHelper.java create mode 100644 diboot-shiro/src/main/java/com/diboot/shiro/vo/PermissionVO.java diff --git a/diboot-example/src/main/java/com/diboot/example/controller/AuthTokenController.java b/diboot-example/src/main/java/com/diboot/example/controller/AuthTokenController.java index cd85102..d4c05f2 100644 --- a/diboot-example/src/main/java/com/diboot/example/controller/AuthTokenController.java +++ b/diboot-example/src/main/java/com/diboot/example/controller/AuthTokenController.java @@ -2,7 +2,7 @@ package com.diboot.example.controller; import com.diboot.core.vo.JsonResult; import com.diboot.core.vo.Status; -import com.diboot.shiro.BaseJwtAuthenticationToken; +import com.diboot.shiro.jwt.BaseJwtAuthenticationToken; import com.diboot.shiro.config.AuthType; import com.diboot.shiro.entity.SysUser; import com.diboot.shiro.service.AuthWayService; @@ -11,17 +11,14 @@ import org.apache.shiro.subject.Subject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.Map; @RestController -@RequestMapping("/token") +@RequestMapping("/auth") public class AuthTokenController { private static final Logger logger = LoggerFactory.getLogger(AuthTokenController.class); @@ -38,7 +35,7 @@ public class AuthTokenController { * @throws Exception */ @PostMapping("/login") - public JsonResult login(@ModelAttribute SysUser sysUser, HttpServletRequest request, HttpServletResponse response) throws Exception{ + public JsonResult login(@RequestBody SysUser sysUser, HttpServletRequest request, HttpServletResponse response) throws Exception{ String errorMsg = "登录失败"; try{ BaseJwtAuthenticationToken authToken = new BaseJwtAuthenticationToken(authWayServiceMap, sysUser.getUsername(), sysUser.getPassword(), AuthType.USERNAME_PASSWORD); diff --git a/diboot-example/src/main/java/com/diboot/example/controller/SysUserController.java b/diboot-example/src/main/java/com/diboot/example/controller/SysUserController.java new file mode 100644 index 0000000..e5dae18 --- /dev/null +++ b/diboot-example/src/main/java/com/diboot/example/controller/SysUserController.java @@ -0,0 +1,69 @@ +package com.diboot.example.controller; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.diboot.core.util.V; +import com.diboot.core.vo.JsonResult; +import com.diboot.core.vo.Status; +import com.diboot.shiro.entity.SysUser; +import com.diboot.shiro.service.RoleService; +import com.diboot.shiro.service.SysUserService; +import com.diboot.shiro.util.JwtHelper; +import com.diboot.shiro.vo.RoleVO; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; + +@RestController +@RequestMapping("/sysUser") +public class SysUserController { + + private static final Logger logger = LoggerFactory.getLogger(SysUserController.class); + + @Autowired + private RoleService roleService; + + @Autowired + private SysUserService sysUserService; + + /*** + * 获取登录用户信息 + * @param request + * @return + * @throws Exception + */ + @GetMapping("/info") + public JsonResult info(HttpServletRequest request) throws Exception{ + String token = JwtHelper.getRequestToken(request); + if (V.isEmpty(token)){ + return new JsonResult(Status.FAIL_OPERATION, new String[]{"获取数据失败"}); + } + + String username = JwtHelper.getAccountFromToken(token); + if (V.isEmpty(username)){ + return new JsonResult(Status.FAIL_OPERATION, new String[]{"获取数据失败"}); + } + + QueryWrapper query = new QueryWrapper<>(); + query.lambda() + .eq(SysUser::getUsername, username); + List userList = sysUserService.getEntityList(query); + if (V.isEmpty(userList)){ + return new JsonResult(Status.FAIL_OPERATION, new String[]{"获取数据失败"}); + } + + SysUser user = userList.get(0); + + List roleVOList = roleService.getRelatedRoleAndPermissionListByUser(SysUser.class.getSimpleName(), user.getId()); + if (V.isEmpty(roleVOList)){ + return new JsonResult(Status.FAIL_OPERATION, new String[]{"获取用户角色失败"}); + } + + user.setRoleVOList(roleVOList); + + return new JsonResult(Status.OK, user, new String[]{"获取角色列表成功"}); + } +} diff --git a/diboot-shiro/src/main/java/com/diboot/shiro/config/ShiroConfig.java b/diboot-shiro/src/main/java/com/diboot/shiro/config/ShiroConfig.java index 29c0759..681eed0 100644 --- a/diboot-shiro/src/main/java/com/diboot/shiro/config/ShiroConfig.java +++ b/diboot-shiro/src/main/java/com/diboot/shiro/config/ShiroConfig.java @@ -1,7 +1,7 @@ package com.diboot.shiro.config; -import com.diboot.shiro.BaseJwtAuthenticationFilter; -import com.diboot.shiro.BaseJwtRealm; +import com.diboot.shiro.jwt.BaseJwtAuthenticationFilter; +import com.diboot.shiro.jwt.BaseJwtRealm; import org.apache.shiro.mgt.SecurityManager; import org.apache.shiro.realm.Realm; import org.apache.shiro.spring.LifecycleBeanPostProcessor; @@ -57,9 +57,9 @@ public class ShiroConfig { filterChainDefinitionMap.put("/", "anon"); filterChainDefinitionMap.put("/static/**", "anon"); - filterChainDefinitionMap.put("/token/login", "anon"); + filterChainDefinitionMap.put("/auth/login", "anon"); filterChainDefinitionMap.put("/error", "anon"); - filterChainDefinitionMap.put("/token/logout", "logout"); + filterChainDefinitionMap.put("/auth/logout", "logout"); filterChainDefinitionMap.put("/**", "jwt"); shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); diff --git a/diboot-shiro/src/main/java/com/diboot/shiro/controller/PermissionController.java b/diboot-shiro/src/main/java/com/diboot/shiro/controller/PermissionController.java new file mode 100644 index 0000000..b4094ad --- /dev/null +++ b/diboot-shiro/src/main/java/com/diboot/shiro/controller/PermissionController.java @@ -0,0 +1,121 @@ +package com.diboot.shiro.controller; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.diboot.core.controller.BaseCrudRestController; +import com.diboot.core.service.BaseService; +import com.diboot.core.util.BeanUtils; +import com.diboot.core.util.V; +import com.diboot.core.vo.JsonResult; +import com.diboot.core.vo.Pagination; +import com.diboot.core.vo.Status; +import com.diboot.shiro.entity.Permission; +import com.diboot.shiro.service.PermissionService; +import com.diboot.shiro.vo.PermissionVO; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.ui.ModelMap; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; + +/** + * Organization相关Controller + * @author Mazhicheng + * @version 2018/12/23 + * Copyright © www.dibo.ltd + */ +@RestController +@RequestMapping("/permission") +public class PermissionController extends BaseCrudRestController { + + private static final Logger logger = LoggerFactory.getLogger(PermissionService.class); + + @Autowired + private PermissionService permissionService; + + /*** + * 查询ViewObject的分页数据 (此为非继承的自定义使用案例,更简化的调用父类案例请参考UserController) + *

+ * url参数示例: /list?_pageSize=20&_pageIndex=1&_orderBy=id&code=TST + *

+ * @return + * @throws Exception + */ + @RequiresPermissions("permission:list") + @GetMapping("/list") + public JsonResult getVOList(HttpServletRequest request) throws Exception{ + QueryWrapper queryWrapper = buildQuery(request); + // 构建分页 + Pagination pagination = buildPagination(request); + // 查询当前页的Entity主表数据 + List entityList = getService().getEntityList(queryWrapper, pagination); + // 自动转换VO中注解绑定的关联 + List voList = super.convertToVoAndBindRelations(entityList, PermissionVO.class); + + return new JsonResult(Status.OK, voList).bindPagination(pagination); + } + + /*** + * 创建Entity + * @return + * @throws Exception + */ + @RequiresPermissions("permission:add") + @PostMapping("/") + public JsonResult createEntity(@ModelAttribute PermissionVO viewObject, BindingResult result, HttpServletRequest request, ModelMap modelMap) + throws Exception{ + // 转换 + Permission entity = BeanUtils.convert(viewObject, Permission.class); + // 创建 + return super.createEntity(entity, result, modelMap); + } + + /*** + * 查询Entity + * @param id ID + * @return + * @throws Exception + */ + @RequiresPermissions("permission:get") + @GetMapping("/{id}") + public JsonResult getModel(@PathVariable("id")Long id, HttpServletRequest request, ModelMap modelMap) + throws Exception{ + PermissionVO vo = permissionService.getViewObject(id, PermissionVO.class); + return new JsonResult(vo); + } + + /*** + * 更新Entity + * @param id ID + * @return + * @throws Exception + */ + @RequiresPermissions("permission:update") + @PutMapping("/{id}") + public JsonResult updateModel(@PathVariable("id")Long id, @ModelAttribute Permission entity, BindingResult result, + HttpServletRequest request, ModelMap modelMap) throws Exception{ + return super.updateEntity(entity, result, modelMap); + } + + /*** + * 删除用户 + * @param id 用户ID + * @return + * @throws Exception + */ + @RequiresPermissions("permission:delete") + @DeleteMapping("/{id}") + public JsonResult deleteModel(@PathVariable("id")Long id, HttpServletRequest request) throws Exception{ + return super.deleteEntity(id); + } + + @Override + protected BaseService getService() { + return permissionService; + } + +} diff --git a/diboot-shiro/src/main/java/com/diboot/shiro/entity/SysUser.java b/diboot-shiro/src/main/java/com/diboot/shiro/entity/SysUser.java index 94f77a1..4ae9ea2 100644 --- a/diboot-shiro/src/main/java/com/diboot/shiro/entity/SysUser.java +++ b/diboot-shiro/src/main/java/com/diboot/shiro/entity/SysUser.java @@ -2,6 +2,7 @@ package com.diboot.shiro.entity; import com.baomidou.mybatisplus.annotation.TableField; import com.diboot.core.entity.BaseEntity; +import com.diboot.shiro.vo.RoleVO; import lombok.Data; import java.util.List; @@ -31,6 +32,9 @@ public class SysUser extends BaseEntity { @TableField(exist = false) private List roleList; + @TableField(exist = false) + private List roleVOList; + @TableField(exist = false) private List permissionList; } diff --git a/diboot-shiro/src/main/java/com/diboot/shiro/BaseJwtAuthenticationFilter.java b/diboot-shiro/src/main/java/com/diboot/shiro/jwt/BaseJwtAuthenticationFilter.java similarity index 97% rename from diboot-shiro/src/main/java/com/diboot/shiro/BaseJwtAuthenticationFilter.java rename to diboot-shiro/src/main/java/com/diboot/shiro/jwt/BaseJwtAuthenticationFilter.java index 2b7974f..2e53855 100644 --- a/diboot-shiro/src/main/java/com/diboot/shiro/BaseJwtAuthenticationFilter.java +++ b/diboot-shiro/src/main/java/com/diboot/shiro/jwt/BaseJwtAuthenticationFilter.java @@ -1,11 +1,10 @@ -package com.diboot.shiro; +package com.diboot.shiro.jwt; import com.diboot.core.util.JSON; import com.diboot.core.util.V; import com.diboot.core.vo.JsonResult; import com.diboot.core.vo.Status; import com.diboot.shiro.util.JwtHelper; -import org.apache.shiro.SecurityUtils; import org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,7 +39,7 @@ public class BaseJwtAuthenticationFilter extends BasicHttpAuthenticationFilter { logger.warn("Token为空!url="+httpRequest.getRequestURL()); return false; } - //获取userId + //获取username String account = JwtHelper.getAccountFromToken(accessToken); if(V.notEmpty(account)){ logger.debug("Token认证成功!account="+account); diff --git a/diboot-shiro/src/main/java/com/diboot/shiro/BaseJwtAuthenticationToken.java b/diboot-shiro/src/main/java/com/diboot/shiro/jwt/BaseJwtAuthenticationToken.java similarity index 99% rename from diboot-shiro/src/main/java/com/diboot/shiro/BaseJwtAuthenticationToken.java rename to diboot-shiro/src/main/java/com/diboot/shiro/jwt/BaseJwtAuthenticationToken.java index f6dad2f..8de06ed 100644 --- a/diboot-shiro/src/main/java/com/diboot/shiro/BaseJwtAuthenticationToken.java +++ b/diboot-shiro/src/main/java/com/diboot/shiro/jwt/BaseJwtAuthenticationToken.java @@ -1,4 +1,4 @@ -package com.diboot.shiro; +package com.diboot.shiro.jwt; import com.diboot.core.util.V; import com.diboot.shiro.config.AuthType; diff --git a/diboot-shiro/src/main/java/com/diboot/shiro/BaseJwtRealm.java b/diboot-shiro/src/main/java/com/diboot/shiro/jwt/BaseJwtRealm.java similarity index 78% rename from diboot-shiro/src/main/java/com/diboot/shiro/BaseJwtRealm.java rename to diboot-shiro/src/main/java/com/diboot/shiro/jwt/BaseJwtRealm.java index 757e56a..59450f1 100644 --- a/diboot-shiro/src/main/java/com/diboot/shiro/BaseJwtRealm.java +++ b/diboot-shiro/src/main/java/com/diboot/shiro/jwt/BaseJwtRealm.java @@ -1,11 +1,8 @@ -package com.diboot.shiro; +package com.diboot.shiro.jwt; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.diboot.core.entity.BaseEntity; import com.diboot.core.util.V; import com.diboot.shiro.entity.Permission; -import com.diboot.shiro.entity.Role; -import com.diboot.shiro.entity.UserRole; import com.diboot.shiro.service.*; import com.diboot.shiro.vo.RoleVO; import org.apache.shiro.authc.AuthenticationException; @@ -91,27 +88,7 @@ public class BaseJwtRealm extends AuthorizingRealm { BaseEntity user = (BaseEntity) principals.getPrimaryPrincipal(); // 根据用户类型与用户id获取roleList - QueryWrapper query = new QueryWrapper<>(); - query.lambda() - .eq(UserRole::getUserType, userType) - .eq(UserRole::getUserId, user.getId()); - List userRoleList = userRoleService.getEntityList(query); - if (V.isEmpty(userRoleList)){ - return authorizationInfo; - } - List roleIdList = userRoleList.stream() - .map(UserRole::getRoleId) - .collect(Collectors.toList()); - if (V.isEmpty(roleIdList)){ - return authorizationInfo; - } - - // 获取角色列表,并使用VO自动多对多关联permission - QueryWrapper roleQuery = new QueryWrapper<>(); - roleQuery - .lambda() - .in(Role::getId, roleIdList); - List roleVOList = roleService.getViewObjectList(roleQuery, null, RoleVO.class); + List roleVOList = roleService.getRelatedRoleAndPermissionListByUser(userType, user.getId()); if (V.isEmpty(roleVOList)){ return authorizationInfo; diff --git a/diboot-shiro/src/main/java/com/diboot/shiro/service/AuthWayService.java b/diboot-shiro/src/main/java/com/diboot/shiro/service/AuthWayService.java index cc71ebf..2dae3eb 100644 --- a/diboot-shiro/src/main/java/com/diboot/shiro/service/AuthWayService.java +++ b/diboot-shiro/src/main/java/com/diboot/shiro/service/AuthWayService.java @@ -1,7 +1,7 @@ package com.diboot.shiro.service; import com.diboot.core.entity.BaseEntity; -import com.diboot.shiro.BaseJwtAuthenticationToken; +import com.diboot.shiro.jwt.BaseJwtAuthenticationToken; import com.diboot.shiro.config.AuthType; /*** diff --git a/diboot-shiro/src/main/java/com/diboot/shiro/service/RoleService.java b/diboot-shiro/src/main/java/com/diboot/shiro/service/RoleService.java index 43ad2a9..5a6569e 100644 --- a/diboot-shiro/src/main/java/com/diboot/shiro/service/RoleService.java +++ b/diboot-shiro/src/main/java/com/diboot/shiro/service/RoleService.java @@ -2,6 +2,10 @@ package com.diboot.shiro.service; import com.diboot.core.service.BaseService; import com.diboot.shiro.entity.Role; +import com.diboot.shiro.vo.RoleVO; + +import java.util.List; +import java.util.Set; /** * 角色相关Service @@ -11,4 +15,12 @@ import com.diboot.shiro.entity.Role; */ public interface RoleService extends BaseService { + /*** + * 根据用户类型和用户id获取角色关联权限列表 + * @param userType + * @param userId + * @return + */ + List getRelatedRoleAndPermissionListByUser(String userType, Long userId); + } diff --git a/diboot-shiro/src/main/java/com/diboot/shiro/service/impl/RoleServiceImpl.java b/diboot-shiro/src/main/java/com/diboot/shiro/service/impl/RoleServiceImpl.java index 6844a4a..74d64f2 100644 --- a/diboot-shiro/src/main/java/com/diboot/shiro/service/impl/RoleServiceImpl.java +++ b/diboot-shiro/src/main/java/com/diboot/shiro/service/impl/RoleServiceImpl.java @@ -1,12 +1,25 @@ package com.diboot.shiro.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.diboot.core.service.impl.BaseServiceImpl; +import com.diboot.core.util.V; +import com.diboot.shiro.entity.Permission; import com.diboot.shiro.entity.Role; +import com.diboot.shiro.entity.UserRole; import com.diboot.shiro.mapper.RoleMapper; import com.diboot.shiro.service.RoleService; +import com.diboot.shiro.service.UserRoleService; +import com.diboot.shiro.vo.RoleVO; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + /** * 角色相关Service * @author Yangzhao @@ -17,4 +30,33 @@ import org.springframework.stereotype.Service; @Slf4j public class RoleServiceImpl extends BaseServiceImpl implements RoleService { + @Autowired + private UserRoleService userRoleService; + + @Override + public List getRelatedRoleAndPermissionListByUser(String userType, Long userId) { + // 根据用户类型与用户id获取roleList + QueryWrapper query = new QueryWrapper<>(); + query.lambda() + .eq(UserRole::getUserType, userType) + .eq(UserRole::getUserId, userId); + List userRoleList = userRoleService.getEntityList(query); + if (V.isEmpty(userRoleList)){ + return Collections.emptyList(); + } + List roleIdList = userRoleList.stream() + .map(UserRole::getRoleId) + .collect(Collectors.toList()); + if (V.isEmpty(roleIdList)){ + return Collections.emptyList(); + } + + // 获取角色列表,并使用VO自动多对多关联permission + QueryWrapper roleQuery = new QueryWrapper<>(); + roleQuery + .lambda() + .in(Role::getId, roleIdList); + List roleVOList = this.getViewObjectList(roleQuery, null, RoleVO.class); + return roleVOList; + } } diff --git a/diboot-shiro/src/main/java/com/diboot/shiro/service/impl/UsernamePasswordAuthWayServiceImpl.java b/diboot-shiro/src/main/java/com/diboot/shiro/service/impl/UsernamePasswordAuthWayServiceImpl.java index 72f18dc..bce9496 100644 --- a/diboot-shiro/src/main/java/com/diboot/shiro/service/impl/UsernamePasswordAuthWayServiceImpl.java +++ b/diboot-shiro/src/main/java/com/diboot/shiro/service/impl/UsernamePasswordAuthWayServiceImpl.java @@ -2,9 +2,8 @@ package com.diboot.shiro.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.diboot.core.entity.BaseEntity; -import com.diboot.core.util.BeanUtils; import com.diboot.core.util.V; -import com.diboot.shiro.BaseJwtAuthenticationToken; +import com.diboot.shiro.jwt.BaseJwtAuthenticationToken; import com.diboot.shiro.config.AuthType; import com.diboot.shiro.entity.SysUser; import com.diboot.shiro.service.AuthWayService; diff --git a/diboot-shiro/src/main/java/com/diboot/shiro/util/AuthHelper.java b/diboot-shiro/src/main/java/com/diboot/shiro/util/AuthHelper.java new file mode 100644 index 0000000..2dbb46d --- /dev/null +++ b/diboot-shiro/src/main/java/com/diboot/shiro/util/AuthHelper.java @@ -0,0 +1,44 @@ +package com.diboot.shiro.util; + +import com.diboot.core.entity.BaseEntity; +import org.apache.shiro.SecurityUtils; +import org.apache.shiro.subject.Subject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AuthHelper { + private static final Logger logger = LoggerFactory.getLogger(AuthHelper.class); + + /** + * 得到当前登录的用户名 + * @return + */ + public static T getCurrentUser(){ + try{ + Subject subject = SecurityUtils.getSubject(); + if(subject != null && subject.isAuthenticated()){ + return (T)subject.getPrincipal(); + } + } + catch (Exception e){ + logger.warn("获取用户信息异常", e); + } + return null; + } + + /** + * 得到当前登录的用户id + * @return + */ + public static Long getCurrentUserId(){ + BaseEntity user = getCurrentUser(); + if(user != null){ + return (Long)user.getId(); + } + if(logger.isDebugEnabled()){ + logger.warn("无法获取当前用户Id!"); + } + return null; + } + +} diff --git a/diboot-shiro/src/main/java/com/diboot/shiro/vo/PermissionVO.java b/diboot-shiro/src/main/java/com/diboot/shiro/vo/PermissionVO.java new file mode 100644 index 0000000..d80cb76 --- /dev/null +++ b/diboot-shiro/src/main/java/com/diboot/shiro/vo/PermissionVO.java @@ -0,0 +1,20 @@ +package com.diboot.shiro.vo; + +import com.diboot.core.binding.annotation.BindEntityList; +import com.diboot.shiro.entity.Permission; +import com.diboot.shiro.entity.Role; +import lombok.Data; + +import java.util.List; + +/** + * @author Yangzhao + * @version v2.0 + * @date 2019/6/6 + */ +@Data +public class PermissionVO extends Permission { + + private static final long serialVersionUID = 860775286174387052L; + +} \ No newline at end of file diff --git a/diboot-shiro/src/main/java/com/diboot/shiro/vo/RoleVO.java b/diboot-shiro/src/main/java/com/diboot/shiro/vo/RoleVO.java index 3d6f717..923438f 100644 --- a/diboot-shiro/src/main/java/com/diboot/shiro/vo/RoleVO.java +++ b/diboot-shiro/src/main/java/com/diboot/shiro/vo/RoleVO.java @@ -6,6 +6,7 @@ import com.diboot.shiro.entity.Role; import lombok.Data; import java.util.List; +import java.util.Set; /** * @author Yangzhao