欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
學(xué)習acegi-security - bulain - ITeye技術(shù)網(wǎng)站
學(xué)習acegi-security
這幾天對acegi研究了一下,現對這幾天的研究做個(gè)總結。

網(wǎng)上資料對于acegi在web上的應用非常多,所以特意不從web入手,而從一般的java方法入手。

acegi的基本原理就是利用攔截器,對請求進(jìn)行攔截,在攔截前和攔截后做些安全驗證,以達到安全目的。所謂安全,一般包括兩個(gè)部分,一為認證(authentication),二為授權(authorization)。

1,攔截器體系
acegi中攔截器為分為三類(lèi):
(1)filter攔截器(FilterSecurityInterceptor),主要對web應用進(jìn)行攔截,即利用servlet的filter進(jìn)行攔截。
(2)method攔截器,分為spring的method攔截器(MethodSecurityInterceptor)和aspectj的method攔截器(AspectJSecurityInterceptor)。

Java代碼  
  1. public abstract class AbstractSecurityInterceptor implements InitializingBean, ApplicationEventPublisherAware,  
  2.     MessageSourceAware {  
  3.     private AccessDecisionManager accessDecisionManager;  
  4.     private AfterInvocationManager afterInvocationManager;  
  5.     private ApplicationEventPublisher eventPublisher;  
  6.     private AuthenticationManager authenticationManager;  
  7.     protected MessageSourceAccessor messages = AcegiMessageSource.getAccessor();  
  8.     private RunAsManager runAsManager = new NullRunAsManager();  
  9.     private boolean alwaysReauthenticate = false;  
  10.     private boolean rejectPublicInvocations = false;  
  11.     private boolean validateConfigAttributes = true;  
  12.     .........  
  13.   
  14.     protected Object afterInvocation(InterceptorStatusToken token, Object returnedObject) {  
  15.        ............  
  16.     SecurityContextHolder.getContext().setAuthentication(token.getAuthentication());  
  17.     ............  
  18.        if (afterInvocationManager != null) {  
  19.             returnedObject = afterInvocationManager.decide(token.getAuthentication(), token.getSecureObject(),token.getAttr(), returnedObject);  
  20.         }  
  21.        ............  
  22.     }  
  23.   
  24.     protected InterceptorStatusToken beforeInvocation(Object object) {          
  25.       ............  
  26.          authenticated = this.authenticationManager.authenticate(SecurityContextHolder.getContext().getAuthentication());  
  27.       ............  
  28.          this.accessDecisionManager.decide(authenticated, object, attr);  
  29.          ............  
  30.          Authentication runAs = this.runAsManager.buildRunAs(authenticated, object, attr);  
  31.          if (runAs == null) {  
  32.         ............  
  33.               return new InterceptorStatusToken(authenticated, false, attr, object);   
  34.          } else {  
  35.         ............  
  36.               SecurityContextHolder.getContext().setAuthentication(runAs);  
  37.               return new InterceptorStatusToken(authenticated, true, attr, object);   
  38.          }  
  39.       ............  
  40.     }  
  41. }  
  42.   
  43. public class FilterSecurityInterceptor extends AbstractSecurityInterceptor implements Filter {  
  44.      public void invoke(FilterInvocation fi) throws IOException, ServletException {  
  45.         if ((fi.getRequest() != null) && (fi.getRequest().getAttribute(FILTER_APPLIED) != null)  
  46.             && observeOncePerRequest) {  
  47.              
  48.             fi.getChain().doFilter(fi.getRequest(), fi.getResponse());  
  49.         } else {  
  50.              
  51.             if (fi.getRequest() != null) {  
  52.                 fi.getRequest().setAttribute(FILTER_APPLIED, Boolean.TRUE);  
  53.             }  
  54.   
  55.             InterceptorStatusToken token = super.beforeInvocation(fi);  
  56.   
  57.             try {  
  58.                 fi.getChain().doFilter(fi.getRequest(), fi.getResponse());  
  59.             } finally {  
  60.                 super.afterInvocation(token, null);  
  61.             }  
  62.         }  
  63.     }  
  64.     ............  
  65. }  
  66.   
  67. public class MethodSecurityInterceptor extends AbstractSecurityInterceptor implements MethodInterceptor {      
  68.     public Object invoke(MethodInvocation mi) throws Throwable {  
  69.         Object result = null;  
  70.         InterceptorStatusToken token = super.beforeInvocation(mi);  
  71.   
  72.         try {  
  73.             result = mi.proceed();  
  74.         } finally {  
  75.             result = super.afterInvocation(token, result);  
  76.         }  
  77.   
  78.         return result;  
  79.     }  
  80.     ............  
  81. }  
  82.   
  83. public class AspectJSecurityInterceptor extends AbstractSecurityInterceptor {  
  84.      public Object invoke(JoinPoint jp, AspectJCallback advisorProceed) {  
  85.         Object result = null;  
  86.         InterceptorStatusToken token = super.beforeInvocation(jp);  
  87.   
  88.         try {  
  89.             result = advisorProceed.proceedWithObject();  
  90.         } finally {  
  91.             result = super.afterInvocation(token, result);  
  92.         }  
  93.   
  94.         return result;  
  95.     }  
  96.     ............  
  97. }  


上面的代碼片斷已經(jīng)顯示,所有的真正參與驗證的代碼都在父類(lèi)AbstractSecurityInterceptor.beforeInvocation()之中進(jìn)行,而對于攔截器都只是做些委托罷了。這樣可以把具體的驗證代碼同攔截器分開(kāi),也有利于擴展,用其他的aop技術(shù)或攔截器進(jìn)行擴展,可以很輕松。

認證體系由AuthenticationManager負責,授權體系由AccessDecisionManager負責,RunAsManager是作為用戶(hù)身份轉換的手段。AfterInvocationManager留下了一個(gè)接口,可以擴展默認的授權體系,可以做一些其他額外的工作。

在A(yíng)bstractSecurityInterceptor.beforeInvocation()中,
首先進(jìn)行認證,authenticated = this.authenticationManager.authenticate(SecurityContextHolder.getContext().getAuthentication());
其次進(jìn)行授權,this.accessDecisionManager.decide(authenticated, object, attr);

AbstractSecurityInterceptor.afterInvocation()中,
做其他擴展,returnedObject =afterInvocationManager.decide(token.getAuthentication(),token.getSecureObject(),token.getAttr(), returnedObject);

2,認證體系
2.1認證管理器
認證體系的核心為AuthenticationManager,他的方法authenticate(Authentication authentication)負責所有的認證。在acegi中,由具體類(lèi)ProviderManager來(lái)進(jìn)行認證過(guò)程。
Java代碼  
  1. public interface AuthenticationManager {  
  2.     public Authentication authenticate(Authentication authentication)  
  3.         throws AuthenticationException;  
  4. }  
  5.   
  6. public abstract class AbstractAuthenticationManager  
  7.     implements AuthenticationManager{  
  8.     public final Authentication authenticate(Authentication authRequest)  
  9.         throws AuthenticationException {  
  10.         try {  
  11.             Authentication authResult = doAuthentication(authRequest);  
  12.             copyDetails(authRequest, authResult);  
  13.   
  14.             return authResult;  
  15.         } catch (AuthenticationException e) {  
  16.             e.setAuthentication(authRequest);  
  17.             throw e;  
  18.         }  
  19.     }  
  20.   
  21.     private void copyDetails(Authentication source, Authentication dest) {  
  22.         if ((dest instanceof AbstractAuthenticationToken) && (dest.getDetails() == null)) {  
  23.             AbstractAuthenticationToken token = (AbstractAuthenticationToken) dest;  
  24.   
  25.             token.setDetails(source.getDetails());  
  26.         }  
  27.     }  
  28.   
  29.     protected abstract Authentication doAuthentication(Authentication authentication)  
  30.         throws AuthenticationException;  
  31.   
  32.     .........  
  33. }  
  34.   
  35. public class ProviderManager extends AbstractAuthenticationManager implements InitializingBean,  
  36.     ApplicationEventPublisherAware, MessageSourceAware {  
  37.     private List providers;  
  38.     ............  
  39.     public Authentication doAuthentication(Authentication authentication)  
  40.         throws AuthenticationException {  
  41.      .........  
  42.         Iterator iter = providers.iterator();  
  43.         ............  
  44.         while (iter.hasNext()) {  
  45.             .............  
  46.             AuthenticationProvider provider = (AuthenticationProvider) iter.next();  
  47.             .........  
  48.             result = provider.authenticate(authentication);  
  49.             ............  
  50.         }  
  51.         ............  
  52.     }  
  53.     .........  
  54. }  


從上面代碼片斷可以看出,真正的認證過(guò)程是在ProviderManager.doAuthentication()中進(jìn)行的。而ProviderManager并不是具體的認證者,他只是個(gè)管理器,它要將具體的認證過(guò)程委托給具體的認證器提供者AuthenticationProvider去做。

2.2認證提供者
認證提供者就有很多了,可以提供各種各樣的認證。如dao,ldap,anonymous,authbyadapter,cas,jaas,remeberme,remote,runnasimpl,testing,x509等。
Java代碼  
  1. public interface AuthenticationProvider {  
  2.     public Authentication authenticate(Authentication authentication) throws AuthenticationException;  
  3.     public boolean supports(Class authentication);  
  4. }  


具體的認證提供者類(lèi)就不詳細分析了,只提個(gè)名字:DaoAuthenticationProvider,LdapAuthenticationProvider,AnonymousAuthenticationProvider,AuthByAdapterProvider,CasAuthenticationProvider,JaasAuthenticationProvider,RememberMeAuthenticationProvider,RemoteAuthenticationProvider,RunAsImplAuthenticationProvider,TestingAuthenticationProvider,X509AuthenticationProvider。

3,授權體系
3.1授權管理器
授權體系的核心為授權管理器(AccessDecisionManager),它的方法decide(Authenticationauthentication, Object object, ConfigAttributeDefinitionconfig)進(jìn)行具體的授權動(dòng)作。
Java代碼  
  1. public interface AccessDecisionManager {  
  2.      
  3.     public void decide(Authentication authentication, Object object, ConfigAttributeDefinition config)  
  4.         throws AccessDeniedException, InsufficientAuthenticationException;  
  5.     public boolean supports(ConfigAttribute attribute);  
  6.     public boolean supports(Class clazz);  
  7. }  
  8.   
  9. public abstract class AbstractAccessDecisionManager implements AccessDecisionManager, InitializingBean,  
  10.     MessageSourceAware {  
  11.     private List decisionVoters;  
  12.     protected MessageSourceAccessor messages = AcegiMessageSource.getAccessor();  
  13.     private boolean allowIfAllAbstainDecisions = false;  
  14.   
  15.     public boolean supports(ConfigAttribute attribute) {  
  16.         Iterator iter = this.decisionVoters.iterator();  
  17.   
  18.         while (iter.hasNext()) {  
  19.             AccessDecisionVoter voter = (AccessDecisionVoter) iter.next();  
  20.   
  21.             if (voter.supports(attribute)) {  
  22.                 return true;  
  23.             }  
  24.         }  
  25.   
  26.         return false;  
  27.     }  
  28.   
  29.     public boolean supports(Class clazz) {  
  30.         Iterator iter = this.decisionVoters.iterator();  
  31.   
  32.         while (iter.hasNext()) {  
  33.             AccessDecisionVoter voter = (AccessDecisionVoter) iter.next();  
  34.   
  35.             if (!voter.supports(clazz)) {  
  36.                 return false;  
  37.             }  
  38.         }  
  39.   
  40.         return true;  
  41.     }  
  42.     ..............  
  43. }  
  44.   
  45. public class AffirmativeBased extends AbstractAccessDecisionManager {  
  46.     public void decide(Authentication authentication, Object object, ConfigAttributeDefinition config)  
  47.         throws AccessDeniedException {  
  48.         Iterator iter = this.getDecisionVoters().iterator();  
  49.         int deny = 0;  
  50.   
  51.         while (iter.hasNext()) {  
  52.             AccessDecisionVoter voter = (AccessDecisionVoter) iter.next();  
  53.             int result = voter.vote(authentication, object, config);  
  54.   
  55.             switch (result) {  
  56.             case AccessDecisionVoter.ACCESS_GRANTED:  
  57.                 return;  
  58.   
  59.             case AccessDecisionVoter.ACCESS_DENIED:  
  60.                 deny++;  
  61.   
  62.                 break;  
  63.   
  64.             default:  
  65.                 break;  
  66.             }  
  67.         }  
  68.   
  69.         if (deny > 0) {  
  70.             throw new AccessDeniedException(messages.getMessage("AbstractAccessDecisionManager.accessDenied",  
  71.                     "Access is denied"));  
  72.         }  
  73.   
  74.         // To get this far, every AccessDecisionVoter abstained  
  75.         checkAllowIfAllAbstainDecisions();  
  76.     }  
  77.     ..............  
  78. }  
  79.   
  80. public class ConsensusBased extends AbstractAccessDecisionManager {  
  81.     public void decide(Authentication authentication, Object object, ConfigAttributeDefinition config)  
  82.         throws AccessDeniedException {  
  83.         Iterator iter = this.getDecisionVoters().iterator();  
  84.         int grant = 0;  
  85.         int deny = 0;  
  86.         int abstain = 0;  
  87.   
  88.         while (iter.hasNext()) {  
  89.             AccessDecisionVoter voter = (AccessDecisionVoter) iter.next();  
  90.             int result = voter.vote(authentication, object, config);  
  91.   
  92.             switch (result) {  
  93.             case AccessDecisionVoter.ACCESS_GRANTED:  
  94.                 grant++;  
  95.   
  96.                 break;  
  97.   
  98.             case AccessDecisionVoter.ACCESS_DENIED:  
  99.                 deny++;  
  100.   
  101.                 break;  
  102.   
  103.             default:  
  104.                 abstain++;  
  105.   
  106.                 break;  
  107.             }  
  108.         }  
  109.   
  110.         if (grant > deny) {  
  111.             return;  
  112.         }  
  113.   
  114.         if (deny > grant) {  
  115.             throw new AccessDeniedException(messages.getMessage("AbstractAccessDecisionManager.accessDenied",  
  116.                     "Access is denied"));  
  117.         }  
  118.   
  119.         if ((grant == deny) && (grant != 0)) {  
  120.             if (this.allowIfEqualGrantedDeniedDecisions) {  
  121.                 return;  
  122.             } else {  
  123.                 throw new AccessDeniedException(messages.getMessage("AbstractAccessDecisionManager.accessDenied",  
  124.                         "Access is denied"));  
  125.             }  
  126.         }  
  127.   
  128.         // To get this far, every AccessDecisionVoter abstained  
  129.         checkAllowIfAllAbstainDecisions();  
  130.     }  
  131.     ..............  
  132. }  
  133.   
  134. public class UnanimousBased extends AbstractAccessDecisionManager {  
  135.     public void decide(Authentication authentication, Object object, ConfigAttributeDefinition config)  
  136.         throws AccessDeniedException {  
  137.         int grant = 0;  
  138.         int abstain = 0;  
  139.   
  140.         Iterator configIter = config.getConfigAttributes();  
  141.   
  142.         while (configIter.hasNext()) {  
  143.             ConfigAttributeDefinition thisDef = new ConfigAttributeDefinition();  
  144.             thisDef.addConfigAttribute((ConfigAttribute) configIter.next());  
  145.   
  146.             Iterator voters = this.getDecisionVoters().iterator();  
  147.   
  148.             while (voters.hasNext()) {  
  149.                 AccessDecisionVoter voter = (AccessDecisionVoter) voters.next();  
  150.                 int result = voter.vote(authentication, object, thisDef);  
  151.   
  152.                 switch (result) {  
  153.                 case AccessDecisionVoter.ACCESS_GRANTED:  
  154.                     grant++;  
  155.   
  156.                     break;  
  157.   
  158.                 case AccessDecisionVoter.ACCESS_DENIED:  
  159.                     throw new AccessDeniedException(messages.getMessage("AbstractAccessDecisionManager.accessDenied",  
  160.                             "Access is denied"));  
  161.   
  162.                 default:  
  163.                     abstain++;  
  164.   
  165.                     break;  
  166.                 }  
  167.             }  
  168.         }  
  169.   
  170.         // To get this far, there were no deny votes  
  171.         if (grant > 0) {  
  172.             return;  
  173.         }  
  174.   
  175.         // To get this far, every AccessDecisionVoter abstained  
  176.         checkAllowIfAllAbstainDecisions();  
  177.     }  
  178.     ..............  
  179. }  


授權管理器AccessDecisionManager默認有三個(gè)實(shí)現,具體為AffirmativeBased,ConsensusBased,UnanimousBased。三個(gè)具體實(shí)現都大同小異,主要在具有角色是否應該授權上。
而具體能否單個(gè)角色是否授權,是委派給AccessDecisionVoter去做的。

3.2授權投票者
授權投票責的核心是接口A(yíng)ccessDecisionVoter。他有幾個(gè)具體實(shí)現類(lèi):BasicAclEntryVoter,AuthenticatedVoter,RoleVoter。
Java代碼  
  1. public interface AccessDecisionVoter {  
  2.      
  3.     public static final int ACCESS_GRANTED = 1;  
  4.     public static final int ACCESS_ABSTAIN = 0;  
  5.     public static final int ACCESS_DENIED = -1;  
  6.   
  7.     public boolean supports(ConfigAttribute attribute);  
  8.     public boolean supports(Class clazz);  
  9.     public int vote(Authentication authentication, Object object, ConfigAttributeDefinition config);  
  10. }  
  11.   
  12. public abstract class AbstractAclVoter implements AccessDecisionVoter {  
  13.     public boolean supports(Class clazz) {  
  14.         if (MethodInvocation.class.isAssignableFrom(clazz)) {  
  15.             return true;  
  16.         } else if (JoinPoint.class.isAssignableFrom(clazz)) {  
  17.             return true;  
  18.         } else {  
  19.             return false;  
  20.         }  
  21.     }  
  22.     ............  
  23. }  
  24.   
  25. public class BasicAclEntryVoter extends AbstractAclVoter implements InitializingBean {    
  26.     private AclManager aclManager;  
  27.     private String internalMethod;  
  28.     private String processConfigAttribute;  
  29.     private int[] requirePermission;  
  30.   
  31.     public boolean supports(ConfigAttribute attribute) {  
  32.         if ((attribute.getAttribute() != null) && attribute.getAttribute().startsWith(getProcessConfigAttribute())) {  
  33.             return true;  
  34.         } else {  
  35.             return false;  
  36.         }  
  37.     }  
  38.   
  39.     public int vote(Authentication authentication, Object object, ConfigAttributeDefinition config) {  
  40.         Iterator iter = config.getConfigAttributes();  
  41.   
  42.         while (iter.hasNext()) {  
  43.             ConfigAttribute attr = (ConfigAttribute) iter.next();  
  44.   
  45.             if (this.supports(attr)) {  
  46.                 // Need to make an access decision on this invocation  
  47.                 // Attempt to locate the domain object instance to process  
  48.                 Object domainObject = getDomainObjectInstance(object);  
  49.   
  50.                 // If domain object is null, vote to abstain  
  51.                 if (domainObject == null) {  
  52.                     if (logger.isDebugEnabled()) {  
  53.                         logger.debug("Voting to abstain - domainObject is null");  
  54.                     }  
  55.   
  56.                     return AccessDecisionVoter.ACCESS_ABSTAIN;  
  57.                 }  
  58.   
  59.                 // Evaluate if we are required to use an inner domain object  
  60.                 if ((internalMethod != null) && !"".equals(internalMethod)) {  
  61.                     try {  
  62.                         Class clazz = domainObject.getClass();  
  63.                         Method method = clazz.getMethod(internalMethod, new Class[] {});  
  64.                         domainObject = method.invoke(domainObject, new Object[] {});  
  65.                     } catch (NoSuchMethodException nsme) {  
  66.                         throw new AuthorizationServiceException("Object of class '" + domainObject.getClass()  
  67.                             + "' does not provide the requested internalMethod: " + internalMethod);  
  68.                     } catch (IllegalAccessException iae) {  
  69.                         if (logger.isDebugEnabled()) {  
  70.                             logger.debug("IllegalAccessException", iae);  
  71.   
  72.                             if (iae.getCause() != null) {  
  73.                                 logger.debug("Cause: " + iae.getCause().getMessage(), iae.getCause());  
  74.                             }  
  75.                         }  
  76.   
  77.                         throw new AuthorizationServiceException("Problem invoking internalMethod: " + internalMethod  
  78.                             + " for object: " + domainObject);  
  79.                     } catch (InvocationTargetException ite) {  
  80.                         if (logger.isDebugEnabled()) {  
  81.                             logger.debug("InvocationTargetException", ite);  
  82.   
  83.                             if (ite.getCause() != null) {  
  84.                                 logger.debug("Cause: " + ite.getCause().getMessage(), ite.getCause());  
  85.                             }  
  86.                         }  
  87.   
  88.                         throw new AuthorizationServiceException("Problem invoking internalMethod: " + internalMethod  
  89.                             + " for object: " + domainObject);  
  90.                     }  
  91.                 }  
  92.   
  93.                 // Obtain the ACLs applicable to the domain object  
  94.                 AclEntry[] acls = aclManager.getAcls(domainObject, authentication);  
  95.   
  96.                 // If principal has no permissions for domain object, deny  
  97.                 if ((acls == null) || (acls.length == 0)) {  
  98.                     if (logger.isDebugEnabled()) {  
  99.                         logger.debug("Voting to deny access - no ACLs returned for this principal");  
  100.                     }  
  101.   
  102.                     return AccessDecisionVoter.ACCESS_DENIED;  
  103.                 }  
  104.   
  105.                 // Principal has some permissions for domain object, check them  
  106.                 for (int i = 0; i < acls.length; i++) {  
  107.                     // Locate processable AclEntrys  
  108.                     if (acls[i] instanceof BasicAclEntry) {  
  109.                         BasicAclEntry processableAcl = (BasicAclEntry) acls[i];  
  110.   
  111.                         // See if principal has any of the required permissions  
  112.                         for (int y = 0; y < requirePermission.length; y++) {  
  113.                             if (processableAcl.isPermitted(requirePermission[y])) {  
  114.                                 if (logger.isDebugEnabled()) {  
  115.                                     logger.debug("Voting to grant access");  
  116.                                 }  
  117.   
  118.                                 return AccessDecisionVoter.ACCESS_GRANTED;  
  119.                             }  
  120.                         }  
  121.                     }  
  122.                 }  
  123.   
  124.                 // No permissions match  
  125.                 if (logger.isDebugEnabled()) {  
  126.                     logger.debug(  
  127.                         "Voting to deny access - ACLs returned, but insufficient permissions for this principal");  
  128.                 }  
  129.   
  130.                 return AccessDecisionVoter.ACCESS_DENIED;  
  131.             }  
  132.         }  
  133.   
  134.         return AccessDecisionVoter.ACCESS_ABSTAIN;  
  135.     }  
  136.     ...............  
  137. }  
  138.   
  139.   
  140. public class AuthenticatedVoter implements AccessDecisionVoter {  
  141.   
  142.     public static final String IS_AUTHENTICATED_FULLY = "IS_AUTHENTICATED_FULLY";  
  143.     public static final String IS_AUTHENTICATED_REMEMBERED = "IS_AUTHENTICATED_REMEMBERED";  
  144.     public static final String IS_AUTHENTICATED_ANONYMOUSLY = "IS_AUTHENTICATED_ANONYMOUSLY";  
  145.   
  146.     private AuthenticationTrustResolver authenticationTrustResolver = new AuthenticationTrustResolverImpl();  
  147.   
  148.     private boolean isFullyAuthenticated(Authentication authentication) {  
  149.         return (!authenticationTrustResolver.isAnonymous(authentication)  
  150.         && !authenticationTrustResolver.isRememberMe(authentication));  
  151.     }  
  152.   
  153.     public void setAuthenticationTrustResolver(AuthenticationTrustResolver authenticationTrustResolver) {  
  154.         Assert.notNull(authenticationTrustResolver, "AuthenticationTrustResolver cannot be set to null");  
  155.         this.authenticationTrustResolver = authenticationTrustResolver;  
  156.     }  
  157.   
  158.     public boolean supports(ConfigAttribute attribute) {  
  159.         if ((attribute.getAttribute() != null)  
  160.             && (IS_AUTHENTICATED_FULLY.equals(attribute.getAttribute())  
  161.             || IS_AUTHENTICATED_REMEMBERED.equals(attribute.getAttribute())  
  162.             || IS_AUTHENTICATED_ANONYMOUSLY.equals(attribute.getAttribute()))) {  
  163.             return true;  
  164.         } else {  
  165.             return false;  
  166.         }  
  167.     }  
  168.   
  169.   
  170.     public boolean supports(Class clazz) {  
  171.         return true;  
  172.     }  
  173.   
  174.     public int vote(Authentication authentication, Object object, ConfigAttributeDefinition config) {  
  175.         int result = ACCESS_ABSTAIN;  
  176.         Iterator iter = config.getConfigAttributes();  
  177.   
  178.         while (iter.hasNext()) {  
  179.             ConfigAttribute attribute = (ConfigAttribute) iter.next();  
  180.   
  181.             if (this.supports(attribute)) {  
  182.                 result = ACCESS_DENIED;  
  183.   
  184.                 if (IS_AUTHENTICATED_FULLY.equals(attribute.getAttribute())) {  
  185.                     if (isFullyAuthenticated(authentication)) {  
  186.                         return ACCESS_GRANTED;  
  187.                     }  
  188.                 }  
  189.   
  190.                 if (IS_AUTHENTICATED_REMEMBERED.equals(attribute.getAttribute())) {  
  191.                     if (authenticationTrustResolver.isRememberMe(authentication)  
  192.                         || isFullyAuthenticated(authentication)) {  
  193.                         return ACCESS_GRANTED;  
  194.                     }  
  195.                 }  
  196.   
  197.                 if (IS_AUTHENTICATED_ANONYMOUSLY.equals(attribute.getAttribute())) {  
  198.                     if (authenticationTrustResolver.isAnonymous(authentication) || isFullyAuthenticated(authentication)  
  199.                         || authenticationTrustResolver.isRememberMe(authentication)) {  
  200.                         return ACCESS_GRANTED;  
  201.                     }  
  202.                 }  
  203.             }  
  204.         }  
  205.   
  206.         return result;  
  207.     }  
  208. }  
  209.   
  210. public class RoleVoter implements AccessDecisionVoter {  
  211.     private String rolePrefix = "ROLE_";  
  212.   
  213.     public boolean supports(ConfigAttribute attribute) {  
  214.         if ((attribute.getAttribute() != null) && attribute.getAttribute().startsWith(getRolePrefix())) {  
  215.             return true;  
  216.         } else {  
  217.             return false;  
  218.         }  
  219.     }  
  220.   
  221.   
  222.     public boolean supports(Class clazz) {  
  223.         return true;  
  224.     }  
  225.   
  226.     public int vote(Authentication authentication, Object object, ConfigAttributeDefinition config) {  
  227.         int result = ACCESS_ABSTAIN;  
  228.         Iterator iter = config.getConfigAttributes();  
  229.   
  230.         while (iter.hasNext()) {  
  231.             ConfigAttribute attribute = (ConfigAttribute) iter.next();  
  232.   
  233.             if (this.supports(attribute)) {  
  234.                 result = ACCESS_DENIED;  
  235.   
  236.                 for (int i = 0; i < authentication.getAuthorities().length; i++) {  
  237.                     if (attribute.getAttribute().equals(authentication.getAuthorities()[i].getAuthority())) {  
  238.                         return ACCESS_GRANTED;  
  239.                     }  
  240.                 }  
  241.             }  
  242.         }  
  243.         return result;  
  244.     }  
  245. }  


這三個(gè)授權投票實(shí)現類(lèi)中 acl 又最復雜。他會(huì )委托給acl管理器(AclManager)來(lái)做具體的授權工作。

3.3acl授權體系
AclManager只有一個(gè)實(shí)現類(lèi)AclProviderManager ,負責提供acl授權實(shí)體。
Java代碼  
  1. public interface AclManager {  
  2.      
  3.     public AclEntry[] getAcls(Object domainInstance);  
  4.     public AclEntry[] getAcls(Object domainInstance, Authentication authentication);  
  5. }  
  6.   
  7. public class AclProviderManager implements AclManager, InitializingBean {    
  8.     public AclEntry[] getAcls(Object domainInstance) {  
  9.         Assert.notNull(domainInstance, "domainInstance is null - violating interface contract");  
  10.   
  11.         Iterator iter = providers.iterator();  
  12.   
  13.         while (iter.hasNext()) {  
  14.             AclProvider provider = (AclProvider) iter.next();  
  15.   
  16.             if (provider.supports(domainInstance)) {  
  17.                 if (logger.isDebugEnabled()) {  
  18.                     logger.debug("ACL lookup using " + provider.getClass().getName());  
  19.                 }  
  20.   
  21.                 return provider.getAcls(domainInstance);  
  22.             }  
  23.         }  
  24.   
  25.         if (logger.isDebugEnabled()) {  
  26.             logger.debug("No AclProvider found for " + domainInstance.toString());  
  27.         }  
  28.   
  29.         return null;  
  30.     }  
  31.   
  32.     public AclEntry[] getAcls(Object domainInstance, Authentication authentication) {  
  33.         Assert.notNull(domainInstance, "domainInstance is null - violating interface contract");  
  34.         Assert.notNull(authentication, "authentication is null - violating interface contract");  
  35.   
  36.         Iterator iter = providers.iterator();  
  37.   
  38.         while (iter.hasNext()) {  
  39.             AclProvider provider = (AclProvider) iter.next();  
  40.   
  41.             if (provider.supports(domainInstance)) {  
  42.                 if (logger.isDebugEnabled()) {  
  43.                     logger.debug("ACL lookup using " + provider.getClass().getName());  
  44.                 }  
  45.   
  46.                 return provider.getAcls(domainInstance, authentication);  
  47.             } else {  
  48.                 if (logger.isDebugEnabled()) {  
  49.                     logger.debug("Provider " + provider.toString() + " does not support " + domainInstance);  
  50.                 }  
  51.             }  
  52.         }  
  53.   
  54.         if (logger.isDebugEnabled()) {  
  55.             logger.debug("No AclProvider found for " + domainInstance.toString());  
  56.         }  
  57.   
  58.         return null;  
  59.     }  
  60.     .........  

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
Spring源代碼解析(十):Spring Acegi框架授權的實(shí)現
Spring Boot 訪(fǎng)問(wèn)安全之認證和鑒權詳解
hibernate實(shí)現增刪改查的各種方法
Java 集合系列10: HashMap深入解析(2)
Hashtable的實(shí)現原理
org.springside.modules.utils.ReflectionUtils
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久