I have a backend of stateless REST services written in Java Spring Boot.
1- One of the services is "/Login". It receives a username and a password from my own web form (not the form generated by Shibboleth). In this service call, I want to contact Shibboleth (using OAuth2 or SAML or whatever) to authenticate this user and get a token. This should be done synchronously, as the service must return "true" or "false" to the caller. No redirection is permitted: either true of false.
2- This token will be included in the response sent back to the frontend and will be stored in the frontend. It will be resend back to the backend in the following calls to the other REST services (other than /Login). Those other calls must contact Shibboleth by sending the token to it. Shibboleth must return the information about the user, or an error if the token is not correct.
How can I implement points 1- and 2- manually, i.e. without using Spring Security? Just pur Java and maybe other third party libraries.
In my opinion, you can safely use Spring Security for this purpose. All it takes is to just configure it properly.
Let's start from the end, which involves querying Shibboleth after each request to see if the passed token is valid. What you need to do is simply define a class that extends
BasicAuthenticationFilterand use it in your Spring Security configuration. A very simplified implementation might look like this:Next, you use this class in your Spring Security configuration and set session management to Stateless, so Spring Security does not store sessions, and authentication is required with every single request:
In the end, all you need to do is define an endpoint that allows logging in and obtaining a token. This will be nothing more than a simple proxy to Shibboleth, that exposes your own form:
I would definitely recommend doing this with Spring Security, because that's exactly what this tool is for. It does have a somewhat high barrier to entry, but it will definitely pay off, believe me.