Search in sources :

Example 11 with RedirectView

use of org.springframework.web.servlet.view.RedirectView in project spring-security-oauth by spring-projects.

the class AuthorizationEndpointTests method testApproveOrDeny.

@Test
public void testApproveOrDeny() throws Exception {
    AuthorizationRequest request = getAuthorizationRequest("foo", "http://anywhere.com", null, null, Collections.singleton("code"));
    request.setApproved(true);
    Map<String, String> approvalParameters = new HashMap<String, String>();
    approvalParameters.put("user_oauth_approval", "true");
    model.put("authorizationRequest", request);
    View result = endpoint.approveOrDeny(approvalParameters, model, sessionStatus, principal);
    assertTrue("Wrong view: " + result, ((RedirectView) result).getUrl().startsWith("http://anywhere.com"));
}
Also used : AuthorizationRequest(org.springframework.security.oauth2.provider.AuthorizationRequest) HashMap(java.util.HashMap) RedirectView(org.springframework.web.servlet.view.RedirectView) RedirectView(org.springframework.web.servlet.view.RedirectView) ModelAndView(org.springframework.web.servlet.ModelAndView) View(org.springframework.web.servlet.View) Test(org.junit.Test)

Example 12 with RedirectView

use of org.springframework.web.servlet.view.RedirectView in project spring-security-oauth by spring-projects.

the class AuthorizationEndpointTests method testAuthorizationCodeWithTrickyQueryParams.

@Test
public void testAuthorizationCodeWithTrickyQueryParams() throws Exception {
    endpoint.setAuthorizationCodeServices(new StubAuthorizationCodeServices());
    model.put("authorizationRequest", getAuthorizationRequest("foo", "http://anywhere.com?foo=b =&bar=f $", null, null, Collections.singleton("code")));
    View result = endpoint.approveOrDeny(Collections.singletonMap(OAuth2Utils.USER_OAUTH_APPROVAL, "true"), model, sessionStatus, principal);
    String url = ((RedirectView) result).getUrl();
    assertEquals("http://anywhere.com?foo=b%20=&bar=f%20$&code=thecode", url);
    MultiValueMap<String, String> params = UriComponentsBuilder.fromHttpUrl(url).build().getQueryParams();
    assertEquals("[b%20=]", params.get("foo").toString());
    assertEquals("[f%20$]", params.get("bar").toString());
}
Also used : RedirectView(org.springframework.web.servlet.view.RedirectView) RedirectView(org.springframework.web.servlet.view.RedirectView) ModelAndView(org.springframework.web.servlet.ModelAndView) View(org.springframework.web.servlet.View) Test(org.junit.Test)

Example 13 with RedirectView

use of org.springframework.web.servlet.view.RedirectView in project spring-security-oauth by spring-projects.

the class AuthorizationEndpointTests method testImplicitWithAdditionalInfo.

@Test
public void testImplicitWithAdditionalInfo() throws Exception {
    endpoint.setTokenGranter(new TokenGranter() {

        public OAuth2AccessToken grant(String grantType, TokenRequest tokenRequest) {
            DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken("FOO");
            token.setAdditionalInformation(Collections.<String, Object>singletonMap("foo", "bar"));
            return token;
        }
    });
    endpoint.setUserApprovalHandler(new DefaultUserApprovalHandler() {

        public boolean isApproved(AuthorizationRequest authorizationRequest, Authentication userAuthentication) {
            return true;
        }
    });
    AuthorizationRequest authorizationRequest = getAuthorizationRequest("foo", "http://anywhere.com", "mystate", "myscope", Collections.singleton("token"));
    ModelAndView result = endpoint.authorize(model, authorizationRequest.getRequestParameters(), sessionStatus, principal);
    String url = ((RedirectView) result.getView()).getUrl();
    assertTrue("Wrong url: " + result, url.contains("foo=bar"));
}
Also used : AuthorizationRequest(org.springframework.security.oauth2.provider.AuthorizationRequest) TokenGranter(org.springframework.security.oauth2.provider.TokenGranter) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Authentication(org.springframework.security.core.Authentication) TokenRequest(org.springframework.security.oauth2.provider.TokenRequest) DefaultUserApprovalHandler(org.springframework.security.oauth2.provider.approval.DefaultUserApprovalHandler) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) Test(org.junit.Test)

Example 14 with RedirectView

use of org.springframework.web.servlet.view.RedirectView in project cas by apereo.

the class CasWebAppConfiguration method rootController.

@Bean
protected Controller rootController() {
    return new ParameterizableViewController() {

        @Override
        protected ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
            final String queryString = request.getQueryString();
            final String url = request.getContextPath() + "/login" + (queryString != null ? '?' + queryString : StringUtils.EMPTY);
            return new ModelAndView(new RedirectView(response.encodeURL(url)));
        }
    };
}
Also used : ParameterizableViewController(org.springframework.web.servlet.mvc.ParameterizableViewController) HttpServletRequest(javax.servlet.http.HttpServletRequest) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletListenerRegistrationBean(org.springframework.boot.web.servlet.ServletListenerRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 15 with RedirectView

use of org.springframework.web.servlet.view.RedirectView in project cas by apereo.

the class CasApplicationContextConfiguration method rootController.

@Bean
protected Controller rootController() {
    return new ParameterizableViewController() {

        @Override
        protected ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
            final String queryString = request.getQueryString();
            final String url = request.getContextPath() + "/login" + (queryString != null ? '?' + queryString : StringUtils.EMPTY);
            return new ModelAndView(new RedirectView(response.encodeURL(url)));
        }
    };
}
Also used : ParameterizableViewController(org.springframework.web.servlet.mvc.ParameterizableViewController) HttpServletRequest(javax.servlet.http.HttpServletRequest) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) HttpServletResponse(javax.servlet.http.HttpServletResponse) Bean(org.springframework.context.annotation.Bean)

Aggregations

RedirectView (org.springframework.web.servlet.view.RedirectView)79 ModelAndView (org.springframework.web.servlet.ModelAndView)68 Test (org.junit.Test)34 HashMap (java.util.HashMap)18 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)17 View (org.springframework.web.servlet.View)16 Authentication (org.springframework.security.core.Authentication)14 AuthorizationRequest (org.springframework.security.oauth2.provider.AuthorizationRequest)13 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)9 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)8 TokenRequest (org.springframework.security.oauth2.provider.TokenRequest)8 DefaultUserApprovalHandler (org.springframework.security.oauth2.provider.approval.DefaultUserApprovalHandler)8 ServletException (javax.servlet.ServletException)7 RequestInfoForm (org.orcid.pojo.ajaxForm.RequestInfoForm)7 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)7 TokenGranter (org.springframework.security.oauth2.provider.TokenGranter)7 Principal (org.apereo.cas.authentication.principal.Principal)6 OAuthRegisteredService (org.apereo.cas.support.oauth.services.OAuthRegisteredService)6 CasProfile (org.pac4j.cas.profile.CasProfile)6 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)6