Search in sources :

Example 1 with UserAuthorizationSuccessfulAuthenticationHandler

use of org.springframework.security.oauth.provider.filter.UserAuthorizationSuccessfulAuthenticationHandler 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");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) UserAuthorizationSuccessfulAuthenticationHandler(org.springframework.security.oauth.provider.filter.UserAuthorizationSuccessfulAuthenticationHandler) HttpServletResponse(javax.servlet.http.HttpServletResponse) RedirectStrategy(org.springframework.security.web.RedirectStrategy) Test(org.junit.Test)

Aggregations

HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Test (org.junit.Test)1 UserAuthorizationSuccessfulAuthenticationHandler (org.springframework.security.oauth.provider.filter.UserAuthorizationSuccessfulAuthenticationHandler)1 RedirectStrategy (org.springframework.security.web.RedirectStrategy)1