Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Security : difference between ROLE_ANONYMOUS and IS_AUTHENTICATED_ANONYMOUSLY

In Spring Security What's difference between ROLE_ANONYMOUS and IS_AUTHENTICATED_ANONYMOUSLY .

In other words , how are RoleVoter and AuthenticatedVoter different ?

like image 380
Vinoth Kumar C M Avatar asked Mar 30 '11 06:03

Vinoth Kumar C M


People also ask

What is the difference between Role_user and Role_anonymous in a spring intercept URL configuration?

ROLE_ANONYMOUS has no user credentials, ROLE_USER has user credentials... has been authenticated.

Is anonymous () Spring Security?

Spring Security's anonymous authentication just gives you a more convenient way to configure your access-control attributes. Calls to servlet API calls such as getCallerPrincipal , for example, will still return null even though there is actually an anonymous authentication object in the SecurityContextHolder .

What is AnonymousAuthenticationToken?

AnonymousAuthenticationToken is an implementation of Authentication , and stores the GrantedAuthority s which apply to the anonymous principal. There is a corresponding AnonymousAuthenticationProvider , which is chained into the ProviderManager so that AnonymousAuthenticationToken s are accepted.


1 Answers

From the relevant section in spring security documentation,

You will often see the ROLE_ANONYMOUS attribute in the above interceptor configuration replaced with IS_AUTHENTICATED_ANONYMOUSLY, which is effectively the same thing when defining access controls. This is an example of the use of the AuthenticatedVoter which we will see in the authorization chapter. It uses an AuthenticationTrustResolver to process this particular configuration attribute and grant access to anonymous users. The AuthenticatedVoter approach is more powerful, since it allows you to differentiate between anonymous, remember-me and fully-authenticated users. If you don't need this functionality though, then you can stick with ROLE_ANONYMOUS, which will be processed by Spring Security's standard RoleVoter.

Also, from Luke's comment on the related jira issue,

The anonymous access issue is partly historical. Anonymous tokens were introduced initially (i.e. ROLE_ANONYMOUS) which would allow you to use a "secure-by-defaul" configurations with specific exceptions. At a later stage the AuthenticatedVoter was introduced to allow you to differentiate between different levels of authentication - anonyous, remember-me and fully-authenticated (i.e. logged in during the current session). I've added an extra bit to the anonymous chapter to explain that they are the same unless you require the extra functionality offered by the AuthenticatedVoter.

like image 74
Raghuram Avatar answered Sep 20 '22 16:09

Raghuram