Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Security's "isAuthenticated()" expression really necessary when used with "hasRole()"?

I need a clarification about Spring Security isAuthenticated() built-in expression.

See here for documentation.

I would like to know whether or not it is really necessary or plain redundant to use isAuthenticated() when the hasRole() expression is also used.

like image 461
balteo Avatar asked Apr 01 '14 12:04

balteo


1 Answers

Normally, yes it would be unnecessary. The isAuthenticated() expression's purpose is to allow you to allow access for authenticated users regardless of what roles they have.

Unless you use hasRole() in a contrived way (e.g. by selecting the role assigned to anonymous users), then there's no reason why you would also need to add isAuthenticated(), since only authenticated users will have the roles you assign to them in your application.

like image 110
Shaun the Sheep Avatar answered Oct 12 '22 23:10

Shaun the Sheep