Spring Security + restrict user based on username

Does Spring security having any implementation to restrict user based on their username?

I know this we can do it through filters using some if checks, though I am curious to know, does Spring Security having any such kinda of implementations?

Upvotes: 0

Views: 1259

Answers (1)

holmis83
holmis83

Reputation: 16614

Sure.

For example, an annotation that only allows the method to be run by user "admin":

@PreAuthorize("authentication.name == 'admin'")
public void doAdminStuff();

You can reference a Spring bean with @:

@PreAuthorize("@myService.hasPermission(authentication.name)")
public void doSomeStuff();

Upvotes: 1

Related Questions