I have an application that is built in Java that requires authorization. However, the authentication piece is handled by a different/separate application (not in Java). The user logs in to the authentication app, and that app sets a cookie. If the user is authorized to access the Java app, they will be redirected by the authorization app to the Java app’s URL.
I want to use Spring Security to verify/check the cookie before allowing access to the Java application. What’s the best way to do this? The Java app should do below:
- check to see if cookie exists
- if cookie exists, validate cookie values with db. If not, send them to other app to login
- if cookie is valid, show application. If not, send user to “authentication” app.
Any ideas?
You can do this by making your own
UsernamePasswordAuthenticationFilter. Inside the filter you can check for the cookies you need. You should only need to override theattemptAuthentication()method. You have the request and response objects there so checking for the cookies should be easy.You will also need to implement a
UserDetailsServiceto check the user credentials with the database.UserDetailsService.Your namespace config should look something like this:
Also be careful not to use
<formLogin>if you decide to implement the filter.