Skip to content

Commit 83bf238

Browse files
committed
Document OAuth 2 support
1 parent 3619ebd commit 83bf238

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/docs/asciidoc/advanced-topics.adoc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,31 @@ A defined set of values shared across the messages is a good candidate: geograph
8686
Cardinality of filter values can be from a few to a few thousands.
8787
Extreme cardinality (a couple or dozens of thousands) can make filtering less efficient.
8888

89+
=== OAuth 2 Support
90+
91+
The client can authenticate against an OAuth 2 server like https://github.com/cloudfoundry/uaa[UAA].
92+
It uses the https://tools.ietf.org/html/rfc6749#section-4.4[OAuth 2 Client Credentials flow].
93+
The https://www.rabbitmq.com/docs/oauth2[OAuth 2 plugin] must be enabled on the server side and configured to use the same OAuth 2 server as the client.
94+
95+
How to retrieve the OAuth 2 token is configured at the environment level:
96+
97+
.Configuring OAuth 2 token retrieval
98+
[source,java,indent=0]
99+
--------
100+
include::{test-examples}/EnvironmentUsage.java[tag=oauth2]
101+
--------
102+
<1> Access the OAuth 2 configuration
103+
<2> Set the token endpoint URI
104+
<3> Authenticate the client application
105+
<4> Set the grant type
106+
<5> Set optional parameters (depends on the OAuth 2 server)
107+
<6> Set the SSL context (e.g. to verify and trust the identity of the OAuth 2 server)
108+
109+
The environment retrieves tokens and uses them to create stream connections.
110+
It also takes care of refreshing the tokens before they expire and of re-authenticating existing connections so the broker does not close them when their token expires.
111+
112+
The environment uses the same token for all the connections it maintains.
113+
89114
=== Using Native `epoll`
90115

91116
The stream Java client uses the https://netty.io/[Netty] network framework and its Java NIO transport implementation by default.

src/test/java/com/rabbitmq/stream/docs/EnvironmentUsage.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
import io.micrometer.observation.ObservationRegistry;
2121
import io.netty.channel.EventLoopGroup;
2222
import io.netty.channel.MultiThreadIoEventLoopGroup;
23-
import io.netty.channel.epoll.EpollEventLoopGroup;
2423
import io.netty.channel.epoll.EpollIoHandler;
2524
import io.netty.channel.epoll.EpollSocketChannel;
2625
import io.netty.handler.ssl.SslContext;
2726
import io.netty.handler.ssl.SslContextBuilder;
27+
28+
import javax.net.ssl.SSLContext;
2829
import java.io.FileInputStream;
2930
import java.security.cert.CertificateFactory;
3031
import java.security.cert.X509Certificate;
@@ -140,6 +141,22 @@ void deleteStream() {
140141
// end::stream-deletion[]
141142
}
142143

144+
void oauth2() {
145+
SSLContext sslContext = null;
146+
// tag::oauth2[]
147+
Environment env = Environment.builder()
148+
.oauth2() // <1>
149+
.tokenEndpointUri("https://localhost:8443/uaa/oauth/token/") // <2>
150+
.clientId("rabbitmq").clientSecret("rabbitmq") // <3>
151+
.grantType("password") // <4>
152+
.parameter("username", "rabbit_super") // <5>
153+
.parameter("password", "rabbit_super") // <5>
154+
.sslContext(sslContext) // <6>
155+
.environmentBuilder()
156+
.build();
157+
// end::oauth2[]
158+
}
159+
143160
void nativeEpoll() {
144161
// tag::native-epoll[]
145162
EventLoopGroup epollEventLoopGroup = new MultiThreadIoEventLoopGroup( // <1>

0 commit comments

Comments
 (0)