public ConfigAttributeDefinition getAttributes(Object filter) throws IllegalArgumentException { // TODO Auto-generated method stub FilterInvocation filterInvocation = (FilterInvocation) filter; String requestURI = filterInvocation.getRequestUrl(); Map<String, Set<String>> urlAuthorities = this.getUrlAuthorities(filterInvocation); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); boolean isSuperUser = false; if (auth != null) { for (int i = 0; i < auth.getAuthorities().length; i++) { if ("超级管理员".equals(auth.getAuthorities()[i].getAuthority())) { isSuperUser = true; break; } } if ((!isSuperUser) && (!isUrlGrantedRight(requestURI, auth))) { return null; } else { String grantedAuthorities = null; grantedAuthorities = getAuth(requestURI, auth); if (grantedAuthorities != null) { ConfigAttributeEditor configAttrEditor = new ConfigAttributeEditor(); configAttrEditor.setAsText(grantedAuthorities); return (ConfigAttributeDefinition) configAttrEditor.getValue(); } } } return null; }
/** * @param filterInvocation * @return */ @SuppressWarnings("unchecked") private Map<String, Set<String>> getUrlAuthorities(FilterInvocation filterInvocation) { ServletContext servletContext = filterInvocation.getHttpRequest().getSession().getServletContext(); this.roleUrlsMap = (Map<String, Set<String>>) servletContext.getAttribute("urlAuthorities"); return (Map<String, Set<String>>) servletContext.getAttribute("urlAuthorities"); }