Example usage for org.springframework.security.oauth2.provider.client BaseClientDetails addAdditionalInformation

List of usage examples for org.springframework.security.oauth2.provider.client BaseClientDetails addAdditionalInformation

Introduction

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

Prototype

@org.codehaus.jackson.annotate.JsonAnySetter
    @com.fasterxml.jackson.annotation.JsonAnySetter
    public void addAdditionalInformation(String key, Object value) 

Source Link

Usage

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

@Test
public void authorizeEndpointWithPromptNone_WhenNotAuthenticated() throws Exception {
    String clientId = "testclient" + generator.generate();
    BaseClientDetails clientDetails = new BaseClientDetails(clientId, null, "uaa.user,other.scope",
            "authorization_code,refresh_token", "uaa.resource", TEST_REDIRECT_URI);
    clientDetails.setAutoApproveScopes(Arrays.asList("uaa.user"));
    clientDetails.setClientSecret("secret");
    clientDetails.addAdditionalInformation(ClientConstants.AUTO_APPROVE, Arrays.asList("other.scope"));
    clientDetails.addAdditionalInformation(ClientConstants.ALLOWED_PROVIDERS, Arrays.asList("uaa"));
    clientDetailsService.addClientDetails(clientDetails);

    MockHttpSession session = new MockHttpSession();

    String state = generator.generate();

    MvcResult result = getMockMvc()/* w  w  w .j a v  a2  s .  c o  m*/
            .perform(get("/oauth/authorize").session(session).param(OAuth2Utils.RESPONSE_TYPE, "code")
                    .param(OAuth2Utils.STATE, state).param(OAuth2Utils.CLIENT_ID, clientId)
                    .param(OAuth2Utils.REDIRECT_URI, TEST_REDIRECT_URI)
                    .param(ID_TOKEN_HINT_PROMPT, ID_TOKEN_HINT_PROMPT_NONE))
            .andExpect(status().isFound()).andExpect(cookie().maxAge("Current-User", 0)).andReturn();

    String url = result.getResponse().getHeader("Location");
    assertEquals(UaaUrlUtils.addQueryParameter(TEST_REDIRECT_URI, "error", "login_required"), url);

}

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

@Test
public void testAuthorizeEndpointWithPromptNone_Authenticated() throws Exception {
    String clientId = "testclient" + generator.generate();
    BaseClientDetails clientDetails = new BaseClientDetails(clientId, null, "uaa.user,other.scope",
            "authorization_code,refresh_token", "uaa.resource", TEST_REDIRECT_URI);
    clientDetails.setAutoApproveScopes(Arrays.asList("uaa.user"));
    clientDetails.setClientSecret("secret");
    clientDetails.addAdditionalInformation(ClientConstants.AUTO_APPROVE, Arrays.asList("other.scope"));
    clientDetails.addAdditionalInformation(ClientConstants.ALLOWED_PROVIDERS, Arrays.asList("uaa"));
    clientDetailsService.addClientDetails(clientDetails);

    String username = "testuser" + generator.generate();
    String userScopes = "uaa.user,other.scope";
    ScimUser developer = setUpUser(username, userScopes, OriginKeys.UAA, IdentityZone.getUaa().getId());

    MockHttpSession session = getAuthenticatedSession(developer);

    String state = generator.generate();

    MvcResult result = getMockMvc()/* w w w .j a  v  a2s .c o  m*/
            .perform(get("/oauth/authorize").session(session).param(OAuth2Utils.RESPONSE_TYPE, "code")
                    .param(OAuth2Utils.STATE, state).param(OAuth2Utils.CLIENT_ID, clientId)
                    .param(OAuth2Utils.REDIRECT_URI, TEST_REDIRECT_URI)
                    .param(ID_TOKEN_HINT_PROMPT, ID_TOKEN_HINT_PROMPT_NONE))
            .andExpect(status().isFound()).andReturn();

    String url = result.getResponse().getHeader("Location");
    assertThat(url, containsString(TEST_REDIRECT_URI));
}

From source file:org.cloudfoundry.identity.uaa.oauth.TokenRevocationEndpoint.java

@RequestMapping("/oauth/token/revoke/client/{clientId}")
public ResponseEntity<Void> revokeTokensForClient(@PathVariable String clientId) {
    logger.debug("Revoking tokens for client: " + clientId);
    BaseClientDetails client = (BaseClientDetails) clientDetailsService.loadClientByClientId(clientId);
    client.addAdditionalInformation(ClientConstants.TOKEN_SALT, generator.generate());
    clientDetailsService.updateClientDetails(client);
    logger.debug("Tokens revoked for client: " + clientId);
    return new ResponseEntity<>(OK);
}

From source file:org.cloudfoundry.identity.uaa.provider.saml.IdentityProviderConfiguratorTests.java

@Test
public void testGetIdentityProviderDefinititonsForAllowedProviders() throws Exception {
    BaseClientDetails clientDetails = new BaseClientDetails();
    List<String> clientIdpAliases = asList("simplesamlphp-url", "okta-local-2");
    clientDetails.addAdditionalInformation(ClientConstants.ALLOWED_PROVIDERS, clientIdpAliases);

    conf.setIdentityProviders(sampleData);
    conf.afterPropertiesSet();/*  ww w .  jav  a 2s  .  c om*/
    List<SamlIdentityProviderDefinition> clientIdps = conf.getIdentityProviderDefinitions(clientIdpAliases,
            IdentityZoneHolder.get());
    assertEquals(2, clientIdps.size());
    assertTrue(clientIdpAliases.contains(clientIdps.get(0).getIdpEntityAlias()));
    assertTrue(clientIdpAliases.contains(clientIdps.get(1).getIdpEntityAlias()));
}