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

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

Introduction

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

Prototype

public void setClientSecret(String clientSecret) 

Source Link

Usage

From source file:st.malike.auth.server.service.security.ClientDetailService.java

private BaseClientDetails getClientFromMongoDBClientDetails(ClientDetail clientDetails) {
    BaseClientDetails bc = new BaseClientDetails();
    bc.setAccessTokenValiditySeconds(clientDetails.getAccessTokenValiditySeconds());
    bc.setAuthorizedGrantTypes(clientDetails.getAuthorizedGrantTypes());
    bc.setClientId(clientDetails.getClientId());
    bc.setClientSecret(clientDetails.getClientSecret());
    bc.setRefreshTokenValiditySeconds(clientDetails.getRefreshTokenValiditySeconds());
    bc.setRegisteredRedirectUri(clientDetails.getRegisteredRedirectUri());
    bc.setResourceIds(clientDetails.getResourceIds());
    bc.setScope(clientDetails.getScope());
    return bc;/*from  w  w  w  . j a v a2 s . c om*/
}

From source file:com.ge.predix.test.utils.UaaTestUtil.java

private void createClientWithAuthorities(final String clientId, final String clientSecret,
        final Collection<? extends GrantedAuthority> authorities) {
    BaseClientDetails client = new BaseClientDetails();
    client.setAuthorities(authorities);// w  w w  . j  a  v  a2 s .c o m
    client.setAuthorizedGrantTypes(Arrays.asList(new String[] { "client_credentials" }));
    client.setClientId(clientId);
    client.setClientSecret(clientSecret);
    client.setResourceIds(Arrays.asList(new String[] { "uaa.none" }));
    createOrUpdateClient(client);
}

From source file:com.tlantic.integration.authentication.service.security.ClientDetailService.java

private BaseClientDetails getClientFromMongoDBClientDetails(ClientDetail clientDetails) {
    BaseClientDetails bc = new BaseClientDetails();
    bc.setAccessTokenValiditySeconds(clientDetails.getAccessTokenValiditySeconds());
    bc.setAuthorizedGrantTypes(clientDetails.getAuthorizedGrantTypes());
    bc.setClientId(clientDetails.getClientId());
    bc.setClientSecret(clientDetails.getClientSecret());
    bc.setRefreshTokenValiditySeconds(clientDetails.getRefreshTokenValiditySeconds());
    bc.setRegisteredRedirectUri(clientDetails.getRegisteredRedirectUri());
    bc.setResourceIds(clientDetails.getResourceIds());
    bc.setScope(clientDetails.getScope());
    List<SimpleGrantedAuthority> authorities = new LinkedList<>();
    authorities.add(new SimpleGrantedAuthority("trust"));
    authorities.add(new SimpleGrantedAuthority("read"));
    authorities.add(new SimpleGrantedAuthority("write"));
    bc.setAuthorities(authorities);/*from   w w  w  .  ja  v a  2s  .  c  o  m*/
    return bc;
}

From source file:com.cedac.security.oauth2.provider.client.MongoClientDetailsService.java

@SuppressWarnings("unchecked")
private ClientDetails toClientDetails(DBObject dbo) {
    final String clientId = (String) dbo.get(clientIdFieldName);
    final String resourceIds = collectionToCommaDelimitedString((Collection) dbo.get(resourceIdsFieldName));
    final String scopes = collectionToCommaDelimitedString((Collection) dbo.get(scopeFieldName));
    final String grantTypes = collectionToCommaDelimitedString(
            (Collection) dbo.get(authorizedGrantTypesFieldName));
    final String authorities = collectionToCommaDelimitedString((Collection) dbo.get(authoritiesFieldName));
    final String redirectUris = collectionToCommaDelimitedString(
            (Collection) dbo.get(registeredRedirectUrisFieldName));
    BaseClientDetails clientDetails = new BaseClientDetails(clientId, resourceIds, scopes, grantTypes,
            authorities, redirectUris);/*w  w w  .  j ava 2s.  c o m*/
    clientDetails.setClientSecret((String) dbo.get(clientSecretFieldName));
    clientDetails.setAccessTokenValiditySeconds((Integer) dbo.get(accessTokenValidityFieldName));
    clientDetails.setRefreshTokenValiditySeconds((Integer) dbo.get(refreshTokenValidityFieldName));
    Object autoApprove = dbo.get(autoApproveFieldName);
    if (autoApprove != null) {
        if (autoApprove instanceof String) {
            clientDetails.setAutoApproveScopes(Collections.singleton((String) autoApprove));
        } else {
            clientDetails.setAutoApproveScopes((Collection<String>) dbo.get(autoApproveFieldName));
        }
    }
    DBObject additionalInfo = (DBObject) dbo.get(additionalInformationFieldName);
    if (additionalInfo != null) {
        for (String key : additionalInfo.keySet()) {
            clientDetails.addAdditionalInformation(key, additionalInfo.get(key));
        }
    }
    return clientDetails;
}

From source file:com.ge.predix.test.utils.UaaTestUtil.java

private void createAcsZoneClient(final String acsZone, final String clientId, final String clientSecret) {
    BaseClientDetails acsZoneAdminClient = new BaseClientDetails();
    ArrayList<SimpleGrantedAuthority> authorities = new ArrayList<SimpleGrantedAuthority>();
    authorities.add(new SimpleGrantedAuthority("acs.attributes.read"));
    authorities.add(new SimpleGrantedAuthority("acs.attributes.write"));
    authorities.add(new SimpleGrantedAuthority("acs.policies.read"));
    authorities.add(new SimpleGrantedAuthority("acs.policies.write"));
    authorities.add(new SimpleGrantedAuthority("predix-acs.zones." + acsZone + ".admin"));
    authorities.add(new SimpleGrantedAuthority("predix-acs.zones." + acsZone + ".user"));
    acsZoneAdminClient.setAuthorities(authorities);
    acsZoneAdminClient.setAuthorizedGrantTypes(Arrays.asList(new String[] { "client_credentials" }));
    acsZoneAdminClient.setClientId(clientId);
    acsZoneAdminClient.setClientSecret(clientSecret);
    acsZoneAdminClient.setResourceIds(Arrays.asList(new String[] { "uaa.none" }));
    createOrUpdateClient(acsZoneAdminClient);
}

From source file:com.ge.predix.test.utils.UaaTestUtil.java

private void createAcsAdminClient(final List<String> acsZones, final String clientId,
        final String clientSecret) {
    BaseClientDetails acsAdminClient = new BaseClientDetails();
    ArrayList<SimpleGrantedAuthority> authorities = new ArrayList<SimpleGrantedAuthority>();
    authorities.add(new SimpleGrantedAuthority("acs.zones.admin"));
    authorities.add(new SimpleGrantedAuthority("acs.attributes.read"));
    authorities.add(new SimpleGrantedAuthority("acs.attributes.write"));
    authorities.add(new SimpleGrantedAuthority("acs.policies.read"));
    authorities.add(new SimpleGrantedAuthority("acs.policies.write"));
    for (int i = 0; i < acsZones.size(); i++) {
        authorities.add(new SimpleGrantedAuthority("predix-acs.zones." + acsZones.get(i) + ".admin"));
        authorities.add(new SimpleGrantedAuthority("predix-acs.zones." + acsZones.get(i) + ".user"));
    }//from w w w .j a v a2  s. c o m

    acsAdminClient.setAuthorities(authorities);
    acsAdminClient.setAuthorizedGrantTypes(Arrays.asList(new String[] { "client_credentials" }));
    acsAdminClient.setClientId(clientId);
    acsAdminClient.setClientSecret(clientSecret);
    acsAdminClient.setResourceIds(Arrays.asList(new String[] { "uaa.none" }));
    createOrUpdateClient(acsAdminClient);
}

From source file:org.cloudfoundry.identity.uaa.scim.endpoints.ScimUserEndpointsMockMvcTests.java

@Test
public void verification_link_in_non_default_zone() throws Exception {
    String subdomain = generator.generate().toLowerCase();
    MockMvcUtils.IdentityZoneCreationResult zoneResult = utils()
            .createOtherIdentityZoneAndReturnResult(subdomain, getMockMvc(), getWebApplicationContext(), null);
    String zonedClientId = "zonedClientId";
    String zonedClientSecret = "zonedClientSecret";
    BaseClientDetails zonedClientDetails = (BaseClientDetails) utils().createClient(this.getMockMvc(),
            zoneResult.getZoneAdminToken(), zonedClientId, zonedClientSecret, Collections.singleton("oauth"),
            null, Arrays.asList(new String[] { "client_credentials" }), "scim.create", null,
            zoneResult.getIdentityZone());
    zonedClientDetails.setClientSecret(zonedClientSecret);
    String zonedScimCreateToken = utils().getClientCredentialsOAuthAccessToken(getMockMvc(),
            zonedClientDetails.getClientId(), zonedClientDetails.getClientSecret(), "scim.create", subdomain);

    ScimUser joel = setUpScimUser(zoneResult.getIdentityZone());

    MockHttpServletRequestBuilder get = MockMvcRequestBuilders.get("/Users/" + joel.getId() + "/verify-link")
            .header("Host", subdomain + ".localhost").header("Authorization", "Bearer " + zonedScimCreateToken)
            .param("redirect_uri", HTTP_REDIRECT_EXAMPLE_COM).accept(APPLICATION_JSON);

    MvcResult result = getMockMvc().perform(get).andExpect(status().isOk()).andReturn();
    VerificationResponse verificationResponse = JsonUtils.readValue(result.getResponse().getContentAsString(),
            VerificationResponse.class);
    assertThat(verificationResponse.getVerifyLink().toString(),
            startsWith("http://" + subdomain + ".localhost/verify_user"));

    String query = verificationResponse.getVerifyLink().getQuery();

    String code = getQueryStringParam(query, "code");
    assertThat(code, is(notNullValue()));

    ExpiringCode expiringCode = codeStore.retrieveCode(code);
    assertThat(expiringCode.getExpiresAt().getTime(), is(greaterThan(System.currentTimeMillis())));
    assertThat(expiringCode.getIntent(), is(REGISTRATION.name()));
    Map<String, String> data = JsonUtils.readValue(expiringCode.getData(),
            new TypeReference<Map<String, String>>() {
            });// w w w .ja  va 2  s  .  c  o  m
    assertThat(data.get(InvitationConstants.USER_ID), is(notNullValue()));
    assertThat(data.get(CLIENT_ID), is(zonedClientDetails.getClientId()));
    assertThat(data.get(REDIRECT_URI), is(HTTP_REDIRECT_EXAMPLE_COM));
}

From source file:org.cloudfoundry.identity.uaa.client.ClientAdminBootstrap.java

private void addNewClients() throws Exception {
    for (Map.Entry<String, Map<String, Object>> entry : clients.entrySet()) {
        String clientId = entry.getKey();
        Map<String, Object> map = entry.getValue();
        BaseClientDetails client = new BaseClientDetails(clientId, (String) map.get("resource-ids"),
                (String) map.get("scope"), (String) map.get("authorized-grant-types"),
                (String) map.get("authorities"), getRedirectUris(map));
        client.setClientSecret((String) map.get("secret"));
        Integer validity = (Integer) map.get("access-token-validity");
        Boolean override = (Boolean) map.get("override");
        if (override == null) {
            override = defaultOverride;// w ww.j  a v  a2s  . c  om
        }
        Map<String, Object> info = new HashMap<String, Object>(map);
        if (validity != null) {
            client.setAccessTokenValiditySeconds(validity);
        }
        validity = (Integer) map.get("refresh-token-validity");
        if (validity != null) {
            client.setRefreshTokenValiditySeconds(validity);
        }
        // UAA does not use the resource ids in client registrations
        client.setResourceIds(Collections.singleton("none"));
        if (client.getScope().isEmpty()) {
            client.setScope(Collections.singleton("uaa.none"));
        }
        if (client.getAuthorities().isEmpty()) {
            client.setAuthorities(Collections.singleton(UaaAuthority.UAA_NONE));
        }
        if (client.getAuthorizedGrantTypes().contains("authorization_code")) {
            client.getAuthorizedGrantTypes().add("refresh_token");
        }
        for (String key : Arrays.asList("resource-ids", "scope", "authorized-grant-types", "authorities",
                "redirect-uri", "secret", "id", "override", "access-token-validity", "refresh-token-validity",
                "show-on-homepage", "app-launch-url", "app-icon")) {
            info.remove(key);
        }

        client.setAdditionalInformation(info);
        try {
            clientRegistrationService.addClientDetails(client);
        } catch (ClientAlreadyExistsException e) {
            if (override == null || override) {
                logger.debug("Overriding client details for " + clientId);
                clientRegistrationService.updateClientDetails(client);
                if (StringUtils.hasText(client.getClientSecret())
                        && didPasswordChange(clientId, client.getClientSecret())) {
                    clientRegistrationService.updateClientSecret(clientId, client.getClientSecret());
                }
            } else {
                // ignore it
                logger.debug(e.getMessage());
            }
        }
        ClientMetadata clientMetadata = buildClientMetadata(map, clientId);
        clientMetadataProvisioning.update(clientMetadata);
    }
}

From source file:org.cloudfoundry.identity.uaa.integration.feature.SamlLoginIT.java

protected BaseClientDetails createClientAndSpecifyProvider(String clientId, IdentityProvider provider,
        String redirectUri) throws Exception {

    RestTemplate identityClient = IntegrationTestUtils.getClientCredentialsTempate(IntegrationTestUtils
            .getClientCredentialsResource(baseUrl, new String[0], "identity", "identitysecret"));
    RestTemplate adminClient = IntegrationTestUtils.getClientCredentialsTempate(
            IntegrationTestUtils.getClientCredentialsResource(baseUrl, new String[0], "admin", "adminsecret"));
    String email = new RandomValueStringGenerator().generate() + "@samltesting.org";
    ScimUser user = IntegrationTestUtils.createUser(adminClient, baseUrl, email, "firstname", "lastname", email,
            true);/* w  ww. j  a  v  a2 s  .c  o m*/
    IntegrationTestUtils.makeZoneAdmin(identityClient, baseUrl, user.getId(), Origin.UAA);

    String zoneAdminToken = IntegrationTestUtils.getAuthorizationCodeToken(serverRunning,
            UaaTestAccounts.standard(serverRunning), "identity", "identitysecret", email, "secr3T");

    BaseClientDetails clientDetails = new BaseClientDetails(clientId, null, "openid", "authorization_code",
            "uaa.resource", redirectUri);
    clientDetails.setClientSecret("secret");
    List<String> idps = Arrays.asList(provider.getOriginKey());
    clientDetails.addAdditionalInformation(ClientConstants.ALLOWED_PROVIDERS, idps);
    clientDetails.addAdditionalInformation(ClientConstants.AUTO_APPROVE, true);
    IntegrationTestUtils.createClient(zoneAdminToken, baseUrl, clientDetails);

    return clientDetails;
}