Search in sources :

Example 1 with OAuthClientDetails

use of com.oauth.server.dto.OAuthClientDetails in project alexa-oauth-sample by alexa-samples.

the class SampleDataLoader method loadSampleData.

public void loadSampleData() {
    OAuthClientDetails testAlexaClient = OAuthClientDetails.builder().clientId("test_alexa_client").clientSecret(passwordEncoder.encode("test_client_secret")).scopes("profile").webServerRedirectUri("https://pitangui.amazon.com/api/skill/link/M3KVOEXUO4ALBL").accessTokenValidity(3600).refreshTokenValidity(0).authorizedGrantTypes("implicit,authorization_code,refresh_token").build();
    OAuthClientDetails adminClient = OAuthClientDetails.builder().clientId("test_admin_client").clientSecret(passwordEncoder.encode("test_client_secret")).scopes("test_scope").webServerRedirectUri("http://localhost:5000/redirect").accessTokenValidity(3600).refreshTokenValidity(0).authorities(RoleEnum.ROLE_CLIENT_ADMIN.name()).authorizedGrantTypes("client_credentials,implicit,authorization_code,password,refresh_token").build();
    OAuthPartner testAlexaPartner = OAuthPartner.builder().partnerId("test_alexa_client").clientId("amzn1.application-oa2-client.0897266ee6fb480ead86d615e2653558").clientSecret("8241c286e8eb9c9741ce5b9e009c892f0bd4d603b21e51dc37efb5981245191a").scopes("alexa::health:profile:write").accessTokenUri("https://api.amazon.com/auth/o2/token").userAuthorizationUri("https://www.amazon.com/ap/oa").preEstablishedRedirectUri("").build();
    dynamoDBMapper.batchSave(ImmutableList.of(testAlexaClient, adminClient, testAlexaPartner));
}
Also used : OAuthPartner(com.oauth.server.dto.OAuthPartner) OAuthClientDetails(com.oauth.server.dto.OAuthClientDetails)

Example 2 with OAuthClientDetails

use of com.oauth.server.dto.OAuthClientDetails in project alexa-oauth-sample by alexa-samples.

the class DynamoDBClientDetailsDAO method addOrUpdateClientDetails.

/**
 * Add or update a client details in database.
 *
 * @param clientDetails client details.
 */
public void addOrUpdateClientDetails(@NonNull ClientDetails clientDetails) {
    List<String> autoApproveList = clientDetails.getScope().stream().filter(scope -> clientDetails.isAutoApprove(scope)).collect(Collectors.toList());
    OAuthClientDetails oAuthClientDetails = OAuthClientDetails.builder().clientId(clientDetails.getClientId()).authorities(StringUtils.collectionToCommaDelimitedString(clientDetails.getAuthorities())).authorizedGrantTypes(StringUtils.collectionToCommaDelimitedString(clientDetails.getAuthorizedGrantTypes())).scopes(StringUtils.collectionToCommaDelimitedString(clientDetails.getScope())).webServerRedirectUri(StringUtils.collectionToCommaDelimitedString(clientDetails.getRegisteredRedirectUri())).accessTokenValidity(clientDetails.getAccessTokenValiditySeconds()).refreshTokenValidity(clientDetails.getRefreshTokenValiditySeconds()).autoapprove(StringUtils.collectionToCommaDelimitedString(autoApproveList)).build();
    DynamoDBMapperConfig dynamoDBMapperConfig = DynamoDBMapperConfig.builder().withSaveBehavior(SaveBehavior.UPDATE_SKIP_NULL_ATTRIBUTES).build();
    dynamoDBMapper.save(oAuthClientDetails, dynamoDBMapperConfig);
}
Also used : ClientRegistrationException(org.springframework.security.oauth2.provider.ClientRegistrationException) NonNull(lombok.NonNull) ClientAlreadyExistsException(org.springframework.security.oauth2.provider.ClientAlreadyExistsException) OAuthClientDetails(com.oauth.server.dto.OAuthClientDetails) DynamoDBScanExpression(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression) RequiredArgsConstructor(lombok.RequiredArgsConstructor) SaveBehavior(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperConfig.SaveBehavior) NoSuchClientException(org.springframework.security.oauth2.provider.NoSuchClientException) Collectors(java.util.stream.Collectors) ClientDetailsService(org.springframework.security.oauth2.provider.ClientDetailsService) List(java.util.List) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) DynamoDBMapper(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper) Log4j2(lombok.extern.log4j.Log4j2) Optional(java.util.Optional) DynamoDBMapperConfig(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperConfig) ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) ClientRegistrationService(org.springframework.security.oauth2.provider.ClientRegistrationService) StringUtils(org.springframework.util.StringUtils) DynamoDBMapperConfig(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperConfig) OAuthClientDetails(com.oauth.server.dto.OAuthClientDetails)

Example 3 with OAuthClientDetails

use of com.oauth.server.dto.OAuthClientDetails in project alexa-oauth-sample by alexa-samples.

the class DynamoDBClientDetailsDAO method addClientDetails.

/**
 * Add a new {@link ClientDetails} into Database.
 *
 * @param clientDetails client details to be added.
 * @throws ClientAlreadyExistsException if client details already exists.
 */
@Override
public void addClientDetails(ClientDetails clientDetails) throws ClientAlreadyExistsException {
    OAuthClientDetails oAuthClientDetails = dynamoDBMapper.load(OAuthClientDetails.class, clientDetails.getClientId());
    if (oAuthClientDetails != null) {
        throw new ClientAlreadyExistsException("client already exists: " + clientDetails.getClientId());
    }
    addOrUpdateClientDetails(clientDetails);
}
Also used : OAuthClientDetails(com.oauth.server.dto.OAuthClientDetails) ClientAlreadyExistsException(org.springframework.security.oauth2.provider.ClientAlreadyExistsException)

Example 4 with OAuthClientDetails

use of com.oauth.server.dto.OAuthClientDetails in project alexa-oauth-sample by alexa-samples.

the class DynamoDBClientDetailsDAO method updateClientDetails.

/**
 * Update an existing {@link ClientDetails} in database.
 *
 * @param clientDetails client details.
 * @throws NoSuchClientException if client not exit.
 */
@Override
public void updateClientDetails(@NonNull ClientDetails clientDetails) throws NoSuchClientException {
    OAuthClientDetails oAuthClientDetails = dynamoDBMapper.load(OAuthClientDetails.class, clientDetails.getClientId());
    if (oAuthClientDetails == null) {
        throw new NoSuchClientException("client not exists: " + clientDetails.getClientId());
    }
    addOrUpdateClientDetails(clientDetails);
}
Also used : OAuthClientDetails(com.oauth.server.dto.OAuthClientDetails) NoSuchClientException(org.springframework.security.oauth2.provider.NoSuchClientException)

Example 5 with OAuthClientDetails

use of com.oauth.server.dto.OAuthClientDetails in project alexa-oauth-sample by alexa-samples.

the class DynamoDBClientDetailsDAO method updateClientSecret.

/**
 * Update the client secret for a specific client id.
 *
 * @param clientId client id.
 * @param secret client secret.
 * @throws NoSuchClientException if client not exist.
 */
@Override
public void updateClientSecret(@NonNull String clientId, @NonNull String secret) throws NoSuchClientException {
    OAuthClientDetails oAuthClientDetails = dynamoDBMapper.load(OAuthClientDetails.class, clientId);
    if (oAuthClientDetails == null) {
        throw new NoSuchClientException("client not exists: " + clientId);
    }
    OAuthClientDetails updatedItem = oAuthClientDetails.toBuilder().clientSecret(passwordEncoder.encode(secret)).build();
    dynamoDBMapper.save(updatedItem);
}
Also used : OAuthClientDetails(com.oauth.server.dto.OAuthClientDetails) NoSuchClientException(org.springframework.security.oauth2.provider.NoSuchClientException)

Aggregations

OAuthClientDetails (com.oauth.server.dto.OAuthClientDetails)5 NoSuchClientException (org.springframework.security.oauth2.provider.NoSuchClientException)3 ClientAlreadyExistsException (org.springframework.security.oauth2.provider.ClientAlreadyExistsException)2 DynamoDBMapper (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper)1 DynamoDBMapperConfig (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperConfig)1 SaveBehavior (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperConfig.SaveBehavior)1 DynamoDBScanExpression (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression)1 OAuthPartner (com.oauth.server.dto.OAuthPartner)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 NonNull (lombok.NonNull)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 Log4j2 (lombok.extern.log4j.Log4j2)1 PasswordEncoder (org.springframework.security.crypto.password.PasswordEncoder)1 ClientDetails (org.springframework.security.oauth2.provider.ClientDetails)1 ClientDetailsService (org.springframework.security.oauth2.provider.ClientDetailsService)1 ClientRegistrationException (org.springframework.security.oauth2.provider.ClientRegistrationException)1 ClientRegistrationService (org.springframework.security.oauth2.provider.ClientRegistrationService)1 StringUtils (org.springframework.util.StringUtils)1