Example usage for org.springframework.security.oauth2.client.token.grant.client ClientCredentialsResourceDetails ClientCredentialsResourceDetails

List of usage examples for org.springframework.security.oauth2.client.token.grant.client ClientCredentialsResourceDetails ClientCredentialsResourceDetails

Introduction

In this page you can find the example usage for org.springframework.security.oauth2.client.token.grant.client ClientCredentialsResourceDetails ClientCredentialsResourceDetails.

Prototype

public ClientCredentialsResourceDetails() 

Source Link

Usage

From source file:org.cloudfoundry.identity.client.UaaContextFactory.java

/**
 * Performs a {@link org.cloudfoundry.identity.client.token.GrantType#CLIENT_CREDENTIALS authentication}
 * @param request - a configured TokenRequest
 * @return an authenticated {@link UaaContext}
 *//* w  w  w . j av a  2s  . com*/

protected UaaContext authenticateClientCredentials(TokenRequest request) {
    ClientCredentialsResourceDetails details = new ClientCredentialsResourceDetails();
    configureResourceDetails(request, details);
    setClientCredentials(request, details);
    setRequestScopes(request, details);
    OAuth2RestTemplate template = new OAuth2RestTemplate(details, new DefaultOAuth2ClientContext());
    skipSslValidation(request, template, null);
    OAuth2AccessToken token = template.getAccessToken();
    CompositeAccessToken result = new CompositeAccessToken(token);
    return new UaaContextImpl(request, template, result);
}

From source file:od.providers.modeloutput.lap.LAPModelOutputProvider.java

private PageImpl<ModelOutput> fetch(ProviderData providerData, String tenantId,
        Map<String, String> urlVariables, Pageable pageable, String uri) {

    log.debug("{}", urlVariables);
    log.debug("{}", uri);

    String url = getUrl(providerData.findValueForKey("base_url"), uri, pageable);

    ClientCredentialsResourceDetails resourceDetails = new ClientCredentialsResourceDetails();
    resourceDetails.setClientId(providerData.findValueForKey("key"));
    resourceDetails.setClientSecret(providerData.findValueForKey("secret"));
    resourceDetails//from ww  w  .  jav a 2  s.  c  o m
            .setAccessTokenUri(getUrl(providerData.findValueForKey("base_url"), LAP_OAUTH_TOKEN_URI, null));
    DefaultOAuth2ClientContext clientContext = new DefaultOAuth2ClientContext();

    OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resourceDetails, clientContext);
    MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    converter.setSupportedMediaTypes(
            Arrays.asList(MediaType.APPLICATION_JSON, MediaType.valueOf("text/javascript")));
    restTemplate.setMessageConverters(Arrays.<HttpMessageConverter<?>>asList(converter));
    ParameterizedTypeReference<PageWrapper<ModelOutputImpl>> responseType = new ParameterizedTypeReference<PageWrapper<ModelOutputImpl>>() {
    };

    PageWrapper<ModelOutputImpl> pageWrapper = restTemplate
            .exchange(url, HttpMethod.GET, null, responseType, urlVariables).getBody();
    log.debug(pageWrapper.toString());
    List<ModelOutput> output;
    if (pageWrapper != null && pageWrapper.getContent() != null && !pageWrapper.getContent().isEmpty()) {
        output = new LinkedList<ModelOutput>(pageWrapper.getContent());
    } else {
        output = new ArrayList<>();
    }

    return new PageImpl<ModelOutput>(output, pageable, pageWrapper.getPage().getTotalElements());
}

From source file:org.apereo.lap.services.output.handlers.SSPEarlyAlertOutputHandler.java

@Override
public OutputResult writeOutput(Output output) {
    logger.debug(output.toString());/* w  w  w  .j  a  v a  2 s .  c om*/

    SSPConfigPersistentStorage sspConfigPersistentStorage = storageFactory.getSSPConfigPersistentStorage();
    SSPConfig sspConfig = sspConfigPersistentStorage.get();

    if (sspConfig == null) {
        throw new RuntimeException("No SSP Configuration");
    }

    ClientCredentialsResourceDetails resourceDetails = new ClientCredentialsResourceDetails();
    resourceDetails.setClientId(sspConfig.getKey());
    resourceDetails.setClientSecret(sspConfig.getSecret());

    String baseUrl = sspConfig.getUrl();
    if (!baseUrl.endsWith("/")) {
        baseUrl = baseUrl.concat("/");
    }

    resourceDetails.setAccessTokenUri(baseUrl + "ssp/api/1/oauth2/token");
    DefaultOAuth2ClientContext clientContext = new DefaultOAuth2ClientContext();

    OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resourceDetails, clientContext);
    MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    converter.setSupportedMediaTypes(
            Arrays.asList(MediaType.APPLICATION_JSON, MediaType.valueOf("text/javascript")));
    restTemplate.setMessageConverters(Arrays.<HttpMessageConverter<?>>asList(converter));

    OutputResult result = new OutputResult(output);

    String selectSQL = output.makeTempDBSelectSQL();

    SqlRowSet rowSet;
    try {
        rowSet = storage.getTempJdbcTemplate().queryForRowSet(selectSQL);

    } catch (Exception e) {
        throw new RuntimeException("Failure while trying to retrieve the output data set: " + selectSQL);
    }

    Map<String, Integer> riskMap = new HashMap<String, Integer>();
    riskMap.put("NO RISK", 0);
    riskMap.put("LOW RISK", 1);
    riskMap.put("MEDIUM RISK", 2);
    riskMap.put("HIGH RISK", 3);

    Integer riskThreshold = riskMap.get(sspConfig.getRiskRule());

    List<EarlyAlert> earlyAlertList = new ArrayList<SSPEarlyAlertOutputHandler.EarlyAlert>();
    while (rowSet.next()) {
        if (!rowSet.wasNull()) {

            String student = rowSet.getString(1);
            String course = rowSet.getString(2);
            String risk = rowSet.getString(3);

            Integer riskScore = riskMap.get(risk);

            if (riskScore >= riskThreshold) {
                EarlyAlert earlyAlert = new EarlyAlert(course, student,
                        "Automated early alert due to risk score above acceptable limit", risk, null);
                earlyAlertList.add(earlyAlert);
            }

            logger.debug(String.format("student: %s, course: %s, risk:%s", student, course, risk));
        }
    }

    if (earlyAlertList.size() > 0) {
        EarlyAlertMessage message = new EarlyAlertMessage("test.com", "test", earlyAlertList);
        restTemplate.postForLocation(baseUrl + "ssp/api/1/bulkEarlyAlerts", message);
    }

    return result;
}

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

public ClientCredentialsResourceDetails getClientCredentialsResource(String clientId, String clientSecret) {
    ClientCredentialsResourceDetails resource = new ClientCredentialsResourceDetails();
    resource.setClientId(clientId);/*from  w  ww.  j  av a 2s  . co  m*/
    resource.setClientSecret(clientSecret);
    resource.setId(clientId);
    resource.setScope(Arrays.asList("read", "write", "password"));
    resource.setClientAuthenticationScheme(AuthenticationScheme.header);
    resource.setAccessTokenUri(server.getAccessTokenUri());
    return resource;
}

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

public ClientCredentialsResourceDetails getClientCredentialsResource(String[] scope, String clientId,
        String clientSecret) {// w w w  .ja v  a2 s  .c  om
    ClientCredentialsResourceDetails resource = new ClientCredentialsResourceDetails();
    resource.setClientId(clientId);
    resource.setClientSecret(clientSecret);
    resource.setId(clientId);
    if (scope != null) {
        resource.setScope(Arrays.asList(scope));
    }
    resource.setClientAuthenticationScheme(AuthenticationScheme.header);
    resource.setAccessTokenUri(server.getAccessTokenUri());
    return resource;
}