List of usage examples for org.springframework.web.servlet.view RedirectView getUrl
@Nullable
public String getUrl()
From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackActionControllerTests.java
@Test public void verifyResponseIsCodeWithoutState() throws Exception { final AuthorizationCode authorizationCode = mock(AuthorizationCode.class); when(authorizationCode.getId()).thenReturn(AC_ID); final Set<String> scopes = new HashSet<>(); scopes.add(NAME1);//from ww w .j av a 2s .co m scopes.add(NAME2); final CentralOAuthService centralOAuthService = mock(CentralOAuthService.class); when(centralOAuthService.grantAuthorizationCode(TokenType.OFFLINE, CLIENT_ID, TICKET_GRANTING_TICKET_ID, REDIRECT_URI, scopes)).thenReturn(authorizationCode); final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_ACTION_URL); final MockHttpSession mockSession = new MockHttpSession(); mockSession.putValue(OAuthConstants.OAUTH20_CLIENT_ID, CLIENT_ID); mockSession.putValue(OAuthConstants.OAUTH20_REDIRECT_URI, REDIRECT_URI); mockSession.putValue(OAuthConstants.OAUTH20_TOKEN_TYPE, TokenType.OFFLINE); mockSession.putValue(OAuthConstants.OAUTH20_LOGIN_TICKET_ID, TICKET_GRANTING_TICKET_ID); mockSession.putValue(OAuthConstants.OAUTH20_SCOPE_SET, scopes); mockRequest.setSession(mockSession); mockRequest.setParameter(OAuthConstants.OAUTH20_APPROVAL_PROMPT_ACTION, OAuthConstants.OAUTH20_APPROVAL_PROMPT_ACTION_ALLOW); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.setCentralOAuthService(centralOAuthService); oauth20WrapperController.afterPropertiesSet(); final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse); assertTrue(modelAndView.getView() instanceof RedirectView); final RedirectView redirectView = (RedirectView) modelAndView.getView(); assertEquals(redirectView.getUrl(), REDIRECT_URI + "?" + OAuthConstants.CODE + "=" + AC_ID); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_RESPONSE_TYPE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_CLIENT_ID)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_STATE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_REDIRECT_URI)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_TOKEN_TYPE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_LOGIN_TICKET_ID)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_SCOPE_SET)); }
From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackActionControllerTests.java
@Test public void verifyResponseIsCodeWithState() throws Exception { final AuthorizationCode authorizationCode = mock(AuthorizationCode.class); when(authorizationCode.getId()).thenReturn(AC_ID); final Set<String> scopes = new HashSet<>(); scopes.add(NAME1);//from ww w. j a v a 2 s . c om scopes.add(NAME2); final CentralOAuthService centralOAuthService = mock(CentralOAuthService.class); when(centralOAuthService.grantAuthorizationCode(TokenType.OFFLINE, CLIENT_ID, TICKET_GRANTING_TICKET_ID, REDIRECT_URI, scopes)).thenReturn(authorizationCode); final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_ACTION_URL); final MockHttpSession mockSession = new MockHttpSession(); mockSession.putValue(OAuthConstants.OAUTH20_CLIENT_ID, CLIENT_ID); mockSession.putValue(OAuthConstants.OAUTH20_STATE, STATE); mockSession.putValue(OAuthConstants.OAUTH20_REDIRECT_URI, REDIRECT_URI); mockSession.putValue(OAuthConstants.OAUTH20_TOKEN_TYPE, TokenType.OFFLINE); mockSession.putValue(OAuthConstants.OAUTH20_LOGIN_TICKET_ID, TICKET_GRANTING_TICKET_ID); mockSession.putValue(OAuthConstants.OAUTH20_SCOPE_SET, scopes); mockRequest.setSession(mockSession); mockRequest.setParameter(OAuthConstants.OAUTH20_APPROVAL_PROMPT_ACTION, OAuthConstants.OAUTH20_APPROVAL_PROMPT_ACTION_ALLOW); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.setCentralOAuthService(centralOAuthService); oauth20WrapperController.afterPropertiesSet(); final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse); assertTrue(modelAndView.getView() instanceof RedirectView); final RedirectView redirectView = (RedirectView) modelAndView.getView(); assertEquals(redirectView.getUrl(), REDIRECT_URI + "?" + OAuthConstants.CODE + "=" + AC_ID + "&" + OAuthConstants.STATE + '=' + STATE); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_RESPONSE_TYPE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_CLIENT_ID)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_STATE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_REDIRECT_URI)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_TOKEN_TYPE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_LOGIN_TICKET_ID)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_SCOPE_SET)); }
From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackActionControllerTests.java
@Test public void verifyResponseIsTokenWithoutState() throws Exception { final AuthorizationCode authorizationCode = mock(AuthorizationCode.class); final TicketGrantingTicket ticketGrantingTicket = mock(TicketGrantingTicket.class); when(ticketGrantingTicket.getCreationTime()).thenReturn(new Date().getTime()); final AccessToken accessToken = mock(AccessToken.class); when(accessToken.getId()).thenReturn(AT_ID); when(accessToken.getTicket()).thenReturn(ticketGrantingTicket); final Set<String> scopes = new HashSet<>(); scopes.add(NAME1);// w ww.j a v a 2s . c o m scopes.add(NAME2); final CentralOAuthService centralOAuthService = mock(CentralOAuthService.class); when(centralOAuthService.grantAuthorizationCode(TokenType.ONLINE, CLIENT_ID, TICKET_GRANTING_TICKET_ID, REDIRECT_URI, scopes)).thenReturn(authorizationCode); when(centralOAuthService.grantOnlineAccessToken(authorizationCode)).thenReturn(accessToken); final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_ACTION_URL); final MockHttpSession mockSession = new MockHttpSession(); mockSession.putValue(OAuthConstants.OAUTH20_RESPONSE_TYPE, RESPONSE_TYPE); mockSession.putValue(OAuthConstants.OAUTH20_CLIENT_ID, CLIENT_ID); mockSession.putValue(OAuthConstants.OAUTH20_REDIRECT_URI, REDIRECT_URI); mockSession.putValue(OAuthConstants.OAUTH20_LOGIN_TICKET_ID, TICKET_GRANTING_TICKET_ID); mockSession.putValue(OAuthConstants.OAUTH20_SCOPE_SET, scopes); mockRequest.setSession(mockSession); mockRequest.setParameter(OAuthConstants.OAUTH20_APPROVAL_PROMPT_ACTION, OAuthConstants.OAUTH20_APPROVAL_PROMPT_ACTION_ALLOW); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.setCentralOAuthService(centralOAuthService); oauth20WrapperController.setTimeout(TIMEOUT); oauth20WrapperController.afterPropertiesSet(); final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse); assertTrue(modelAndView.getView() instanceof RedirectView); final RedirectView redirectView = (RedirectView) modelAndView.getView(); assertEquals(redirectView.getUrl(), REDIRECT_URI + "#" + OAuthConstants.ACCESS_TOKEN + "=" + accessToken.getId() + "&" + OAuthConstants.EXPIRES_IN + '=' + TIMEOUT + "&" + OAuthConstants.TOKEN_TYPE + '=' + OAuthConstants.BEARER_TOKEN); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_RESPONSE_TYPE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_CLIENT_ID)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_STATE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_REDIRECT_URI)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_TOKEN_TYPE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_LOGIN_TICKET_ID)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_SCOPE_SET)); }
From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackActionControllerTests.java
@Test public void verifyResponseIsTokenWithState() throws Exception { final AuthorizationCode authorizationCode = mock(AuthorizationCode.class); final TicketGrantingTicket ticketGrantingTicket = mock(TicketGrantingTicket.class); when(ticketGrantingTicket.getCreationTime()).thenReturn(new Date().getTime()); final AccessToken accessToken = mock(AccessToken.class); when(accessToken.getId()).thenReturn(AT_ID); when(accessToken.getTicket()).thenReturn(ticketGrantingTicket); final Set<String> scopes = new HashSet<>(); scopes.add(NAME1);/*from w w w.j a va 2 s .c om*/ scopes.add(NAME2); final CentralOAuthService centralOAuthService = mock(CentralOAuthService.class); when(centralOAuthService.grantAuthorizationCode(TokenType.ONLINE, CLIENT_ID, TICKET_GRANTING_TICKET_ID, REDIRECT_URI, scopes)).thenReturn(authorizationCode); when(centralOAuthService.grantOnlineAccessToken(authorizationCode)).thenReturn(accessToken); final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_ACTION_URL); final MockHttpSession mockSession = new MockHttpSession(); mockSession.putValue(OAuthConstants.OAUTH20_RESPONSE_TYPE, RESPONSE_TYPE); mockSession.putValue(OAuthConstants.OAUTH20_CLIENT_ID, CLIENT_ID); mockSession.putValue(OAuthConstants.OAUTH20_STATE, STATE); mockSession.putValue(OAuthConstants.OAUTH20_REDIRECT_URI, REDIRECT_URI); mockSession.putValue(OAuthConstants.OAUTH20_LOGIN_TICKET_ID, TICKET_GRANTING_TICKET_ID); mockSession.putValue(OAuthConstants.OAUTH20_SCOPE_SET, scopes); mockRequest.setSession(mockSession); mockRequest.setParameter(OAuthConstants.OAUTH20_APPROVAL_PROMPT_ACTION, OAuthConstants.OAUTH20_APPROVAL_PROMPT_ACTION_ALLOW); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.setCentralOAuthService(centralOAuthService); oauth20WrapperController.setTimeout(TIMEOUT); oauth20WrapperController.afterPropertiesSet(); final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse); assertTrue(modelAndView.getView() instanceof RedirectView); final RedirectView redirectView = (RedirectView) modelAndView.getView(); assertEquals(redirectView.getUrl(), REDIRECT_URI + "#" + OAuthConstants.ACCESS_TOKEN + "=" + accessToken.getId() + "&" + OAuthConstants.EXPIRES_IN + '=' + TIMEOUT + "&" + OAuthConstants.TOKEN_TYPE + '=' + OAuthConstants.BEARER_TOKEN + "&" + OAuthConstants.STATE + '=' + STATE); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_RESPONSE_TYPE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_CLIENT_ID)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_STATE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_REDIRECT_URI)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_TOKEN_TYPE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_LOGIN_TICKET_ID)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_SCOPE_SET)); }
From source file:nl.surfnet.coin.teams.control.InvitationControllerTest.java
@Test public void testDoAcceptAdmin() throws Exception { RedirectView view = controller.doAccept(getRequest()); invitation.setIntendedRole(Role.Admin); assertTrue("Accepted invitation", invitation.isAccepted()); assertEquals(invitation.getIntendedRole(), Role.Admin); String redirectUrl = "detailteam.shtml?team=team-1&view=app"; assertEquals(redirectUrl, view.getUrl()); }
From source file:com.healthcit.cacure.web.controller.QuestionEditControllerTest.java
@SuppressWarnings("unchecked") @Test/*from ww w . j a va2 s. c o m*/ public void testOnSubmitForCreate() { Long formId = 1l; Map lookUpData = new HashMap(); lookUpData.put(QuestionElementEditController.FORM_ID_NAME, formId); Question inputQuestion = createMockQuestion(null); MockHttpServletRequest request = new MockHttpServletRequest(); EasyMock.expect(formManager.getForm(1l)).andReturn(createMockQuestionForm(formId, 1)); EasyMock.replay(formManager); EasyMock.expect(qaManager.addNewQestion(inputQuestion, formId)).andReturn(createMockQuestion(1l)); EasyMock.replay(qaManager); RedirectView expected = new RedirectView(Constants.QUESTION_LISTING_URI + "?formId=" + formId, true); RedirectView actual = (RedirectView) questionEditController.onSubmit(inputQuestion, lookUpData, null, null, request, null); Assert.assertNotNull(actual); Assert.assertEquals(expected.getUrl(), actual.getUrl()); }
From source file:com.healthcit.cacure.web.controller.QuestionEditControllerTest.java
@Test public void testOnSubmitForUpdate() { Long formId = 1l;/*from ww w . ja va 2s . com*/ Question inputQuestion = createMockQuestion(1l); inputQuestion.setForm(createMockQuestionForm(1l, 1)); EasyMock.expect(qaManager.updateQuestion(inputQuestion)).andReturn(inputQuestion); EasyMock.replay(qaManager); RedirectView expected = new RedirectView(Constants.QUESTION_LISTING_URI + "?formId=" + formId, true); MockHttpServletRequest request = new MockHttpServletRequest(); RedirectView actual = (RedirectView) questionEditController.onSubmit(inputQuestion, null, null, null, request, null); Assert.assertNotNull(actual); Assert.assertEquals(expected.getUrl(), actual.getUrl()); }
From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackControllerTests.java
@Test public void verifySetupOK() throws Exception { final TicketGrantingTicket ticketGrantingTicket = mock(TicketGrantingTicket.class); when(ticketGrantingTicket.getId()).thenReturn(TICKET_GRANTING_TICKET_ID); final ServiceTicket serviceTicket = mock(ServiceTicket.class); when(serviceTicket.getGrantingTicket()).thenReturn(ticketGrantingTicket); final TicketRegistry ticketRegistry = mock(TicketRegistry.class); when(ticketRegistry.getTicket(SERVICE_TICKET_ID)).thenReturn(serviceTicket); final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL); mockRequest.setParameter(OAuthConstants.TICKET, SERVICE_TICKET_ID); final MockHttpSession mockSession = new MockHttpSession(); mockRequest.setSession(mockSession); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.setTicketRegistry(ticketRegistry); oauth20WrapperController.afterPropertiesSet(); final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse); assertTrue(modelAndView.getView() instanceof RedirectView); final RedirectView redirectView = (RedirectView) modelAndView.getView(); assertTrue(redirectView.getUrl().endsWith(CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL)); }
From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackControllerTests.java
@Test public void verifyBypassPromptIsTrue() throws Exception { final TicketGrantingTicket ticketGrantingTicket = mock(TicketGrantingTicket.class); when(ticketGrantingTicket.isExpired()).thenReturn(false); final TicketRegistry ticketRegistry = mock(TicketRegistry.class); when(ticketRegistry.getTicket(TICKET_GRANTING_TICKET_ID)).thenReturn(ticketGrantingTicket); final Map<String, Scope> scopeMap = new HashMap<>(); scopeMap.put("scope1", new Scope("scope1", "description2")); scopeMap.put("scope2", new Scope("scope2", "description2")); final CentralOAuthService centralOAuthService = mock(CentralOAuthService.class); when(centralOAuthService.getScopes(anySetOf(String.class))).thenReturn(scopeMap); final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL); final MockHttpSession mockSession = new MockHttpSession(); mockSession.putValue(OAuthConstants.OAUTH20_LOGIN_TICKET_ID, TICKET_GRANTING_TICKET_ID); mockSession.putValue(OAuthConstants.OAUTH20_SCOPE, SCOPE); mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME); mockSession.putValue(OAuthConstants.OAUTH20_TOKEN_TYPE, TokenType.OFFLINE); mockSession.putValue(OAuthConstants.OAUTH20_APPROVAL_PROMPT, OAuthConstants.APPROVAL_PROMPT_FORCE); mockSession.putValue(OAuthConstants.BYPASS_APPROVAL_PROMPT, true); mockRequest.setSession(mockSession); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.setTicketRegistry(ticketRegistry); oauth20WrapperController.setCentralOAuthService(centralOAuthService); oauth20WrapperController.afterPropertiesSet(); final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse); assertTrue(modelAndView.getView() instanceof RedirectView); final RedirectView redirectView = (RedirectView) modelAndView.getView(); assertTrue(redirectView.getUrl() .endsWith(CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_ACTION_URL + "?action=allow")); }
From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackControllerTests.java
@Test public void verifyNoPromptWithExistingToken() throws Exception { final Principal principal = mock(Principal.class); when(principal.getId()).thenReturn(PRINCIPAL_ID); final Authentication authentication = mock(Authentication.class); when(authentication.getPrincipal()).thenReturn(principal); final TicketGrantingTicket ticketGrantingTicket = mock(TicketGrantingTicket.class); when(ticketGrantingTicket.isExpired()).thenReturn(false); when(ticketGrantingTicket.getAuthentication()).thenReturn(authentication); final TicketRegistry ticketRegistry = mock(TicketRegistry.class); when(ticketRegistry.getTicket(TICKET_GRANTING_TICKET_ID)).thenReturn(ticketGrantingTicket); final Map<String, Scope> scopeMap = new HashMap<>(); scopeMap.put("scope1", new Scope("scope1", "description2")); scopeMap.put("scope2", new Scope("scope2", "description2")); final CentralOAuthService centralOAuthService = mock(CentralOAuthService.class); when(centralOAuthService.getScopes(anySetOf(String.class))).thenReturn(scopeMap); when(centralOAuthService.isAccessToken(TokenType.ONLINE, CLIENT_ID, PRINCIPAL_ID, scopeMap.keySet())) .thenReturn(true);/* www. j a v a2s . c om*/ when(centralOAuthService.isRefreshToken(CLIENT_ID, PRINCIPAL_ID, scopeMap.keySet())).thenReturn(false); final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL); final MockHttpSession mockSession = new MockHttpSession(); mockSession.putValue(OAuthConstants.OAUTH20_LOGIN_TICKET_ID, TICKET_GRANTING_TICKET_ID); mockSession.putValue(OAuthConstants.OAUTH20_SCOPE, SCOPE); mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME); mockSession.putValue(OAuthConstants.OAUTH20_CLIENT_ID, CLIENT_ID); mockSession.putValue(OAuthConstants.OAUTH20_TOKEN_TYPE, TokenType.ONLINE); mockRequest.setSession(mockSession); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.setTicketRegistry(ticketRegistry); oauth20WrapperController.setCentralOAuthService(centralOAuthService); oauth20WrapperController.afterPropertiesSet(); final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse); assertTrue(modelAndView.getView() instanceof RedirectView); final RedirectView redirectView = (RedirectView) modelAndView.getView(); assertTrue(redirectView.getUrl() .endsWith(CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_ACTION_URL + "?action=allow")); assertEquals(scopeMap.keySet(), mockSession.getAttribute(OAuthConstants.OAUTH20_SCOPE_SET)); }