|
@@ -2,6 +2,7 @@ package com.yaoxiang.diagnosis.authority;
|
|
|
|
|
|
import com.yaoxiang.diagnosis.model.Result;
|
|
|
import com.yaoxiang.diagnosis.util.CommonUtil;
|
|
|
+import com.yaoxiang.diagnosis.util.SecurityUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.aspectj.lang.JoinPoint;
|
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
@@ -47,30 +48,22 @@ public class AuthCheckAspect {
|
|
|
String role = authCheck.role();
|
|
|
String authority = authCheck.authority();
|
|
|
boolean access = authService.check(principal, role, authority);
|
|
|
- logger.info("check auth for principal={},role={},authority={}", principal, role, authority);
|
|
|
+ logger.info("check auth for principal={},role={},authority={},access={}", principal, role, authority, access);
|
|
|
+ if (!access) {
|
|
|
+ throw new AuthCheckException("权限检测失败");
|
|
|
+ }
|
|
|
Object result = null;
|
|
|
try {
|
|
|
- if (access) {
|
|
|
- result = joinPoint.proceed();
|
|
|
- }
|
|
|
+ result = joinPoint.proceed();
|
|
|
} catch (Exception e) {
|
|
|
- logger.error("Something wrong with Server. ", e);
|
|
|
+ logger.error("Server error,message={}.", e.getMessage());
|
|
|
+ throw e;
|
|
|
}
|
|
|
- return access ? result : "Auth check fail";
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
private String getPrincipal() {
|
|
|
- String principal = "";
|
|
|
- Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
|
|
- if (authentication != null && authentication.getPrincipal() != null) {
|
|
|
- Object principalObj = authentication.getPrincipal();
|
|
|
- if (principalObj instanceof UserDetails) {
|
|
|
- principal = ((UserDetails) principalObj).getUsername();
|
|
|
- } else {
|
|
|
- principal = principalObj.toString();
|
|
|
- }
|
|
|
- }
|
|
|
- return principal;
|
|
|
+ return SecurityUtil.getCurrentUser().getUsername();
|
|
|
}
|
|
|
|
|
|
|