| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package com.xintong.visualinspection.securityTools;
- import org.springframework.security.access.AccessDecisionManager;
- import org.springframework.security.access.AccessDeniedException;
- import org.springframework.security.access.ConfigAttribute;
- import org.springframework.security.authentication.InsufficientAuthenticationException;
- import org.springframework.security.core.Authentication;
- import org.springframework.security.core.GrantedAuthority;
- import org.springframework.stereotype.Service;
- import java.util.Collection;
- import java.util.Iterator;
- /**
- * 文件名:MyAccessDecisionManager
- * 版本信息:日期:2017/3/31 Copyright 江苏省交通规划设计院 Corporation 2017 版权所有.
- */
- @Service
- public class MyAccessDecisionManager implements AccessDecisionManager {
- @Override
- public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes) throws AccessDeniedException, InsufficientAuthenticationException {
- if(null== configAttributes || configAttributes.size() <=0) {
- return;
- }
- ConfigAttribute c;
- String needRole;
- for(Iterator<ConfigAttribute> iter = configAttributes.iterator(); iter.hasNext(); ) {
- c = iter.next();
- needRole = c.getAttribute();
- for(GrantedAuthority ga : authentication.getAuthorities()) {
- if(needRole.trim().equals(ga.getAuthority())) {
- return;
- }
- }
- }
- throw new AccessDeniedException("no right");
- }
- @Override
- public boolean supports(ConfigAttribute attribute) {
- return true;
- }
- @Override
- public boolean supports(Class<?> clazz) {
- return true;
- }
- }
|