Example usage for org.springframework.security.oauth2.provider ClientDetails getAuthorizedGrantTypes

List of usage examples for org.springframework.security.oauth2.provider ClientDetails getAuthorizedGrantTypes

Introduction

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

Prototype

Set<String> getAuthorizedGrantTypes();

Source Link

Document

The grant types for which this client is authorized.

Usage

From source file:org.meruvian.yama.webapi.service.RestOauthClientService.java

@Override
public Application findClientDetailsById(String id) {
    ClientDetails clientDetails = clientDetailsService.loadClientByClientId(id);

    if (clientDetails == null) {
        return null;
    }//from   ww  w .ja  va 2 s.  co  m

    Application application = applicationRepository.findById(clientDetails.getClientId());
    application.setScopes(clientDetails.getScope());
    application.setAuthorizedGrantTypes(clientDetails.getAuthorizedGrantTypes());

    return application;
}

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

private ClientDetail getMongoDBClientDetailsFromClient(ClientDetails cd) {
    ClientDetail clientDetails = new ClientDetail();
    clientDetails.setAccessTokenValiditySeconds(cd.getAccessTokenValiditySeconds());
    clientDetails.setAdditionalInformation(cd.getAdditionalInformation());
    clientDetails.setAuthorizedGrantTypes(cd.getAuthorizedGrantTypes());
    clientDetails.setClientId(cd.getClientId());
    clientDetails.setClientSecret(cd.getClientSecret());
    clientDetails.setRefreshTokenValiditySeconds(cd.getRefreshTokenValiditySeconds());
    clientDetails.setRegisteredRedirectUri(cd.getRegisteredRedirectUri());
    clientDetails.setResourceIds(cd.getResourceIds());
    clientDetails.setScope(cd.getScope());
    clientDetails.setScoped(cd.isScoped());
    clientDetails.setSecretRequired(cd.isSecretRequired());
    clientDetails.setId(cd.getClientId());
    return clientDetails;
}

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

public ClientDetail getMongoDBClientDetailsFromClient(ClientDetails cd) {
    ClientDetail clientDetails = new ClientDetail();
    clientDetails.setAccessTokenValiditySeconds(cd.getAccessTokenValiditySeconds());
    clientDetails.setAdditionalInformation(cd.getAdditionalInformation());
    clientDetails.setAuthorizedGrantTypes(cd.getAuthorizedGrantTypes());
    clientDetails.setClientId(cd.getClientId());
    clientDetails.setClientSecret(cd.getClientSecret());
    clientDetails.setRefreshTokenValiditySeconds(cd.getRefreshTokenValiditySeconds());
    clientDetails.setRegisteredRedirectUri(cd.getRegisteredRedirectUri());
    clientDetails.setResourceIds(cd.getResourceIds());
    clientDetails.setScope(cd.getScope());
    clientDetails.setScoped(cd.isScoped());
    clientDetails.setSecretRequired(cd.isSecretRequired());
    clientDetails.setId(cd.getClientId());
    return clientDetails;
}

From source file:org.cloudfoundry.identity.uaa.login.ClientInfoAuthenticationFilter.java

protected void validateClient(ClientDetails client) {
    String clientId = client.getClientId();
    for (String pattern : allowedClients) {
        if (!clientId.matches(pattern)) {
            throw new BadCredentialsException("Client not permitted: " + clientId);
        }//w  w  w .ja va  2  s  . co m
    }
    Set<String> grantTypes = client.getAuthorizedGrantTypes();
    boolean matched = false;
    for (String pattern : allowedGrantTypes) {
        for (String grantType : grantTypes) {
            if (grantType.matches(pattern)) {
                matched = true;
            }
        }
    }
    if (!matched) {
        throw new BadCredentialsException("Client not permitted (wrong grant type): " + clientId);
    }
}

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

private void updateDBObject(DBObject dbo, ClientDetails clientDetails) {
    dbo.put(resourceIdsFieldName, clientDetails.getResourceIds());
    dbo.put(scopeFieldName, clientDetails.getScope());
    dbo.put(authorizedGrantTypesFieldName, clientDetails.getAuthorizedGrantTypes());
    dbo.put(registeredRedirectUrisFieldName, clientDetails.getRegisteredRedirectUri());
    dbo.put(authoritiesFieldName, AuthorityUtils.authorityListToSet(clientDetails.getAuthorities()));
    dbo.put(accessTokenValidityFieldName, clientDetails.getAccessTokenValiditySeconds());
    dbo.put(refreshTokenValidityFieldName, clientDetails.getRefreshTokenValiditySeconds());
    dbo.put(additionalInformationFieldName, clientDetails.getAdditionalInformation());
    Set<String> autoApprove = new HashSet<String>();
    for (String scope : clientDetails.getScope()) {
        if (clientDetails.isAutoApprove(scope)) {
            autoApprove.add(scope);/* w ww . j  ava 2  s.c om*/
        }
    }
    dbo.put(autoApproveFieldName, autoApprove.size() == 1 ? autoApprove.iterator().next() : autoApprove);
}

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

@Override
public String extractKey(OAuth2Authentication authentication) {
    Map<String, Object> values = new LinkedHashMap<String, Object>();
    AuthorizationRequest authorizationRequest = authentication.getAuthorizationRequest();
    if (!authentication.isClientOnly()) {
        values.putAll(userTokenConverter.convertUserAuthentication(authentication.getUserAuthentication()));
    }//from   w w  w  .j a v  a 2s . co m
    ClientDetails client = clientDetailsService.loadClientByClientId(authorizationRequest.getClientId());
    values.put(CLIENT_ID, client.getClientId());
    if (authorizationRequest.getScope() != null) {
        values.put(SCOPE, OAuth2Utils.formatParameterList(authorizationRequest.getScope()));
    }
    Integer validity = client.getAccessTokenValiditySeconds();
    if (validity != null) {
        values.put(ACCESS_TOKEN_VALIDITY, validity);
    }
    validity = client.getRefreshTokenValiditySeconds();
    if (validity != null && client.getAuthorizedGrantTypes().contains("refresh_token")) {
        values.put(REFRESH_TOKEN_VALIDITY, validity);
    }
    MessageDigest digest;
    try {
        digest = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalStateException("MD5 algorithm not available.  Fatal (should be in the JDK).");
    }

    try {
        byte[] bytes = digest.digest(values.toString().getBytes("UTF-8"));
        return String.format("%032x", new BigInteger(1, bytes));
    } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException("UTF-8 encoding not available.  Fatal (should be in the JDK).");
    }
}

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

@Test
public void testLoadingClientIdWithNoDetails() {
    collection.insert(new BasicDBObject("clientId", "clientIdWithNoDetails"));

    ClientDetails clientDetails = fixture.loadClientByClientId("clientIdWithNoDetails");

    assertEquals("clientIdWithNoDetails", clientDetails.getClientId());
    assertFalse(clientDetails.isSecretRequired());
    assertNull(clientDetails.getClientSecret());
    assertFalse(clientDetails.isScoped());
    assertEquals(0, clientDetails.getScope().size());
    assertEquals(2, clientDetails.getAuthorizedGrantTypes().size());
    assertNull(clientDetails.getRegisteredRedirectUri());
    assertEquals(0, clientDetails.getAuthorities().size());
    assertEquals(null, clientDetails.getAccessTokenValiditySeconds());
    assertEquals(null, clientDetails.getAccessTokenValiditySeconds());
}

From source file:com.vivastream.security.oauth2.provider.DynamoDBClientDetailsService.java

public void saveOrUpdateClient(ClientDetails clientDetails) {
    Map<String, AttributeValueUpdate> updates = new HashMap<String, AttributeValueUpdate>();
    DynamoDBUtils.nullSafeUpdateS(updates, schema.getColumnResourceIds(),
            StringUtils.collectionToCommaDelimitedString(clientDetails.getResourceIds()));
    DynamoDBUtils.nullSafeUpdateS(updates, schema.getColumnScopes(),
            StringUtils.collectionToCommaDelimitedString(clientDetails.getScope()));
    DynamoDBUtils.nullSafeUpdateS(updates, schema.getColumnAuthorizedGrantTypes(),
            StringUtils.collectionToCommaDelimitedString(clientDetails.getAuthorizedGrantTypes()));
    DynamoDBUtils.nullSafeUpdateS(updates, schema.getColumnAuthorities(),
            StringUtils.collectionToCommaDelimitedString(
                    AuthorityUtils.authorityListToSet(clientDetails.getAuthorities())));
    DynamoDBUtils.nullSafeUpdateS(updates, schema.getColumnRegisteredRedirectUris(),
            StringUtils.collectionToCommaDelimitedString(clientDetails.getRegisteredRedirectUri()));

    DynamoDBUtils.nullSafeUpdateS(updates, schema.getColumnClientSecret(), clientDetails.getClientSecret());

    enrichUpdates(updates, clientDetails);

    client.updateItem(schema.getTableName(), Collections.singletonMap(schema.getColumnClientId(),
            new AttributeValue(clientDetails.getClientId())), updates);
}

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

@Test
public void testLoadingClientIdWithSingleDetails() {
    collection.insert(new BasicDBObject("clientId", "clientIdWithSingleDetails")
            .append("clientSecret", "mySecret").append("resourceIds", Arrays.asList("myResource"))
            .append("scope", Arrays.asList("myScope"))
            .append("authorizedGrantTypes", Arrays.asList("myAuthorizedGrantType"))
            .append("registeredRedirectUris", Arrays.asList("myRedirectUri"))
            .append("authorities", Arrays.asList("myAuthority")).append("accessTokenValidity", 100)
            .append("refreshTokenValidity", 200).append("autoapprove", "true"));

    ClientDetails clientDetails = fixture.loadClientByClientId("clientIdWithSingleDetails");

    assertEquals("clientIdWithSingleDetails", clientDetails.getClientId());
    assertTrue(clientDetails.isSecretRequired());
    assertEquals("mySecret", clientDetails.getClientSecret());
    assertTrue(clientDetails.isScoped());
    assertEquals(1, clientDetails.getScope().size());
    assertEquals("myScope", clientDetails.getScope().iterator().next());
    assertEquals(1, clientDetails.getResourceIds().size());
    assertEquals("myResource", clientDetails.getResourceIds().iterator().next());
    assertEquals(1, clientDetails.getAuthorizedGrantTypes().size());
    assertEquals("myAuthorizedGrantType", clientDetails.getAuthorizedGrantTypes().iterator().next());
    assertEquals("myRedirectUri", clientDetails.getRegisteredRedirectUri().iterator().next());
    assertEquals(1, clientDetails.getAuthorities().size());
    assertEquals("myAuthority", clientDetails.getAuthorities().iterator().next().getAuthority());
    assertEquals(new Integer(100), clientDetails.getAccessTokenValiditySeconds());
    assertEquals(new Integer(200), clientDetails.getRefreshTokenValiditySeconds());
}

From source file:org.springframework.security.oauth2.provider.client.JdbcClientDetailsService.java

private Object[] getFieldsForUpdate(ClientDetails clientDetails) {
    String json = null;/*from w  ww  . j ava  2 s . c  o m*/
    try {
        json = mapper.write(clientDetails.getAdditionalInformation());
    } catch (Exception e) {
        logger.warn("Could not serialize additional information: " + clientDetails, e);
    }
    return new Object[] {
            clientDetails.getResourceIds() != null
                    ? StringUtils.collectionToCommaDelimitedString(clientDetails.getResourceIds())
                    : null,
            clientDetails.getScope() != null
                    ? StringUtils.collectionToCommaDelimitedString(clientDetails.getScope())
                    : null,
            clientDetails.getAuthorizedGrantTypes() != null
                    ? StringUtils.collectionToCommaDelimitedString(clientDetails.getAuthorizedGrantTypes())
                    : null,
            clientDetails.getRegisteredRedirectUri() != null
                    ? StringUtils.collectionToCommaDelimitedString(clientDetails.getRegisteredRedirectUri())
                    : null,
            clientDetails.getAuthorities() != null
                    ? StringUtils.collectionToCommaDelimitedString(clientDetails.getAuthorities())
                    : null,
            clientDetails.getAccessTokenValiditySeconds(), clientDetails.getRefreshTokenValiditySeconds(), json,
            getAutoApproveScopes(clientDetails), clientDetails.getClientId() };
}