use of org.springframework.security.web.RedirectStrategy in project spring-security by spring-projects.
the class RetryWithHttpEntryPointTests method testGettersSetters.
@Test
public void testGettersSetters() {
RetryWithHttpEntryPoint ep = new RetryWithHttpEntryPoint();
PortMapper portMapper = mock(PortMapper.class);
PortResolver portResolver = mock(PortResolver.class);
RedirectStrategy redirector = mock(RedirectStrategy.class);
ep.setPortMapper(portMapper);
ep.setPortResolver(portResolver);
ep.setRedirectStrategy(redirector);
assertThat(ep.getPortMapper()).isSameAs(portMapper);
assertThat(ep.getPortResolver()).isSameAs(portResolver);
assertThat(ep.getRedirectStrategy()).isSameAs(redirector);
}
use of org.springframework.security.web.RedirectStrategy in project spring-security by spring-projects.
the class SavedRequestAwareAuthenticationSuccessHandlerTests method onAuthenticationSuccessHasSavedRequest.
@Test
public void onAuthenticationSuccessHasSavedRequest() throws Exception {
String redirectUrl = "http://localhost/appcontext/page";
RedirectStrategy redirectStrategy = mock(RedirectStrategy.class);
RequestCache requestCache = mock(RequestCache.class);
SavedRequest savedRequest = mock(SavedRequest.class);
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
when(savedRequest.getRedirectUrl()).thenReturn(redirectUrl);
when(requestCache.getRequest(request, response)).thenReturn(savedRequest);
SavedRequestAwareAuthenticationSuccessHandler handler = new SavedRequestAwareAuthenticationSuccessHandler();
handler.setRequestCache(requestCache);
handler.setRedirectStrategy(redirectStrategy);
handler.onAuthenticationSuccess(request, response, mock(Authentication.class));
verify(redirectStrategy).sendRedirect(request, response, redirectUrl);
}
use of org.springframework.security.web.RedirectStrategy in project spring-security by spring-projects.
the class ConcurrentSessionFilterTests method doFilterWhenNoSessionInformationThenChainIsContinued.
@Test
public void doFilterWhenNoSessionInformationThenChainIsContinued() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setSession(new MockHttpSession());
MockHttpServletResponse response = new MockHttpServletResponse();
RedirectStrategy redirect = mock(RedirectStrategy.class);
SessionRegistry registry = mock(SessionRegistry.class);
String expiredUrl = "/expired";
ConcurrentSessionFilter filter = new ConcurrentSessionFilter(registry, expiredUrl);
filter.setRedirectStrategy(redirect);
MockFilterChain chain = new MockFilterChain();
filter.doFilter(request, response, chain);
assertThat(chain.getRequest()).isNotNull();
}
use of org.springframework.security.web.RedirectStrategy in project spring-security-oauth by spring-projects.
the class UserAuthorizationSuccessfulAuthenticationHandlerTests method testAuthenticationSuccess.
/**
* test determineTargetUrl
*/
@Test
public void testAuthenticationSuccess() throws Exception {
UserAuthorizationSuccessfulAuthenticationHandler handler = new UserAuthorizationSuccessfulAuthenticationHandler();
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
RedirectStrategy redirectStrategy = mock(RedirectStrategy.class);
handler.setRedirectStrategy(redirectStrategy);
when(request.getAttribute(UserAuthorizationProcessingFilter.CALLBACK_ATTRIBUTE)).thenReturn("http://my.host.com/my/context");
when(request.getAttribute(UserAuthorizationProcessingFilter.VERIFIER_ATTRIBUTE)).thenReturn("myver");
when(request.getParameter("requestToken")).thenReturn("mytok");
handler.onAuthenticationSuccess(request, response, null);
verify(redirectStrategy).sendRedirect(request, response, "http://my.host.com/my/context?oauth_token=mytok&oauth_verifier=myver");
handler = new UserAuthorizationSuccessfulAuthenticationHandler();
handler.setRedirectStrategy(redirectStrategy);
when(request.getAttribute(UserAuthorizationProcessingFilter.CALLBACK_ATTRIBUTE)).thenReturn("http://my.hosting.com/my/context?with=some&query=parameter");
when(request.getAttribute(UserAuthorizationProcessingFilter.VERIFIER_ATTRIBUTE)).thenReturn("myvera");
when(request.getParameter("requestToken")).thenReturn("mytoka");
handler.onAuthenticationSuccess(request, response, null);
verify(redirectStrategy).sendRedirect(request, response, "http://my.hosting.com/my/context?with=some&query=parameter&oauth_token=mytoka&oauth_verifier=myvera");
}
use of org.springframework.security.web.RedirectStrategy in project spring-security-oauth by spring-projects.
the class OAuthConsumerContextFilterTests method testDoFilter.
/**
* tests the filter.
*/
@Test
public void testDoFilter() throws Exception {
final OAuthRememberMeServices rememberMeServices = new NoOpOAuthRememberMeServices();
final BaseProtectedResourceDetails resource = new BaseProtectedResourceDetails();
resource.setId("dep1");
OAuthConsumerContextFilter filter = new OAuthConsumerContextFilter() {
@Override
protected String getCallbackURL(HttpServletRequest request) {
return "urn:callback";
}
@Override
protected String getUserAuthorizationRedirectURL(ProtectedResourceDetails details, OAuthConsumerToken requestToken, String callbackURL) {
return callbackURL + "&" + requestToken.getResourceId();
}
};
filter.setRedirectStrategy(new RedirectStrategy() {
public void sendRedirect(HttpServletRequest request, HttpServletResponse response, String url) throws IOException {
response.sendRedirect(url);
}
});
filter.setTokenServices(tokenServices);
filter.setConsumerSupport(support);
filter.setRememberMeServices(rememberMeServices);
doThrow(new AccessTokenRequiredException(resource)).when(filterChain).doFilter(request, response);
when(tokenServices.getToken("dep1")).thenReturn(null);
when(request.getParameter("oauth_verifier")).thenReturn(null);
when(response.encodeRedirectURL("urn:callback")).thenReturn("urn:callback?query");
OAuthConsumerToken token = new OAuthConsumerToken();
token.setAccessToken(false);
token.setResourceId(resource.getId());
when(support.getUnauthorizedRequestToken("dep1", "urn:callback?query")).thenReturn(token);
filter.doFilter(request, response, filterChain);
verify(filterChain).doFilter(request, response);
verify(tokenServices).storeToken("dep1", token);
verify(response).sendRedirect("urn:callback?query&dep1");
verify(request, times(2)).setAttribute(anyString(), anyObject());
reset(request, response, filterChain);
doThrow(new AccessTokenRequiredException(resource)).when(filterChain).doFilter(request, response);
when(tokenServices.getToken("dep1")).thenReturn(token);
when(request.getParameter(OAuthProviderParameter.oauth_verifier.toString())).thenReturn("verifier");
OAuthConsumerToken accessToken = new OAuthConsumerToken();
when(support.getAccessToken(token, "verifier")).thenReturn(accessToken);
when(response.isCommitted()).thenReturn(false);
filter.doFilter(request, response, filterChain);
verify(filterChain, times(2)).doFilter(request, response);
verify(tokenServices).removeToken("dep1");
verify(tokenServices).storeToken("dep1", accessToken);
verify(request, times(2)).setAttribute(anyString(), anyObject());
}
Aggregations