Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

源码阅读请教一个问题 #47

Closed
ttxs0109 opened this issue Aug 2, 2020 · 1 comment
Closed

源码阅读请教一个问题 #47

ttxs0109 opened this issue Aug 2, 2020 · 1 comment

Comments

@ttxs0109
Copy link

ttxs0109 commented Aug 2, 2020

在debug 权限管理决断器(MyAccessDecisionManager), 看到authentication.getAuthorities() 权限操作集合里有角色的信息“ROLE_ADMIN” 这是在什么时候set的?

  @Override
  public void decide(Authentication authentication, Object o, Collection<ConfigAttribute> configAttributes) throws 
   AccessDeniedException, InsufficientAuthenticationException {
    if(configAttributes==null){
        return;
    }
    Iterator<ConfigAttribute> iterator = configAttributes.iterator();
    while (iterator.hasNext()){
        ConfigAttribute c = iterator.next();
        String needPerm = c.getAttribute();
          //authentication.getAuthorities() 权限操作集合里有角色的信息“ROLE_ADMIN” ?
        for(GrantedAuthority ga : authentication.getAuthorities()) {
            // 匹配用户拥有的ga 和 系统中的needPerm
            if(needPerm.trim().equals(ga.getAuthority())) {
                return;
            }
        }
    }
    throw new AccessDeniedException("抱歉,您没有访问权限");
}
@Exrick
Copy link
Owner

Exrick commented Sep 3, 2020

读取当前用户信息时 UserDetails

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants