Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Purpose of PreAuthenticatedAuthenticationToken in Spring Security?

I am authenticating a User using UsernamePasswordAuthenticationToken in SpringBoot.

I am generating a token using JJWT for that User and returning it back.

Now the User uses that token to send any further requests to me. After decrypting the token should I be using PreAuthenticatedAuthenticationToken and set it to SecurityContextHolder.getContext().setAuthentication()?

What is the purpose of PreAuthenticatedAuthenticationToken?

like image 943
amitection Avatar asked Oct 06 '16 04:10

amitection


People also ask

What is the need for @EnableWebSecurity?

The @EnableWebSecurity is a marker annotation. It allows Spring to find (it's a @Configuration and, therefore, @Component ) and automatically apply the class to the global WebSecurity . If I don't annotate any of my class with @EnableWebSecurity still the application prompting for username and password.

What is the purpose of the Spring Security Login Logout module?

Spring Security provides login and logout features that we can use in our application. It is helpful to create secure Spring application.

What is the use of WebSecurityConfigurerAdapter in spring boot?

In Spring Boot 2, if we want our own security configuration, we can simply add a custom WebSecurityConfigurerAdapter. This will disable the default auto-configuration and enable our custom security configuration. Spring Boot 2 also uses most of Spring Security's defaults.

What is the use of spring boot starter security dependency?

If a Spring Boot Security dependency is added on the classpath, Spring Boot application automatically requires the Basic Authentication for all HTTP Endpoints. The Endpoint “/” and “/home” does not require any authentication. All other Endpoints require authentication.


1 Answers

The Purpose of the PreAuthenticatedAuthenticationToken is to integrate Third Party Identity Management Systems into your Spring Application with Spring Security.

A PreAuthenticatedAuthenticationToken can come in the form of a HTTP Header, HTTP Parameter etc. In this case there need not be an Entire User Registration in your Application. Just storing this token and relevant data would be suffice.

You can read more on this from Spring Security Documentation

For JWT Case though after decryption you can even use UsernamePasswordAuthenticationToken as decryption process will reveal the Username, Password, Authorities.

like image 176
shazin Avatar answered Sep 20 '22 12:09

shazin