Skip to content

Commit a124e15

Browse files
committed
Document OAuth 2 support
1 parent 6ba98e4 commit a124e15

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/docs/asciidoc/usage.adoc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,35 @@ include::{test-examples}/Api.java[tag=subscription-listener]
4646
<4> Get the message offset
4747
<5> Store the offset in the external store after processing
4848

49+
=== OAuth 2 Support
50+
51+
The client can authenticate against an OAuth 2 server like https://github.com/cloudfoundry/uaa[UAA].
52+
It uses the https://tools.ietf.org/html/rfc6749#section-4.4[OAuth 2 Client Credentials flow].
53+
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.
54+
55+
How to retrieve the OAuth 2 token can be globally configured at the environment level:
56+
57+
.Configuring OAuth 2 token retrieval
58+
[source,java,indent=0]
59+
--------
60+
include::{test-examples}/Api.java[tag=oauth2]
61+
--------
62+
<1> Access the OAuth 2 configuration
63+
<2> Set the token endpoint URI
64+
<3> Authenticate the client application
65+
<4> Set the grant type
66+
<5> Set optional parameters (depends on the OAuth 2 server)
67+
<6> Set the SSL context (e.g. to verify and trust the identity of the OAuth 2 server)
68+
<7> The token can be shared across the environment connections
69+
70+
The environment retrieves tokens and uses them to create AMQP connections.
71+
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.
72+
73+
The environment uses the same token for all the connections it maintains by default, but this can be changed by setting the `shared` flag to `false`.
74+
With `shared = false`, each connection will have its own OAuth 2 token.
75+
76+
The OAuth 2 configuration can be set at the environment level but also at the connection level.
77+
4978
=== Metrics Collection
5079

5180
The library provides the {javadoc-url}/com/rabbitmq/client/amqp/metrics/MetricsCollector.html[`MetricsCollector`] abstraction to collect metrics.

src/test/java/com/rabbitmq/client/amqp/docs/Api.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import io.micrometer.prometheusmetrics.PrometheusConfig;
2727
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry;
2828

29+
import javax.net.ssl.SSLContext;
30+
2931
class Api {
3032

3133
void connectionSettings() {
@@ -94,4 +96,21 @@ void micrometerObservation() {
9496
// end::micrometer-observation[]
9597
}
9698

99+
void oauth2() {
100+
SSLContext sslContext = null;
101+
// tag::oauth2[]
102+
Environment environment = new AmqpEnvironmentBuilder()
103+
.connectionSettings().oauth2() // <1>
104+
.tokenEndpointUri("https://localhost:8443/uaa/oauth/token/") // <2>
105+
.clientId("rabbitmq").clientSecret("rabbitmq") // <3>
106+
.grantType("password") // <4>
107+
.parameter("username", "rabbit_super") // <5>
108+
.parameter("password", "rabbit_super") // <5>
109+
.tls().sslContext(sslContext).oauth2() // <6>
110+
.shared(true) // <7>
111+
.connection()
112+
.environmentBuilder().build();
113+
// end::oauth2[]
114+
}
115+
97116
}

0 commit comments

Comments
 (0)