提交 4c772d7a 编写于 作者: MaxKey单点登录官方's avatar MaxKey单点登录官方

ADMINISTRATORS Granted

上级 664372db
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
package org.maxkey.web.interceptor; package org.maxkey.web.interceptor;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import javax.servlet.RequestDispatcher; import javax.servlet.RequestDispatcher;
...@@ -30,6 +31,8 @@ import org.slf4j.LoggerFactory; ...@@ -30,6 +31,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
/** /**
...@@ -48,6 +51,12 @@ public class PermissionAdapter extends HandlerInterceptorAdapter { ...@@ -48,6 +51,12 @@ public class PermissionAdapter extends HandlerInterceptorAdapter {
private ApplicationConfig applicationConfig; private ApplicationConfig applicationConfig;
static ConcurrentHashMap<String ,String >navigationsMap=null; static ConcurrentHashMap<String ,String >navigationsMap=null;
static ArrayList<GrantedAuthority> grantedAuthoritys = new ArrayList<GrantedAuthority>();
static {
grantedAuthoritys.add(new SimpleGrantedAuthority("ADMINISTRATORS"));
}
/* /*
* 请求前处理 * 请求前处理
* (non-Javadoc) * (non-Javadoc)
...@@ -58,13 +67,27 @@ public class PermissionAdapter extends HandlerInterceptorAdapter { ...@@ -58,13 +67,27 @@ public class PermissionAdapter extends HandlerInterceptorAdapter {
_logger.trace("PermissionAdapter preHandle"); _logger.trace("PermissionAdapter preHandle");
//判断用户是否登录 //判断用户是否登录
if(WebContext.getAuthentication()==null||WebContext.getAuthentication().getAuthorities()==null){//判断用户和角色,判断用户是否登录用户 if(WebContext.getAuthentication()==null
_logger.trace("No Authentication ... forward to /login"); ||WebContext.getAuthentication().getAuthorities()==null){//判断用户和角色,判断用户是否登录用户
RequestDispatcher dispatcher = request.getRequestDispatcher("/login"); _logger.trace("No Authentication ... forward to /login");
dispatcher.forward(request, response); RequestDispatcher dispatcher = request.getRequestDispatcher("/login");
return false; dispatcher.forward(request, response);
} return false;
}
boolean isGrantedAuthority = false;
for(GrantedAuthority grantedAuthority : grantedAuthoritys) {
if(WebContext.getAuthentication().getAuthorities().contains(grantedAuthority)) {
isGrantedAuthority = true;
_logger.trace("ADMINISTRATORS Authentication .");
}
}
if(!isGrantedAuthority) {
RequestDispatcher dispatcher = request.getRequestDispatcher("/logout");
dispatcher.forward(request, response);
return false;
}
boolean hasAccess=true; boolean hasAccess=true;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册