Spring security always returns HTTP 403

前端 未结 7 2104
逝去的感伤
逝去的感伤 2020-12-28 17:07

I have configured a custom Filter that grants a spring authority for every URL other than /login :

public class TokenFilter impleme         


        
7条回答
  •  太阳男子
    2020-12-28 18:06

    As others have said 403 means that user is logged in but doesn't have the right permission to view the resource; I would check the following:

    1. Your control has the correct role permission @Secured( {"ROLE_myAuthority"} )
    2. You had actually granted the correct permission new SimpleGrantedAuthority("ROLE_myAuthority");
    3. Actual granted authority from the UsernamePasswordAuthenticationToken object
    4. Filter is been injected correctly

      Authentication auth = new UsernamePasswordAuthenticationToken(username, authentication.getCredentials(), authorities);  
      Collection auths = auth.getAuthorities();`
      
      Iterator authsIterator = auths.iterator();
      
      while (authsIterator.hasNext()) {
           SimpleGrantedAuthority sga =  (SimpleGrantedAuthority) authsIterator.next();
              sga.getAuthority();
          // ... 
      }
      

提交回复
热议问题