Package org.dspace.app.rest.security
Class SamlLoginFilter
java.lang.Object
org.springframework.web.filter.GenericFilterBean
org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
org.dspace.app.rest.security.StatelessLoginFilter
org.dspace.app.rest.security.SamlLoginFilter
- All Implemented Interfaces:
jakarta.servlet.Filter,Aware,BeanNameAware,DisposableBean,InitializingBean,ApplicationEventPublisherAware,EnvironmentAware,MessageSourceAware,EnvironmentCapable,ServletContextAware
A filter that examines requests to see if the user has been authenticated via SAML.
The overall SAML login process is as follows:
- When SAML authentication is enabled, the client/UI receives the URL to the active SAML
relying party's authentication endpoint in the WWW-Authenticate header.
See
SamlAuthentication.loginPageURL(org.dspace.core.Context, HttpServletRequest, HttpServletResponse). - The client sends the user to that URL when they select SAML authentication.
- The active SAML relying party sends the client to the login page at the asserting party (aka identity provider, or IdP).
- The user logs in to the asserting party.
- If successful, the asserting party sends the client back to the relying party's assertion consumer endpoint, along with the SAML assertion.
- The relying party receives the SAML assertion, extracts attributes from the assertion, maps them into request attributes, and forwards the request to the path where this filter is listening.
- This filter intercepts the request in order to check for a valid SAML login (see
SamlAuthentication.authenticate(org.dspace.core.Context, String, String, String, HttpServletRequest)) and stores that user info in a JWT. It also saves that JWT in a temporary authentication cookie. - This filter redirects the user back to the UI (after verifying it's at a trusted URL).
- The client reads the JWT from the cookie, and sends it back in a request to /api/authn/login, which triggers the server-side to destroy the cookie and move the JWT into a header.
- Author:
- Ray Lee
-
Field Summary
Fields inherited from class org.dspace.app.rest.security.StatelessLoginFilter
authenticationManager, restAuthenticationServiceFields inherited from class org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
authenticationDetailsSource, eventPublisher, messages -
Constructor Summary
ConstructorsConstructorDescriptionSamlLoginFilter(String url, String httpMethod, AuthenticationManager authenticationManager, RestAuthenticationService restAuthenticationService) -
Method Summary
Modifier and TypeMethodDescriptionattemptAuthentication(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Attempt to authenticate the user by using Spring Security's AuthenticationManager.protected voidsuccessfulAuthentication(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain chain, Authentication auth) If the above attemptAuthentication() call was successful (no authentication error was thrown), then this method will take the returnedDSpaceAuthenticationclass (which includes all the data from the authenticated user) and add the authentication data to the response.Methods inherited from class org.dspace.app.rest.security.StatelessLoginFilter
afterPropertiesSet, unsuccessfulAuthenticationMethods inherited from class org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
doFilter, getAllowSessionCreation, getAuthenticationManager, getFailureHandler, getRememberMeServices, getSuccessHandler, requiresAuthentication, setAllowSessionCreation, setApplicationEventPublisher, setAuthenticationDetailsSource, setAuthenticationFailureHandler, setAuthenticationManager, setAuthenticationSuccessHandler, setContinueChainBeforeSuccessfulAuthentication, setFilterProcessesUrl, setMessageSource, setRememberMeServices, setRequiresAuthenticationRequestMatcher, setSecurityContextHolderStrategy, setSecurityContextRepository, setSessionAuthenticationStrategyMethods inherited from class org.springframework.web.filter.GenericFilterBean
addRequiredProperty, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
-
Constructor Details
-
SamlLoginFilter
public SamlLoginFilter(String url, String httpMethod, AuthenticationManager authenticationManager, RestAuthenticationService restAuthenticationService)
-
-
Method Details
-
attemptAuthentication
public Authentication attemptAuthentication(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws AuthenticationException Description copied from class:StatelessLoginFilterAttempt to authenticate the user by using Spring Security's AuthenticationManager. The AuthenticationManager will delegate this task to one or more AuthenticationProvider classes.For DSpace, our custom AuthenticationProvider is
EPersonRestAuthenticationProvider, so that is the authenticate() method which is called below.- Overrides:
attemptAuthenticationin classStatelessLoginFilter- Parameters:
request- current requestresponse- current response- Returns:
- a valid Spring Security Authentication object if authentication succeeds
- Throws:
AuthenticationException- if authentication fails- See Also:
-
successfulAuthentication
protected void successfulAuthentication(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain chain, Authentication auth) throws IOException, jakarta.servlet.ServletException Description copied from class:StatelessLoginFilterIf the above attemptAuthentication() call was successful (no authentication error was thrown), then this method will take the returnedDSpaceAuthenticationclass (which includes all the data from the authenticated user) and add the authentication data to the response.For DSpace, this is calling our
JWTTokenRestAuthenticationServiceImplin order to create a JWT based on the authentication data & send that JWT back in the response.- Overrides:
successfulAuthenticationin classStatelessLoginFilter- Parameters:
request- current requestresponse- responsechain- FilterChainauth- Authentication object containing info about user who had a successful authentication- Throws:
IOExceptionjakarta.servlet.ServletException- See Also:
-