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

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

Introduction

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

Prototype

public BaseClientDetails(String clientId, String resourceIds, String scopes, String grantTypes,
            String authorities, String redirectUris) 

Source Link

Usage

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

private void addNewClients() throws Exception {
    for (String clientId : clients.keySet()) {
        Map<String, Object> map = clients.get(clientId);
        BaseClientDetails client = new BaseClientDetails(clientId, (String) map.get("resource-ids"),
                (String) map.get("scope"), (String) map.get("authorized-grant-types"),
                (String) map.get("authorities"), (String) map.get("redirect-uri"));
        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  w  w  .  j a  v a2 s  .  c  o  m*/
        }
        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")) {
            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())) {
                    clientRegistrationService.updateClientSecret(clientId, client.getClientSecret());
                }
            } else {
                // ignore it
                logger.debug(e.getMessage());
            }
        }
    }
}

From source file:org.cloudfoundry.identity.uaa.test.TestAccountSetup.java

private void createCfClient(RestOperations client) {
    BaseClientDetails clientDetails = new BaseClientDetails("cf", "cloud_controller,openid,password",
            "openid,cloud_controller.read,cloud_controller_service_permissions.read,password.write,scim.userids",
            "implicit", "uaa.none", "https://uaa.cloudfoundry.com/redirect/cf");
    createClient(client, testAccounts.getClientDetails("oauth.clients.cf", clientDetails));
}

From source file:org.cloudfoundry.identity.uaa.test.UaaTestAccounts.java

public ClientDetails getClientDetails(String prefix, BaseClientDetails defaults) {
    String clientId = environment.getProperty(prefix + ".id", defaults.getClientId());
    String clientSecret = environment.getProperty(prefix + ".secret", defaults.getClientSecret());
    String resourceIds = environment.getProperty(prefix + ".resource-ids",
            StringUtils.collectionToCommaDelimitedString(defaults.getResourceIds()));
    String scopes = environment.getProperty(prefix + ".scope",
            StringUtils.collectionToCommaDelimitedString(defaults.getScope()));
    String grantTypes = environment.getProperty(prefix + ".authorized-grant-types",
            StringUtils.collectionToCommaDelimitedString(defaults.getAuthorizedGrantTypes()));
    String authorities = environment.getProperty(prefix + ".authorities",
            StringUtils.collectionToCommaDelimitedString(defaults.getAuthorities()));
    String redirectUris = environment.getProperty(prefix + ".redirect-uri",
            StringUtils.collectionToCommaDelimitedString(defaults.getRegisteredRedirectUri()));
    BaseClientDetails result = new BaseClientDetails(clientId, resourceIds, scopes, grantTypes, authorities,
            redirectUris);//from   www  . ja  va2  s  .  co  m
    result.setClientSecret(clientSecret);
    return result;
}