Skip to content
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

Added support for OAuth2 authentication with the Solace PubSub+ Broker #313

Merged
merged 12 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<groupId>com.solace.spring.boot</groupId>
<artifactId>solace-spring-boot-bom</artifactId>
<version>2.0.0</version>
<version>2.1.0</version>
</parent>

<groupId>com.solace.spring.cloud</groupId>
<artifactId>solace-spring-cloud-build</artifactId>
<version>4.2.1-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Solace Spring Cloud Build</name>
Expand All @@ -21,20 +21,20 @@
<repoName>SolaceProducts</repoName>

<!-- This is the version of Spring Cloud we have targeted for this build -->
<spring.cloud.version>2023.0.2</spring.cloud.version>
<spring.cloud.version>2023.0.3</spring.cloud.version>

<!-- This is the version of Solace Spring Boot we have targeted for this build -->
<!-- This also dictates the expected version of Spring Boot -->
<!-- Must match ${project.parent.version} -->
<solace.spring.boot.bom.version>2.0.0</solace.spring.boot.bom.version>
<solace.spring.boot.bom.version>2.1.0</solace.spring.boot.bom.version>

<!-- Override spring-boot version from solace-spring-boot to latest patch version -->
<!-- Remove this if the next version of solace-spring-boot works fine -->
<spring.boot.version>3.3.1</spring.boot.version>
<spring.boot.version>3.3.2</spring.boot.version>

<solace.spring.cloud.stream-starter.version>5.2.1-SNAPSHOT</solace.spring.cloud.stream-starter.version>
<solace.spring.cloud.stream-starter.version>5.3.0-SNAPSHOT</solace.spring.cloud.stream-starter.version>

<solace.integration.test.support.version>1.0.2</solace.integration.test.support.version>
<solace.integration.test.support.version>1.1.2</solace.integration.test.support.version>
<solace.integration.test.support.fetch_checkout.skip>false</solace.integration.test.support.fetch_checkout.skip>
<solace.integration.test.support.install.skip>true</solace.integration.test.support.install.skip>
</properties>
Expand Down
7 changes: 4 additions & 3 deletions solace-spring-cloud-bom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Consult the table below to determine which version of the BOM you need to use:
| 2022.0.4 | 3.1.0, 3.2.0 | 3.1.x |
| 2023.0.1 | 4.0.0, 4.1.0 | 3.2.x |
| 2023.0.2 | 4.2.0 | 3.3.x |
| 2023.0.3 | 4.3.0 | 3.3.x |

## Including the BOM

Expand All @@ -40,7 +41,7 @@ In addition to showing how to include the BOM, the following snippets also shows
<dependency>
<groupId>com.solace.spring.cloud</groupId>
<artifactId>solace-spring-cloud-bom</artifactId>
<version>4.2.0</version>
<version>4.3.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -68,7 +69,7 @@ apply plugin: 'io.spring.dependency-management'

dependencyManagement {
imports {
mavenBom "com.solace.spring.cloud:solace-spring-cloud-bom:4.2.0"
mavenBom "com.solace.spring.cloud:solace-spring-cloud-bom:4.3.0"
}
}

Expand All @@ -80,7 +81,7 @@ dependencies {
### Using it with Gradle 5
```groovy
dependencies {
implementation(platform("com.solace.spring.cloud:solace-spring-cloud-bom:4.2.0"))
implementation(platform("com.solace.spring.cloud:solace-spring-cloud-bom:4.3.0"))
implementation("com.solace.spring.cloud:spring-cloud-starter-stream-solace")
}
```
4 changes: 2 additions & 2 deletions solace-spring-cloud-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<parent>
<groupId>com.solace.spring.cloud</groupId>
<artifactId>solace-spring-cloud-build</artifactId>
<version>4.2.1-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>solace-spring-cloud-bom</artifactId>
<packaging>pom</packaging>
<version>4.2.1-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>

<name>Solace Spring Cloud BOM</name>
<description>BOM for Solace Spring Cloud</description>
Expand Down
2 changes: 1 addition & 1 deletion solace-spring-cloud-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.solace.spring.cloud</groupId>
<artifactId>solace-spring-cloud-build</artifactId>
<version>4.2.1-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
= Spring Cloud Stream Binder for Solace PubSub+
:revnumber: 5.2.0
:revnumber: 5.3.0
:toc: preamble
:toclevels: 3
:icons: font
Expand Down Expand Up @@ -175,6 +175,11 @@ Additional session properties not available under the usual `solace.java` prefix
See https://github.com/SolaceProducts/solace-spring-boot/tree/master/solace-spring-boot-starters/solace-java-spring-boot-starter#updating-your-application-properties[JCSMP Spring Boot Auto-Configuration documentation] for more info about `solace.java.apiProperties`.
====

[TIP]
====
The Solace session can be configured to use OAuth2 authentication. See https://github.com/SolaceDev/solace-spring-boot/tree/master/solace-spring-boot-starters/solace-java-spring-boot-starter#using-oauth2-authentication-scheme-with-solace-java-api[JCSMP Spring Boot: Using OAuth2 Authentication Scheme] for more info.
====

==== Solace Consumer Properties

The following properties are available for Solace consumers only and must be prefixed with `spring.cloud.stream.solace.bindings.&lt;bindingName&gt;.consumer.` where `bindingName` looks something like `functionName-in-0` as defined in https://docs.spring.io/spring-cloud-stream/docs/{scst-version}/reference/html/spring-cloud-stream.html#_functional_binding_names[Functional Binding Names].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<groupId>com.solace.spring.cloud</groupId>
<artifactId>solace-spring-cloud-parent</artifactId>
<version>4.2.1-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>
<relativePath>../../solace-spring-cloud-parent/pom.xml</relativePath>
</parent>

<artifactId>spring-cloud-starter-stream-solace</artifactId>
<version>5.2.1-SNAPSHOT</version>
<version>5.3.0-SNAPSHOT</version>
<packaging>jar</packaging>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<groupId>com.solace.spring.cloud</groupId>
<artifactId>solace-spring-cloud-parent</artifactId>
<version>4.2.1-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>
<relativePath>../../solace-spring-cloud-parent/pom.xml</relativePath>
</parent>

<artifactId>spring-cloud-stream-binder-solace-core</artifactId>
<version>5.2.1-SNAPSHOT</version>
<version>5.3.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Solace Spring Cloud Stream Binder Core</name>
Expand Down Expand Up @@ -82,6 +82,12 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-test-binder</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package com.solace.spring.cloud.stream.binder.health.handlers;

import com.solace.spring.cloud.stream.binder.health.indicators.SessionHealthIndicator;
import com.solacesystems.jcsmp.DefaultSolaceOAuth2SessionEventHandler;
import com.solacesystems.jcsmp.JCSMPProperties;
import com.solacesystems.jcsmp.SessionEventArgs;
import com.solacesystems.jcsmp.SessionEventHandler;
import com.solacesystems.jcsmp.SolaceSessionOAuth2TokenProvider;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.lang.Nullable;

public class SolaceSessionEventHandler implements SessionEventHandler {
public class SolaceSessionEventHandler extends DefaultSolaceOAuth2SessionEventHandler {
private final SessionHealthIndicator sessionHealthIndicator;
private static final Log logger = LogFactory.getLog(SolaceSessionEventHandler.class);

public SolaceSessionEventHandler(SessionHealthIndicator sessionHealthIndicator) {
public SolaceSessionEventHandler(JCSMPProperties jcsmpProperties,
@Nullable SolaceSessionOAuth2TokenProvider solaceSessionOAuth2TokenProvider,
SessionHealthIndicator sessionHealthIndicator) {
super(jcsmpProperties, solaceSessionOAuth2TokenProvider);
this.sessionHealthIndicator = sessionHealthIndicator;
}

Expand All @@ -19,6 +25,7 @@ public void handleEvent(SessionEventArgs eventArgs) {
if (logger.isDebugEnabled()) {
logger.debug(String.format("Received Solace JCSMP Session event [%s]", eventArgs));
}
super.handleEvent(eventArgs);
switch (eventArgs.getEvent()) {
case RECONNECTED -> this.sessionHealthIndicator.up();
case DOWN_ERROR -> this.sessionHealthIndicator.down(eventArgs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void testRejectFail(@Values(ints = {1, 255}) int numMessages,

logger.info(String.format("Disabling egress for queue %s", queue.getName()));
sempV2Api.config().updateMsgVpnQueue((String) jcsmpSession.getProperty(JCSMPProperties.VPN_NAME),
queue.getName(), new ConfigMsgVpnQueue().egressEnabled(false), null);
queue.getName(), new ConfigMsgVpnQueue().egressEnabled(false), null, null);
retryAssert(() -> assertFalse(sempV2Api.monitor()
.getMsgVpnQueue(vpnName, queue.getName(), null)
.getData()
Expand All @@ -214,7 +214,7 @@ public void testRejectFail(@Values(ints = {1, 255}) int numMessages,

logger.info(String.format("Enabling egress for queue %s", queue.getName()));
sempV2Api.config().updateMsgVpnQueue((String) jcsmpSession.getProperty(JCSMPProperties.VPN_NAME),
queue.getName(), new ConfigMsgVpnQueue().egressEnabled(true), null);
queue.getName(), new ConfigMsgVpnQueue().egressEnabled(true), null, null);
retryAssert(() -> assertTrue(sempV2Api.monitor()
.getMsgVpnQueue(vpnName, queue.getName(), null)
.getData()
Expand Down Expand Up @@ -277,7 +277,7 @@ public void testRejectWithErrorQueueFail(@Values(ints = {1, 255}) int numMessage
logger.info(String.format("Disabling ingress for error queue %s",
errorQueueInfrastructure.getErrorQueueName()));
sempV2Api.config().updateMsgVpnQueue((String) jcsmpSession.getProperty(JCSMPProperties.VPN_NAME),
errorQueueInfrastructure.getErrorQueueName(), new ConfigMsgVpnQueue().ingressEnabled(false), null);
errorQueueInfrastructure.getErrorQueueName(), new ConfigMsgVpnQueue().ingressEnabled(false), null, null);
retryAssert(() -> assertFalse(sempV2Api.monitor()
.getMsgVpnQueue(vpnName, errorQueueInfrastructure.getErrorQueueName(), null)
.getData()
Expand Down Expand Up @@ -349,7 +349,7 @@ public void testRequeueFail(@Values(ints = {1, 255}) int numMessages,

logger.info(String.format("Disabling egress for queue %s", queue.getName()));
sempV2Api.config().updateMsgVpnQueue((String) jcsmpSession.getProperty(JCSMPProperties.VPN_NAME),
queue.getName(), new ConfigMsgVpnQueue().egressEnabled(false), null);
queue.getName(), new ConfigMsgVpnQueue().egressEnabled(false), null, null);
retryAssert(() -> assertFalse(sempV2Api.monitor()
.getMsgVpnQueue(vpnName, queue.getName(), null)
.getData()
Expand All @@ -370,7 +370,7 @@ public void testRequeueFail(@Values(ints = {1, 255}) int numMessages,

logger.info(String.format("Enabling egress for queue %s", queue.getName()));
sempV2Api.config().updateMsgVpnQueue((String) jcsmpSession.getProperty(JCSMPProperties.VPN_NAME),
queue.getName(), new ConfigMsgVpnQueue().egressEnabled(true), null);
queue.getName(), new ConfigMsgVpnQueue().egressEnabled(true), null, null);
retryAssert(() -> assertTrue(sempV2Api.monitor()
.getMsgVpnQueue(vpnName, queue.getName(), null)
.getData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public void testHandleErrorAsyncRetry(boolean isDurable, JCSMPSession jcsmpSessi

logger.info(String.format("Shutting down ingress for queue %s", errorQueue.getName()));
sempV2Api.config().updateMsgVpnQueue(vpnName, errorQueue.getName(),
new ConfigMsgVpnQueue().ingressEnabled(false), null);
new ConfigMsgVpnQueue().ingressEnabled(false), null, null);
retryAssert(() -> assertFalse(sempV2Api.monitor()
.getMsgVpnQueue(vpnName, errorQueue.getName(), null)
.getData()
Expand All @@ -183,7 +183,7 @@ public void testHandleErrorAsyncRetry(boolean isDurable, JCSMPSession jcsmpSessi
if (key.getErrorQueueDeliveryAttempt() == errorQueueInfrastructure.getMaxDeliveryAttempts()) {
logger.info(String.format("Starting ingress for queue %s", errorQueue.getName()));
sempV2Api.config().updateMsgVpnQueue(vpnName, errorQueue.getName(),
new ConfigMsgVpnQueue().ingressEnabled(true), null);
new ConfigMsgVpnQueue().ingressEnabled(true), null, null);
retryAssert(() -> assertTrue(sempV2Api.monitor()
.getMsgVpnQueue(vpnName, errorQueue.getName(), null)
.getData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ public void testReceiveInterruptedByFlowReconnect(@Values(booleans = {false, tru

logger.info(String.format("Disabling egress to queue %s", queue.getName()));
sempV2Api.config().updateMsgVpnQueue(vpnName, queue.getName(), new ConfigMsgVpnQueue().egressEnabled(false),
null);
null, null);
retryAssert(() -> assertFalse(sempV2Api.monitor()
.getMsgVpnQueue(vpnName, queue.getName(), null)
.getData()
Expand All @@ -784,7 +784,7 @@ public void testReceiveInterruptedByFlowReconnect(@Values(booleans = {false, tru

logger.info(String.format("Enabling egress to queue %s", queue.getName()));
sempV2Api.config().updateMsgVpnQueue(vpnName, queue.getName(), new ConfigMsgVpnQueue().egressEnabled(true),
null);
null, null);
retryAssert(() -> assertTrue(sempV2Api.monitor()
.getMsgVpnQueue(vpnName, queue.getName(), null)
.getData()
Expand Down Expand Up @@ -871,7 +871,7 @@ public void testAcknowledgeAfterFlowReconnect(JCSMPSession jcsmpSession, Queue q

logger.info(String.format("Disabling egress to queue %s", queue.getName()));
sempV2Api.config().updateMsgVpnQueue(vpnName, queue.getName(), new ConfigMsgVpnQueue().egressEnabled(false),
null);
null, null);
retryAssert(() -> assertFalse(sempV2Api.monitor()
.getMsgVpnQueue(vpnName, queue.getName(), null)
.getData()
Expand All @@ -881,7 +881,7 @@ public void testAcknowledgeAfterFlowReconnect(JCSMPSession jcsmpSession, Queue q

logger.info(String.format("Enabling egress to queue %s", queue.getName()));
sempV2Api.config().updateMsgVpnQueue(vpnName, queue.getName(), new ConfigMsgVpnQueue().egressEnabled(true),
null);
null, null);
retryAssert(() -> assertTrue(sempV2Api.monitor()
.getMsgVpnQueue(vpnName, queue.getName(), null)
.getData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<groupId>com.solace.spring.cloud</groupId>
<artifactId>solace-spring-cloud-parent</artifactId>
<version>4.2.1-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>
<relativePath>../../solace-spring-cloud-parent/pom.xml</relativePath>
</parent>

<artifactId>spring-cloud-stream-binder-solace</artifactId>
<version>5.2.1-SNAPSHOT</version>
<version>5.3.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Solace Spring Cloud Stream Binder</name>
Expand Down Expand Up @@ -106,12 +106,23 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import com.solace.spring.cloud.stream.binder.health.handlers.SolaceSessionEventHandler;
import com.solace.spring.cloud.stream.binder.health.indicators.SessionHealthIndicator;
import com.solace.spring.cloud.stream.binder.properties.SolaceSessionHealthProperties;
import com.solacesystems.jcsmp.JCSMPProperties;
import com.solacesystems.jcsmp.SolaceSessionOAuth2TokenProvider;
import jakarta.annotation.Nullable;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
Expand Down Expand Up @@ -40,11 +43,14 @@ public SolaceBinderHealthContributor solaceBinderHealthContributor(
}

@Bean
public SolaceSessionEventHandler solaceSessionEventHandler(SolaceBinderHealthContributor healthContributor) {
public SolaceSessionEventHandler solaceSessionEventHandler(
JCSMPProperties jcsmpProperties,
@Nullable SolaceSessionOAuth2TokenProvider solaceSessionOAuth2TokenProvider,
SolaceBinderHealthContributor healthContributor) {
if (logger.isDebugEnabled()) {
logger.debug("Creating Solace Session Event Handler for monitoring Health");
}
return new SolaceSessionEventHandler(healthContributor.getSolaceSessionHealthIndicator());
return new SolaceSessionEventHandler(jcsmpProperties, solaceSessionOAuth2TokenProvider, healthContributor.getSolaceSessionHealthIndicator());
}

}
Loading
Loading