use of com.jeeagile.core.exception.AgileDemoException in project jeeagile by jeeagile.
the class AgileSecurityInterceptor method checkUserSecurity.
/**
* 权限校验
*
* @param handlerMethod
*/
private void checkUserSecurity(HandlerMethod handlerMethod) {
try {
// 获取当前用户安全认证
IAgileSecurity agileSecurity = AgileSecurityUtil.getAgileSecurity();
if (agileSecurity == null) {
throw new AgileAuthException("请设置用户安全接口类《UserSecurity》");
}
// 当前线程存放用户信息
AgileSecurityContext.putCurrentUser(agileSecurity.getUserData());
// 演示模式拦截
AgileDemo agileDemo = handlerMethod.getMethodAnnotation(AgileDemo.class);
if (agileDemo != null && AgileUtil.isDemoEnabled()) {
throw new AgileDemoException();
}
// 如果为超管用户则不在进行权限校验
if (agileSecurity.getUserData().isSuperAdmin()) {
return;
}
AgileRequiresGuest agileRequiresGuest = handlerMethod.getBeanType().getAnnotation(AgileRequiresGuest.class);
if (agileRequiresGuest != null) {
return;
}
agileRequiresGuest = handlerMethod.getMethodAnnotation(AgileRequiresGuest.class);
if (agileRequiresGuest != null) {
return;
}
AgileRequiresAuthentication agileRequiresAuthentication = handlerMethod.getMethodAnnotation(AgileRequiresAuthentication.class);
if (agileRequiresAuthentication != null && !agileSecurity.checkAuthenticated()) {
throw new AgileAuthException("用户未验证通过!");
}
AgileRequiresUser agileRequiresUser = handlerMethod.getMethodAnnotation(AgileRequiresUser.class);
if (agileRequiresUser != null) {
agileSecurity.checkUser();
}
AgileRequiresRoles agileRequiresRoles = handlerMethod.getMethodAnnotation(AgileRequiresRoles.class);
if (agileRequiresRoles != null) {
agileSecurity.checkRole(agileRequiresRoles);
}
AgilePermissionsPrefix agilePermissionsPrefix = handlerMethod.getBeanType().getAnnotation(AgilePermissionsPrefix.class);
AgileRequiresPermissions agileRequiresPermissions = handlerMethod.getMethodAnnotation(AgileRequiresPermissions.class);
if (agileRequiresPermissions != null) {
if (agilePermissionsPrefix != null) {
agileSecurity.checkPermission(agilePermissionsPrefix, agileRequiresPermissions);
} else {
agileSecurity.checkPermission(agileRequiresPermissions);
}
}
} catch (AgileBaseException ex) {
throw ex;
} catch (Exception ex) {
logger.error("用户权限验证异常", ex);
throw new AgileAuthException("用户权限验证异常!");
}
}
Aggregations