Class ReconnectFilter
- java.lang.Object
-
- org.springframework.web.filter.GenericFilterBean
-
- org.springframework.social.connect.web.ReconnectFilter
-
- All Implemented Interfaces:
javax.servlet.Filter,org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanNameAware,org.springframework.beans.factory.DisposableBean,org.springframework.beans.factory.InitializingBean,org.springframework.context.EnvironmentAware,org.springframework.web.context.ServletContextAware
public class ReconnectFilter extends org.springframework.web.filter.GenericFilterBeanServlet filter that intercepts Spring Social
ApiExceptions thrown in the course of a request and attempts to reconcile any connection-related problems by deleting the stale/revoked connection and walking the user through the connection process to obtain a new connection.This filter handles the exceptions via the following flow:
- If an exception is thrown, redirects to /connect/{provider ID}?reconnect=true Handles its own redirect to /connect/{provider ID}?reconnect=true and converts the request to a POST request to
ConnectControllerto kick of the authorization flow.- Since:
- 1.1.0
- Author:
- Craig Walls
-
-
Constructor Summary
Constructors Constructor Description ReconnectFilter(UsersConnectionRepository usersConnectionRepository, UserIdSource userIdSource)Creates an instance ofReconnectFilter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddoFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)protected StringgetRefreshUrl(javax.servlet.http.HttpServletRequest request, ApiException apiException)Returns the URL to redirect to if it is determined that a connection needs to be renewed.protected booleanshouldPerformRefreshPostRequest(javax.servlet.http.HttpServletRequest request)Determines whether or not the handled request should be converted to a POST request toConnectControllerfor authorization.
-
-
-
Constructor Detail
-
ReconnectFilter
public ReconnectFilter(UsersConnectionRepository usersConnectionRepository, UserIdSource userIdSource)
Creates an instance ofReconnectFilter.- Parameters:
usersConnectionRepository- aUsersConnectionRepositoryused to create aConnectionRepositoryfor the current user.userIdSource- an instance ofUserIdSourceto obtain the current user's ID used to create aConnectionFactory.
-
-
Method Detail
-
doFilter
public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws IOException, javax.servlet.ServletException- Throws:
IOExceptionjavax.servlet.ServletException
-
getRefreshUrl
protected String getRefreshUrl(javax.servlet.http.HttpServletRequest request, ApiException apiException)
Returns the URL to redirect to if it is determined that a connection needs to be renewed. By default, the filter will redirect to /connect/{provider ID} with a "reconnect" query parameter. This filter also handles GET requests to that same path before submitting a POST request toConnectControllerfor authorization. May be overridden by a subclass to handle other flows, such as redirecting to a page that informs the user that a new connection is needed.- Parameters:
request- The HTTP request that triggered the exception.apiException- TheApiException.- Returns:
- the URL to redirect to if a connection needs to be renewed.
-
shouldPerformRefreshPostRequest
protected boolean shouldPerformRefreshPostRequest(javax.servlet.http.HttpServletRequest request)
Determines whether or not the handled request should be converted to a POST request toConnectControllerfor authorization. By default, will return true if the request is a GET request for /connect/{provider ID} and there is a "reconnect" query parameter. May be overridden by a subclass to consider other criteria in deciding whether or not to convert the request.- Parameters:
request- the handled request.- Returns:
- true if the request should be converted to a POST request to
ConnectController.
-
-