Reputation: 61
I am running into some issues while attempting to use Spring Security to secure a new Spring MVC application using an existing (read: very "legacy") single sign-on solution.
DISCLAIMER: I'm relatively familiar with Spring as a whole, but not at all with Spring Security; please forgive my ignorance.
The SSO service works like so:
The SSO service doesn't handle user credentials for authorization, so that has to be handled on a per-application basis :(
As I understand it, the generally accepted practice here would be to use Spring Security's preauthentication framework, but I'm (a) not sure if I'm correct in that assumption, and (b) not sure that I need everything that comes with that solution.
Currently, I have a LoginUrlAuthenticationEntryPoint
bean defined which directs unauthenticated users to the SSO site:
<beans:bean id="customAuthenticationEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
<beans:constructor-arg value="http://sso.myco.com/login" />
</beans:bean>
The entry point is wired up like so:
<http use-expressions="true" entry-point-ref="customAuthenticationEntryPoint">
<intercept-url pattern="/" access="permitAll" />
<intercept-url pattern="/edit/**" access="isAuthenticated()" />
<intercept-url pattern="/setup/**" access="hasRole('setup')" />
<intercept-url pattern="/admin/**" access="hasRole('admin')" />
</http>
The sticking point for me is where to hook in to receive the "callback" from the SSO service. What I'd like is to have a URL (say, http://apps.myco.com/webapp123/auth?token=ABCD1234) that accepts these redirects from the SSO service, validates the token and retrieves the user name from SSO, then saves all of that information within the Spring Security context. There's a good chance I'm on the wrong road, however, or maybe I'm just missing a piece or two.
Any help or guidance is greatly appreciated.
Upvotes: 3
Views: 2989
Reputation: 4970
Ok, so here is what I would do:
I would subclass AbstractAuthenticationProcessingFilter, setting the authenticationManager to the Authentication Manager you have wired in the Spring Security xml. You really should only have to override the attemptAuthentication method. This method takes in the request and response objects allowing access to your URL parameter, etc.
If authentication is a success, you just need to return an Authentication object and Spring security should handle putting the user into the context, etc.
Here is the documentation:
Hope this helps!
Edit:
Might want to take a look how a direct subclass of this is implemented by the guys at Spring, in this case the UsernamePasswordAuthenticationFilter located here:
Upvotes: 1
Reputation: 7522
I would recommend implementing a custom Voter to assign roles (setup, admin etc.) based on token-validity and user details. Please see Voting-Based AccessDecisionManager Implementations and the blog referenced there: SPRING SECURITY CUSTOMIZATION (PART 2 – ADJUSTING SECURED SESSION IN REAL TIME)
Upvotes: 0