-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OAuth2 support for authentication with Solace PubSub+ Broker. (#133)
* Add OAuth2 support for authentication with Solace PubSub+ Broker * Disable overwrite settings in setup-java (#40) * Updated dev docs. * Fix action permissions (#41) * fix manual test support install version * Remove unwanted test dependency as requested in #101 Use slf4j instead of apache logging --------- Co-authored-by: Jeffrey D <[email protected]>
- Loading branch information
1 parent
320892d
commit 39febc5
Showing
77 changed files
with
6,373 additions
and
201 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -5,10 +5,23 @@ name: build | |
on: | ||
pull_request: | ||
push: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
dupe_check: | ||
name: Check for Duplicate Workflow Run | ||
runs-on: ubuntu-latest | ||
outputs: | ||
should_skip: ${{ steps.skip_check.outputs.should_skip }} | ||
steps: | ||
- id: skip_check | ||
uses: fkirc/[email protected] | ||
with: | ||
concurrent_skipping: same_content | ||
do_not_skip: '["pull_request", "workflow_dispatch", "schedule"]' | ||
|
||
build: | ||
if: needs.dupe_check.outputs.should_skip != 'true' | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
|
@@ -18,7 +31,19 @@ jobs: | |
with: | ||
distribution: 'zulu' | ||
java-version: '17' | ||
overwrite-settings: false | ||
cache: 'maven' | ||
- name: Manually Install Test Support If Necessary | ||
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name | ||
run: | | ||
sudo apt-get update -qq | ||
sudo apt-get install -y libxml2-utils | ||
version="$(xmllint --xpath '/*[local-name()="project"]/*[local-name()="properties"]/*[local-name()="solace.integration.test.support.version"]/text()' pom.xml)" | ||
echo "Detected test support version: ${version}" | ||
git clone --depth 1 --branch "${version}" https://github.com/SolaceDev/solace-integration-test-support.git | ||
cd "${GITHUB_WORKSPACE}/solace-integration-test-support" | ||
mvn install -Dchangelist= -DskipTests | ||
- name: Build and run Tests | ||
run: mvn clean verify --settings "${GITHUB_WORKSPACE}/maven/settings.xml" | ||
env: | ||
|
This file contains 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 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 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 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 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 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
70 changes: 70 additions & 0 deletions
70
...re/src/main/java/com/solace/spring/boot/autoconfigure/SolaceOAuthClientConfiguration.java
This file contains 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,70 @@ | ||
package com.solace.spring.boot.autoconfigure; | ||
|
||
import com.solacesystems.jcsmp.DefaultSolaceSessionOAuth2TokenProvider; | ||
import com.solacesystems.jcsmp.JCSMPProperties; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.autoconfigure.security.oauth2.client.servlet.OAuth2ClientAutoConfiguration; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.security.oauth2.client.AuthorizedClientServiceOAuth2AuthorizedClientManager; | ||
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientProvider; | ||
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientProviderBuilder; | ||
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService; | ||
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; | ||
|
||
/** | ||
* Configuration class for Solace OAuth client. This configuration is only active when the | ||
* 'solace.java.apiProperties.AUTHENTICATION_SCHEME' property is set to | ||
* 'AUTHENTICATION_SCHEME_OAUTH2'. | ||
*/ | ||
@Configuration | ||
@ConditionalOnProperty(prefix = "solace.java.apiProperties", name = "AUTHENTICATION_SCHEME", | ||
havingValue = "AUTHENTICATION_SCHEME_OAUTH2") | ||
@Import(OAuth2ClientAutoConfiguration.class) | ||
public class SolaceOAuthClientConfiguration { | ||
|
||
/** | ||
* Creates and configures an OAuth2AuthorizedClientManager for Solace session. This manager is | ||
* configured with OAuth2AuthorizedClientProvider for client credentials and refresh token. | ||
* | ||
* @param clientRegistrationRepository Repository of client registrations. | ||
* @param oAuth2AuthorizedClientService Service for authorized OAuth2 clients. | ||
* @return Configured OAuth2AuthorizedClientManager. | ||
*/ | ||
@Bean | ||
public AuthorizedClientServiceOAuth2AuthorizedClientManager solaceOAuthAuthorizedClientServiceAndManager( | ||
ClientRegistrationRepository clientRegistrationRepository, | ||
OAuth2AuthorizedClientService oAuth2AuthorizedClientService) { | ||
final OAuth2AuthorizedClientProvider clientCredentialsAuthorizedClientProvider = | ||
OAuth2AuthorizedClientProviderBuilder.builder() | ||
.authorizationCode() | ||
.clientCredentials() | ||
.refreshToken() | ||
.build(); | ||
|
||
final AuthorizedClientServiceOAuth2AuthorizedClientManager authorizedClientManager = | ||
new AuthorizedClientServiceOAuth2AuthorizedClientManager( | ||
clientRegistrationRepository, oAuth2AuthorizedClientService); | ||
authorizedClientManager.setAuthorizedClientProvider(clientCredentialsAuthorizedClientProvider); | ||
|
||
return authorizedClientManager; | ||
} | ||
|
||
/** | ||
* Creates a SolaceSessionOAuth2TokenProvider for providing OAuth2 access tokens for Solace | ||
* sessions. | ||
* | ||
* @param jcsmpProperties The JCSMP properties. | ||
* @param solaceOAuthAuthorizedClientServiceAndManager The OAuth2AuthorizedClientManager for | ||
* Solace session. | ||
* @return Configured SolaceSessionOAuth2TokenProvider. | ||
*/ | ||
@Bean | ||
public DefaultSolaceSessionOAuth2TokenProvider solaceSessionOAuth2TokenProvider( | ||
JCSMPProperties jcsmpProperties, | ||
AuthorizedClientServiceOAuth2AuthorizedClientManager solaceOAuthAuthorizedClientServiceAndManager) { | ||
return new DefaultSolaceSessionOAuth2TokenProvider(jcsmpProperties, | ||
solaceOAuthAuthorizedClientServiceAndManager); | ||
} | ||
} |
Oops, something went wrong.