新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

在spring中利用security怎么实现自定义决策管理器-创新互联

在spring中利用security怎么实现自定义决策管理器?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名申请雅安服务器托管、营销软件、网站建设、临城网站维护、网站推广。

首先介绍下Spring的决策管理器,其接口为AccessDecisionManager,抽象类为AbstractAccessDecisionManager。而我们要自定义决策管理器的话一般是继承抽象类而不去直接实现接口。

在Spring中引入了投票器(AccessDecisionVoter)的概念,有无权限访问的最终觉得权是由投票器来决定的,最常见的投票器为RoleVoter,在RoleVoter中定义了权限的前缀,先看下Spring在RoleVoter中是怎么处理授权的。

public int vote(Authentication authentication, Object object, Collection attributes) { 
  int result = ACCESS_ABSTAIN; 
  Collection<? extends GrantedAuthority> authorities = extractAuthorities(authentication); 
  for (ConfigAttribute attribute : attributes) { 
    if (this.supports(attribute)) { 
      result = ACCESS_DENIED; 
      // Attempt to find a matching granted authority 
      for (GrantedAuthority authority : authorities) { 
        if (attribute.getAttribute().equals(authority.getAuthority())) { 
          return ACCESS_GRANTED; 
        } 
      } 
    } 
  } 
  return result; 
} 
Collection<? extends GrantedAuthority> extractAuthorities(Authentication authentication) { 
  return authentication.getAuthorities(); 
} 

网站栏目:在spring中利用security怎么实现自定义决策管理器-创新互联
URL标题:http://www.wjwzjz.com/article/csgcdh.html
在线咨询
服务热线
服务热线:028-86922220
TOP