diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/aspect/PreAuthorizeAspect.java b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/aspect/PreAuthorizeAspect.java index 3a44d82b..47d763b8 100644 --- a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/aspect/PreAuthorizeAspect.java +++ b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/aspect/PreAuthorizeAspect.java @@ -2,6 +2,7 @@ package com.ruoyi.common.security.aspect; import java.lang.reflect.Method; import java.util.Collection; + import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.Signature; import org.aspectj.lang.annotation.Around; @@ -19,81 +20,67 @@ import com.ruoyi.system.api.model.LoginUser; /** * 自定义权限实现 - * + * * @author ruoyi */ @Aspect @Component -public class PreAuthorizeAspect -{ +public class PreAuthorizeAspect { @Autowired private TokenService tokenService; - /** 所有权限标识 */ + /** + * 所有权限标识 + */ private static final String ALL_PERMISSION = "*:*:*"; - /** 管理员角色权限标识 */ + /** + * 管理员角色权限标识 + */ private static final String SUPER_ADMIN = "admin"; - /** 数组为0时 */ + /** + * 数组为0时 + */ private static final Integer ARRAY_EMPTY = 0; @Around("@annotation(com.ruoyi.common.security.annotation.PreAuthorize)") - public Object around(ProceedingJoinPoint point) throws Throwable - { + public Object around(ProceedingJoinPoint point) throws Throwable { Signature signature = point.getSignature(); MethodSignature methodSignature = (MethodSignature) signature; Method method = methodSignature.getMethod(); PreAuthorize annotation = method.getAnnotation(PreAuthorize.class); - if (annotation == null) - { + if (annotation == null) { return point.proceed(); } - if (!StringUtils.isEmpty(annotation.hasPermi())) - { - if (hasPermi(annotation.hasPermi())) - { + if (!StringUtils.isEmpty(annotation.hasPermi())) { + if (hasPermi(annotation.hasPermi())) { return point.proceed(); } throw new PreAuthorizeException(); - } - else if (!StringUtils.isEmpty(annotation.lacksPermi())) - { - if (lacksPermi(annotation.lacksPermi())) - { + } else if (!StringUtils.isEmpty(annotation.lacksPermi())) { + if (lacksPermi(annotation.lacksPermi())) { return point.proceed(); } throw new PreAuthorizeException(); - } - else if (ARRAY_EMPTY < annotation.hasAnyPermi().length) - { - if (hasAnyPermi(annotation.hasAnyPermi())) - { + } else if (ARRAY_EMPTY < annotation.hasAnyPermi().length) { + if (hasAnyPermi(annotation.hasAnyPermi())) { return point.proceed(); } throw new PreAuthorizeException(); - } - else if (!StringUtils.isEmpty(annotation.hasRole())) - { - if (hasRole(annotation.hasRole())) - { + } else if (!StringUtils.isEmpty(annotation.hasRole())) { + if (hasRole(annotation.hasRole())) { return point.proceed(); } throw new PreAuthorizeException(); - } - else if (!StringUtils.isEmpty(annotation.lacksRole())) - { - if (lacksRole(annotation.lacksRole())) - { + } else if (!StringUtils.isEmpty(annotation.lacksRole())) { + if (lacksRole(annotation.lacksRole())) { return point.proceed(); } throw new PreAuthorizeException(); - } - else if (ARRAY_EMPTY < annotation.hasAnyRoles().length) - { - if (hasAnyRoles(annotation.hasAnyRoles())) - { + } else if (ARRAY_EMPTY < annotation.hasAnyRoles().length) { + if (hasAnyRoles(annotation.hasAnyRoles())) { return point.proceed(); } throw new PreAuthorizeException(); @@ -104,15 +91,13 @@ public class PreAuthorizeAspect /** * 验证用户是否具备某权限 - * + * * @param permission 权限字符串 * @return 用户是否具备某权限 */ - public boolean hasPermi(String permission) - { + public boolean hasPermi(String permission) { LoginUser userInfo = tokenService.getLoginUser(); - if (StringUtils.isEmpty(userInfo) || CollectionUtils.isEmpty(userInfo.getPermissions())) - { + if (StringUtils.isEmpty(userInfo) || CollectionUtils.isEmpty(userInfo.getPermissions())) { return false; } return hasPermissions(userInfo.getPermissions(), permission); @@ -124,8 +109,7 @@ public class PreAuthorizeAspect * @param permission 权限字符串 * @return 用户是否不具备某权限 */ - public boolean lacksPermi(String permission) - { + public boolean lacksPermi(String permission) { return hasPermi(permission) != true; } @@ -135,18 +119,14 @@ public class PreAuthorizeAspect * @param permissions 权限列表 * @return 用户是否具有以下任意一个权限 */ - public boolean hasAnyPermi(String[] permissions) - { + public boolean hasAnyPermi(String[] permissions) { LoginUser userInfo = tokenService.getLoginUser(); - if (StringUtils.isEmpty(userInfo) || CollectionUtils.isEmpty(userInfo.getPermissions())) - { + if (StringUtils.isEmpty(userInfo) || CollectionUtils.isEmpty(userInfo.getPermissions())) { return false; } Collection authorities = userInfo.getPermissions(); - for (String permission : permissions) - { - if (permission != null && hasPermissions(authorities, permission)) - { + for (String permission : permissions) { + if (permission != null && hasPermissions(authorities, permission)) { return true; } } @@ -155,21 +135,17 @@ public class PreAuthorizeAspect /** * 判断用户是否拥有某个角色 - * + * * @param role 角色字符串 * @return 用户是否具备某角色 */ - public boolean hasRole(String role) - { + public boolean hasRole(String role) { LoginUser userInfo = tokenService.getLoginUser(); - if (StringUtils.isEmpty(userInfo) || CollectionUtils.isEmpty(userInfo.getRoles())) - { + if (StringUtils.isEmpty(userInfo) || CollectionUtils.isEmpty(userInfo.getRoles())) { return false; } - for (String roleKey : userInfo.getRoles()) - { - if (SUPER_ADMIN.equals(roleKey) || roleKey.equals(role)) - { + for (String roleKey : userInfo.getRoles()) { + if (SUPER_ADMIN.equals(roleKey) || roleKey.equals(role)) { return true; } } @@ -182,8 +158,7 @@ public class PreAuthorizeAspect * @param role 角色名称 * @return 用户是否不具备某角色 */ - public boolean lacksRole(String role) - { + public boolean lacksRole(String role) { return hasRole(role) != true; } @@ -193,17 +168,13 @@ public class PreAuthorizeAspect * @param roles 角色列表 * @return 用户是否具有以下任意一个角色 */ - public boolean hasAnyRoles(String[] roles) - { + public boolean hasAnyRoles(String[] roles) { LoginUser userInfo = tokenService.getLoginUser(); - if (StringUtils.isEmpty(userInfo) || CollectionUtils.isEmpty(userInfo.getRoles())) - { + if (StringUtils.isEmpty(userInfo) || CollectionUtils.isEmpty(userInfo.getRoles())) { return false; } - for (String role : roles) - { - if (hasRole(role)) - { + for (String role : roles) { + if (hasRole(role)) { return true; } } @@ -212,13 +183,12 @@ public class PreAuthorizeAspect /** * 判断是否包含权限 - * + * * @param authorities 权限列表 - * @param permission 权限字符串 + * @param permission 权限字符串 * @return 用户是否具备某权限 */ - private boolean hasPermissions(Collection authorities, String permission) - { + private boolean hasPermissions(Collection authorities, String permission) { return authorities.stream().filter(StringUtils::hasText) .anyMatch(x -> ALL_PERMISSION.contains(x) || PatternMatchUtils.simpleMatch(permission, x)); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysOperlogController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysOperlogController.java index 9bae4124..d621ff9e 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysOperlogController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysOperlogController.java @@ -3,6 +3,8 @@ package com.ruoyi.system.controller; import java.io.IOException; import java.util.List; import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; @@ -23,20 +25,18 @@ import com.ruoyi.system.service.ISysOperLogService; /** * 操作日志记录 - * + * * @author ruoyi */ @RestController @RequestMapping("/operlog") -public class SysOperlogController extends BaseController -{ +public class SysOperlogController extends BaseController { @Autowired private ISysOperLogService operLogService; @PreAuthorize(hasPermi = "system:operlog:list") @GetMapping("/list") - public TableDataInfo list(SysOperLog operLog) - { + public TableDataInfo list(SysOperLog operLog) { startPage(); List list = operLogService.selectOperLogList(operLog); return getDataTable(list); @@ -45,8 +45,7 @@ public class SysOperlogController extends BaseController @Log(title = "操作日志", businessType = BusinessType.EXPORT) @PreAuthorize(hasPermi = "system:operlog:export") @PostMapping("/export") - public void export(HttpServletResponse response, SysOperLog operLog) throws IOException - { + public void export(HttpServletResponse response, SysOperLog operLog) throws IOException { List list = operLogService.selectOperLogList(operLog); ExcelUtil util = new ExcelUtil(SysOperLog.class); util.exportExcel(response, list, "操作日志"); @@ -54,23 +53,20 @@ public class SysOperlogController extends BaseController @PreAuthorize(hasPermi = "system:operlog:remove") @DeleteMapping("/{operIds}") - public AjaxResult remove(@PathVariable Long[] operIds) - { + public AjaxResult remove(@PathVariable Long[] operIds) { return toAjax(operLogService.deleteOperLogByIds(operIds)); } @PreAuthorize(hasPermi = "system:operlog:remove") @Log(title = "操作日志", businessType = BusinessType.CLEAN) @DeleteMapping("/clean") - public AjaxResult clean() - { + public AjaxResult clean() { operLogService.cleanOperLog(); return AjaxResult.success(); } @PostMapping - public AjaxResult add(@RequestBody SysOperLog operLog) - { + public AjaxResult add(@RequestBody SysOperLog operLog) { return toAjax(operLogService.insertOperlog(operLog)); } } diff --git a/xuexi-parent/cloud-order/src/main/resources/application.yml b/xuexi-parent/cloud-order/src/main/resources/application.yml index 29f56d57..53b7dcda 100644 --- a/xuexi-parent/cloud-order/src/main/resources/application.yml +++ b/xuexi-parent/cloud-order/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 8091 + port: 8092 spring: application: name: servier-order