-
-
Notifications
You must be signed in to change notification settings - Fork 343
AWS Cognito Integration #1256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Forfend
wants to merge
10
commits into
awspring:main
Choose a base branch
from
Forfend:gh-1246
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
AWS Cognito Integration #1256
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d884098
AWS Cognito Autoconfiguration
Forfend 53feeb3
gh-1246: AWS Cognito Integration 1.0
Forfend 8de3eec
gh-1246: sample for AWS Cognito Integration
Forfend 84ffac1
Merge branch 'main' of github.com:awspring/spring-cloud-aws into gh-1246
Forfend 17610e0
gh-1246: create some sample of using Cognito integration. Cover Cogni…
Forfend 572565f
gh-1246: fix comments & remove unnecessary exclusions
Forfend 64ee4dc
Merge branch 'main' of github.com:awspring/spring-cloud-aws into gh-1246
Forfend 8622414
Merge branch 'main' of github.com:awspring/spring-cloud-aws into gh-1246
Forfend e4dc185
gh-1246: support for public client operations
Forfend c7606ff
Merge branch 'main' of github.com:awspring/spring-cloud-aws into gh-1246
Forfend File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...igure/src/main/java/io/awspring/cloud/autoconfigure/cognito/CognitoAutoConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright 2013-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.awspring.cloud.autoconfigure.cognito; | ||
|
||
import io.awspring.cloud.autoconfigure.AwsSyncClientCustomizer; | ||
import io.awspring.cloud.autoconfigure.core.AwsAutoConfiguration; | ||
import io.awspring.cloud.autoconfigure.core.AwsClientBuilderConfigurer; | ||
import io.awspring.cloud.autoconfigure.core.AwsConnectionDetails; | ||
import io.awspring.cloud.autoconfigure.core.CredentialsProviderAutoConfiguration; | ||
import io.awspring.cloud.autoconfigure.core.RegionProviderAutoConfiguration; | ||
import io.awspring.cloud.cognito.CognitoTemplate; | ||
import org.springframework.beans.factory.ObjectProvider; | ||
import org.springframework.boot.autoconfigure.AutoConfiguration; | ||
import org.springframework.boot.autoconfigure.AutoConfigureAfter; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import software.amazon.awssdk.services.cognitoidentityprovider.CognitoIdentityProviderClient; | ||
|
||
/** | ||
* {@link AutoConfiguration Auto-Configuration} for AWS Cognito integration. | ||
* | ||
* @author Oleh Onufryk | ||
* @since 3.3.0 | ||
*/ | ||
|
||
@AutoConfiguration | ||
@EnableConfigurationProperties(CognitoProperties.class) | ||
@ConditionalOnClass({ CognitoIdentityProviderClient.class }) | ||
@AutoConfigureAfter({ CredentialsProviderAutoConfiguration.class, RegionProviderAutoConfiguration.class, | ||
AwsAutoConfiguration.class }) | ||
MatejNedic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@ConditionalOnProperty(name = "spring.cloud.aws.cognito.enabled", havingValue = "true", matchIfMissing = true) | ||
public class CognitoAutoConfiguration { | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
public CognitoIdentityProviderClient cognitoIdentityProviderClient(CognitoProperties cognitoProperties, | ||
AwsClientBuilderConfigurer awsClientBuilderConfigurer, ObjectProvider<CognitoClientCustomizer> customizers, | ||
ObjectProvider<AwsSyncClientCustomizer> awsSyncClientCustomizers, | ||
ObjectProvider<AwsConnectionDetails> connectionDetails) { | ||
return awsClientBuilderConfigurer.configureSyncClient(CognitoIdentityProviderClient.builder(), | ||
cognitoProperties, connectionDetails.getIfAvailable(), customizers.orderedStream(), | ||
awsSyncClientCustomizers.orderedStream()).build(); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
@ConditionalOnProperty(name = { "spring.cloud.aws.cognito.client-id", "spring.cloud.aws.cognito.user-pool-id" }) | ||
public CognitoTemplate cognitoTemplate(CognitoProperties cognitoProperties, | ||
CognitoIdentityProviderClient cognitoIdentityProviderClient) { | ||
return new CognitoTemplate(cognitoIdentityProviderClient, cognitoProperties.getClientId(), | ||
cognitoProperties.getUserPoolId(), cognitoProperties.getClientSecret()); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...figure/src/main/java/io/awspring/cloud/autoconfigure/cognito/CognitoClientCustomizer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2013-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.awspring.cloud.autoconfigure.cognito; | ||
|
||
import io.awspring.cloud.autoconfigure.AwsClientCustomizer; | ||
import software.amazon.awssdk.services.cognitoidentityprovider.CognitoIdentityProviderClientBuilder; | ||
|
||
@FunctionalInterface | ||
public interface CognitoClientCustomizer extends AwsClientCustomizer<CognitoIdentityProviderClientBuilder> { | ||
} |
87 changes: 87 additions & 0 deletions
87
...utoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cognito/CognitoProperties.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright 2013-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.awspring.cloud.autoconfigure.cognito; | ||
|
||
import io.awspring.cloud.autoconfigure.AwsClientProperties; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
/** | ||
* Configuration properties for AWS Cognito Integration | ||
* | ||
* @author Oleh Onufryk | ||
* @since 3.3.0 | ||
*/ | ||
|
||
@ConfigurationProperties(CognitoProperties.CONFIG_PREFIX) | ||
public class CognitoProperties extends AwsClientProperties { | ||
|
||
/** | ||
* Configuration prefix. | ||
*/ | ||
public static final String CONFIG_PREFIX = "spring.cloud.aws.cognito"; | ||
|
||
/** | ||
* Enables Cognito integration. | ||
*/ | ||
private boolean enabled = true; | ||
MatejNedic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* The user pool ID. | ||
*/ | ||
private String userPoolId; | ||
|
||
/** | ||
* The client ID. | ||
*/ | ||
private String clientId; | ||
|
||
/** | ||
* The client secret. | ||
*/ | ||
private String clientSecret; | ||
|
||
public boolean isEnabled() { | ||
return enabled; | ||
} | ||
|
||
public void setEnabled(boolean enabled) { | ||
this.enabled = enabled; | ||
} | ||
|
||
public String getUserPoolId() { | ||
return userPoolId; | ||
} | ||
|
||
public void setUserPoolId(String userPoolId) { | ||
this.userPoolId = userPoolId; | ||
} | ||
|
||
public String getClientId() { | ||
return clientId; | ||
} | ||
|
||
public void setClientId(String clientId) { | ||
this.clientId = clientId; | ||
} | ||
|
||
public String getClientSecret() { | ||
return clientSecret; | ||
} | ||
|
||
public void setClientSecret(String clientSecret) { | ||
this.clientSecret = clientSecret; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cognito/package-info.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright 2013-2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* {@link org.springframework.boot.context.config.ConfigDataLoader} implementation for AWS Cognito. | ||
*/ | ||
@org.springframework.lang.NonNullApi | ||
@org.springframework.lang.NonNullFields | ||
package io.awspring.cloud.autoconfigure.cognito; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...e/src/test/java/io/awspring/cloud/autoconfigure/cognito/CognitoAutoConfigurationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright 2013-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.awspring.cloud.autoconfigure.cognito; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import io.awspring.cloud.autoconfigure.core.AwsAutoConfiguration; | ||
import io.awspring.cloud.autoconfigure.core.CredentialsProviderAutoConfiguration; | ||
import io.awspring.cloud.autoconfigure.core.RegionProviderAutoConfiguration; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.autoconfigure.AutoConfigurations; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.boot.test.context.runner.ApplicationContextRunner; | ||
import org.springframework.context.annotation.Bean; | ||
import software.amazon.awssdk.services.cognitoidentityprovider.CognitoIdentityProviderClient; | ||
|
||
/** | ||
* Test for {@link CognitoAutoConfiguration} | ||
*/ | ||
class CognitoAutoConfigurationTest { | ||
|
||
private final ApplicationContextRunner runner = new ApplicationContextRunner() | ||
.withPropertyValues("spring.cloud.aws.region.static:eu-west-1") | ||
.withConfiguration(AutoConfigurations.of(RegionProviderAutoConfiguration.class, | ||
CredentialsProviderAutoConfiguration.class, CognitoAutoConfiguration.class, | ||
AwsAutoConfiguration.class)); | ||
|
||
@Test | ||
void cognitoAutoConfigurationIsDisabled() { | ||
this.runner.withPropertyValues("spring.cloud.aws.cognito.enabled:false") | ||
.run(context -> assertThat(context).doesNotHaveBean(CognitoIdentityProviderClient.class)); | ||
} | ||
|
||
@Test | ||
void cognitoAutoConfigurationIsEnabled() { | ||
this.runner.withPropertyValues("spring.cloud.aws.cognito.enabled:true") | ||
.run(context -> assertThat(context).hasSingleBean(CognitoIdentityProviderClient.class)); | ||
} | ||
|
||
@Test | ||
void createCognitoClientBeanByDefault() { | ||
this.runner.run(context -> assertThat(context).hasSingleBean(CognitoAutoConfiguration.class)); | ||
} | ||
|
||
@Test | ||
void usesCustomBeanWhenProvided() { | ||
this.runner.withUserConfiguration(CustomCognitoConfiguration.class).run(context -> { | ||
assertThat(context).hasSingleBean(CognitoIdentityProviderClient.class); | ||
assertThat(context.getBean(CognitoIdentityProviderClient.class)).isNotNull(); | ||
}); | ||
} | ||
|
||
@TestConfiguration | ||
static class CustomCognitoConfiguration { | ||
@Bean | ||
CognitoIdentityProviderClient cognitoIdentityProviderClient() { | ||
return mock(CognitoIdentityProviderClient.class); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>io.awspring.cloud</groupId> | ||
<artifactId>spring-cloud-aws</artifactId> | ||
<version>3.3.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>spring-cloud-aws-cognito</artifactId> | ||
<name>Spring Cloud AWS Cognito Integration</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>cognitoidentityprovider</artifactId> | ||
<exclusions> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is reason for Exclusions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MatejNedic tbh there is no specific reason, just not to include additional dependencies. can be removed |
||
<exclusion> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>netty-nio-client</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>apache-client</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-core</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.