Package com.loc.security

Source Code of com.loc.security.MyAccssDecisionManager

package com.loc.security;

import java.util.Collection;
import java.util.Iterator;


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;

public class MyAccssDecisionManager implements AccessDecisionManager{

  public void decide(Authentication authentication, Object arg1,
      Collection<ConfigAttribute> attributes) throws AccessDeniedException,
      InsufficientAuthenticationException {
    if(attributes==null){
      return;
    }
    Iterator<ConfigAttribute> iterator = attributes.iterator();
    while(iterator.hasNext()){
      ConfigAttribute configAttribute = iterator.next();
      String needPermission = configAttribute.getAttribute();
      System.out.println("needPermission is "+needPermission);
      for(GrantedAuthority ga:authentication.getAuthorities()){
        if(needPermission.equals(ga.getAuthority())){
          return;
        }
      }
    }
    throw new AccessDeniedException("没有权限!");
  }

  public boolean supports(Class<?> arg0) {
    return true;
  }

  public boolean supports(ConfigAttribute arg0) {
    return true;
  }

}
TOP

Related Classes of com.loc.security.MyAccssDecisionManager

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.