Example usage for org.springframework.security.oauth2.provider AuthorizationRequest AuthorizationRequest

List of usage examples for org.springframework.security.oauth2.provider AuthorizationRequest AuthorizationRequest

Introduction

In this page you can find the example usage for org.springframework.security.oauth2.provider AuthorizationRequest AuthorizationRequest.

Prototype

public AuthorizationRequest() 

Source Link

Document

Default constructor.

Usage

From source file:org.cloudfoundry.identity.uaa.mock.token.TokenMvcMockTests.java

@Test
public void testOpenIdTokenHybridFlowWithNoImplicitGrantWhenLenientWhenAppNotApproved() throws Exception {
    String clientId = "testclient" + generator.generate();
    String scopes = "space.*.developer,space.*.admin,org.*.reader,org.123*.admin,*.*,*,openid";
    setUpClients(clientId, scopes, scopes, "authorization_code", false);
    String username = "testuser" + generator.generate();
    String userScopes = "space.1.developer,space.2.developer,org.1.reader,org.2.reader,org.12345.admin,scope.one,scope.two,scope.three,openid";
    ScimUser developer = setUpUser(username, userScopes, OriginKeys.UAA, IdentityZoneHolder.get().getId());

    MockHttpSession session = getAuthenticatedSession(developer);

    String state = generator.generate();
    AuthorizationRequest authorizationRequest = new AuthorizationRequest();
    authorizationRequest.setClientId(clientId);
    authorizationRequest.setRedirectUri(TEST_REDIRECT_URI);
    authorizationRequest.setScope(new ArrayList<>(Arrays.asList("openid")));
    authorizationRequest.setResponseTypes(new TreeSet<>(Arrays.asList("code", "id_token")));
    authorizationRequest.setState(state);

    session.setAttribute("authorizationRequest", authorizationRequest);

    MvcResult result = getMockMvc()//from   w  ww  .  j  a  va  2 s. c  o m
            .perform(post("/oauth/authorize").session(session).with(cookieCsrf())
                    .param(OAuth2Utils.USER_OAUTH_APPROVAL, "true").param("scope.0", "openid"))
            .andExpect(status().is3xxRedirection()).andReturn();

    URL url = new URL(result.getResponse().getHeader("Location").replace("redirect#", "redirect?"));
    Map query = splitQuery(url);
    assertNotNull(query.get("code"));
    String code = ((List<String>) query.get("code")).get(0);
    assertNotNull(code);
}

From source file:org.cloudfoundry.identity.uaa.mock.token.TokenMvcMockTests.java

@Test
public void testOpenIdTokenHybridFlowWithNoImplicitGrantWhenStrictWhenAppNotApproved() throws Exception {
    String clientId = "testclient" + generator.generate();
    String scopes = "space.*.developer,space.*.admin,org.*.reader,org.123*.admin,*.*,*,openid";
    setUpClients(clientId, scopes, scopes, "authorization_code", false);
    String username = "testuser" + generator.generate();
    String userScopes = "space.1.developer,space.2.developer,org.1.reader,org.2.reader,org.12345.admin,scope.one,scope.two,scope.three,openid";
    ScimUser developer = setUpUser(username, userScopes, OriginKeys.UAA, IdentityZoneHolder.get().getId());

    MockHttpSession session = getAuthenticatedSession(developer);

    String state = generator.generate();

    AuthorizationRequest authorizationRequest = new AuthorizationRequest();
    authorizationRequest.setClientId(clientId);
    authorizationRequest.setRedirectUri(TEST_REDIRECT_URI);
    authorizationRequest.setScope(new ArrayList<>(Arrays.asList("openid")));
    authorizationRequest.setResponseTypes(new TreeSet<>(Arrays.asList("code", "id_token")));
    authorizationRequest.setState(state);
    session.setAttribute("authorizationRequest", authorizationRequest);

    MvcResult result = getMockMvc()//from  w ww.  j a  va2 s . co m
            .perform(post("/oauth/authorize").session(session).param(OAuth2Utils.USER_OAUTH_APPROVAL, "true")
                    .with(cookieCsrf()).param("scope.0", "openid"))
            .andExpect(status().is3xxRedirection()).andReturn();

    URL url = new URL(result.getResponse().getHeader("Location").replace("redirect#", "redirect?"));
    Map query = splitQuery(url);
    assertNotNull(query.get("id_token"));
    assertNotNull(((List) query.get("id_token")).get(0));
    assertNotNull(((List) query.get("code")).get(0));
    assertNull(query.get("token"));
}