Skip to content

Commit 8e86369

Browse files
committed
Use OAuth 2 lingo (not just OAuth)
1 parent bfa950b commit 8e86369

18 files changed

+108
-105
lines changed

src/main/java/com/rabbitmq/client/amqp/ConnectionSettings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public interface ConnectionSettings<T> {
154154
*/
155155
Affinity<? extends T> affinity();
156156

157-
OAuthSettings<? extends T> oauth();
157+
OAuth2Settings<? extends T> oauth2();
158158

159159
/**
160160
* TLS settings.

src/main/java/com/rabbitmq/client/amqp/OAuthSettings.java renamed to src/main/java/com/rabbitmq/client/amqp/OAuth2Settings.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*
2626
* @param <T> the type of object returned by methods, usually the object itself
2727
*/
28-
public interface OAuthSettings<T> {
28+
public interface OAuth2Settings<T> {
2929

3030
/**
3131
* Set the URI to access to get the token.
@@ -35,27 +35,29 @@ public interface OAuthSettings<T> {
3535
* retrieve tokens.</em>
3636
*
3737
* @param uri access URI
38-
* @return OAuth settings
38+
* @return OAuth 2 settings
39+
* @see #tls()
40+
* @see TlsSettings#sslContext(SSLContext)
3941
*/
40-
OAuthSettings<T> tokenEndpointUri(String uri);
42+
OAuth2Settings<T> tokenEndpointUri(String uri);
4143

4244
/**
4345
* Set the OAuth 2 client ID
4446
*
4547
* <p>The client ID usually identifies the application that requests a token.
4648
*
4749
* @param clientId client ID
48-
* @return OAuth settings
50+
* @return OAuth 2 settings
4951
*/
50-
OAuthSettings<T> clientId(String clientId);
52+
OAuth2Settings<T> clientId(String clientId);
5153

5254
/**
5355
* Set the secret (password) to use to get a token.
5456
*
5557
* @param clientSecret client secret
56-
* @return OAuth settings
58+
* @return OAuth 2 settings
5759
*/
58-
OAuthSettings<T> clientSecret(String clientSecret);
60+
OAuth2Settings<T> clientSecret(String clientSecret);
5961

6062
/**
6163
* Set the grant type to use when requesting the token.
@@ -64,9 +66,9 @@ public interface OAuthSettings<T> {
6466
* non-standard grant types to request tokens with extra-information.
6567
*
6668
* @param grantType grant type
67-
* @return OAuth settings
69+
* @return OAuth 2 settings
6870
*/
69-
OAuthSettings<T> grantType(String grantType);
71+
OAuth2Settings<T> grantType(String grantType);
7072

7173
/**
7274
* Set a parameter to pass in the request.
@@ -75,19 +77,19 @@ public interface OAuthSettings<T> {
7577
*
7678
* @param name name of the parameter
7779
* @param value value of the parameter
78-
* @return OAuth settings
80+
* @return OAuth 2 settings
7981
*/
80-
OAuthSettings<T> parameter(String name, String value);
82+
OAuth2Settings<T> parameter(String name, String value);
8183

8284
/**
8385
* Whether to share the same token between connections.
8486
*
8587
* <p>Default is <true>true</true> (the token is shared between connections).
8688
*
8789
* @param shared flag to share the token between connections
88-
* @return OAuth settings
90+
* @return OAuth 2 settings
8991
*/
90-
OAuthSettings<T> shared(boolean shared);
92+
OAuth2Settings<T> shared(boolean shared);
9193

9294
/**
9395
* TLS configuration for requesting the token.
@@ -121,8 +123,8 @@ interface TlsSettings<T> {
121123
/**
122124
* Go back to the general OAuth 2 settings.
123125
*
124-
* @return OAuth settings
126+
* @return OAuth 2 settings
125127
*/
126-
OAuthSettings<T> oauth();
128+
OAuth2Settings<T> oauth2();
127129
}
128130
}

src/main/java/com/rabbitmq/client/amqp/impl/AmqpConnectionBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ public DefaultConnectionSettings.DefaultAffinity<? extends ConnectionBuilder> af
105105
}
106106

107107
@Override
108-
public OAuthSettings<? extends ConnectionBuilder> oauth() {
109-
return this.connectionSettings.oauth();
108+
public OAuth2Settings<? extends ConnectionBuilder> oauth2() {
109+
return this.connectionSettings.oauth2();
110110
}
111111

112112
@Override

src/main/java/com/rabbitmq/client/amqp/impl/CredentialsFactory.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@
1919

2020
import com.rabbitmq.client.amqp.CredentialsProvider;
2121
import com.rabbitmq.client.amqp.UsernamePasswordCredentialsProvider;
22-
import com.rabbitmq.client.amqp.oauth.GsonTokenParser;
23-
import com.rabbitmq.client.amqp.oauth.HttpTokenRequester;
22+
import com.rabbitmq.client.amqp.oauth2.GsonTokenParser;
23+
import com.rabbitmq.client.amqp.oauth2.HttpTokenRequester;
2424
import java.net.http.HttpClient;
2525
import java.util.concurrent.locks.Lock;
2626
import java.util.concurrent.locks.ReentrantLock;
2727
import java.util.function.Consumer;
2828

2929
final class CredentialsFactory {
3030

31-
private volatile Credentials globalOAuthCredentials;
32-
private final Lock oauthCredentialsLock = new ReentrantLock();
31+
private volatile Credentials globalOAuth2Credentials;
32+
private final Lock oauth2CredentialsLock = new ReentrantLock();
3333
private final AmqpEnvironment environment;
3434

3535
CredentialsFactory(AmqpEnvironment environment) {
@@ -39,11 +39,11 @@ final class CredentialsFactory {
3939
Credentials credentials(DefaultConnectionSettings<?> settings) {
4040
CredentialsProvider provider = settings.credentialsProvider();
4141
Credentials credentials;
42-
if (settings.oauth().enabled()) {
43-
if (settings.oauth().shared()) {
44-
credentials = globalOAuthCredentials(settings);
42+
if (settings.oauth2().enabled()) {
43+
if (settings.oauth2().shared()) {
44+
credentials = globalOAuth2Credentials(settings);
4545
} else {
46-
credentials = createOAuthCredentials(settings);
46+
credentials = createOAuth2Credentials(settings);
4747
}
4848
} else {
4949
if (provider instanceof UsernamePasswordCredentialsProvider) {
@@ -57,25 +57,25 @@ Credentials credentials(DefaultConnectionSettings<?> settings) {
5757
return credentials;
5858
}
5959

60-
private Credentials globalOAuthCredentials(DefaultConnectionSettings<?> connectionSettings) {
61-
Credentials result = this.globalOAuthCredentials;
60+
private Credentials globalOAuth2Credentials(DefaultConnectionSettings<?> connectionSettings) {
61+
Credentials result = this.globalOAuth2Credentials;
6262
if (result != null) {
6363
return result;
6464
}
6565

66-
this.oauthCredentialsLock.lock();
66+
this.oauth2CredentialsLock.lock();
6767
try {
68-
if (this.globalOAuthCredentials == null) {
69-
this.globalOAuthCredentials = createOAuthCredentials(connectionSettings);
68+
if (this.globalOAuth2Credentials == null) {
69+
this.globalOAuth2Credentials = createOAuth2Credentials(connectionSettings);
7070
}
71-
return this.globalOAuthCredentials;
71+
return this.globalOAuth2Credentials;
7272
} finally {
73-
this.oauthCredentialsLock.unlock();
73+
this.oauth2CredentialsLock.unlock();
7474
}
7575
}
7676

77-
private Credentials createOAuthCredentials(DefaultConnectionSettings<?> connectionSettings) {
78-
DefaultConnectionSettings.DefaultOAuthSettings<?> settings = connectionSettings.oauth();
77+
private Credentials createOAuth2Credentials(DefaultConnectionSettings<?> connectionSettings) {
78+
DefaultConnectionSettings.DefaultOAuth2Settings<?> settings = connectionSettings.oauth2();
7979
Consumer<HttpClient.Builder> clientBuilderConsumer;
8080
if (settings.tlsEnabled()) {
8181
clientBuilderConsumer = b -> b.sslContext(settings.tls().sslContext());

src/main/java/com/rabbitmq/client/amqp/impl/DefaultConnectionSettings.java

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ abstract class DefaultConnectionSettings<T> implements ConnectionSettings<T> {
7474
private String saslMechanism = ConnectionSettings.SASL_MECHANISM_ANONYMOUS;
7575
private final DefaultTlsSettings<T> tlsSettings = new DefaultTlsSettings<>(this);
7676
private final DefaultAffinity<T> affinity = new DefaultAffinity<>(this);
77-
private final DefaultOAuthSettings<T> oAuthSettings = new DefaultOAuthSettings<>(this);
77+
private final DefaultOAuth2Settings<T> oAuth2Settings = new DefaultOAuth2Settings<>(this);
7878

7979
@Override
8080
public T uri(String uriString) {
@@ -225,8 +225,8 @@ void copyTo(DefaultConnectionSettings<?> copy) {
225225

226226
this.affinity.copyTo(copy.affinity);
227227

228-
if (this.oAuthSettings.enabled()) {
229-
this.oAuthSettings.copyTo(copy.oauth());
228+
if (this.oAuth2Settings.enabled()) {
229+
this.oAuth2Settings.copyTo(copy.oauth2());
230230
}
231231
}
232232

@@ -301,8 +301,8 @@ public DefaultAffinity<? extends T> affinity() {
301301
}
302302

303303
@Override
304-
public DefaultOAuthSettings<? extends T> oauth() {
305-
return this.oAuthSettings;
304+
public DefaultOAuth2Settings<? extends T> oauth2() {
305+
return this.oAuth2Settings;
306306
}
307307

308308
static DefaultConnectionSettings<?> instance() {
@@ -501,7 +501,7 @@ void validate() {
501501
}
502502
}
503503

504-
static class DefaultOAuthSettings<T> implements OAuthSettings<T> {
504+
static class DefaultOAuth2Settings<T> implements OAuth2Settings<T> {
505505

506506
private final DefaultConnectionSettings<T> connectionSettings;
507507
private final DefaultOAuthTlsSettings<T> tls = new DefaultOAuthTlsSettings<>(this);
@@ -514,37 +514,37 @@ static class DefaultOAuthSettings<T> implements OAuthSettings<T> {
514514
private Function<Instant, Duration> refreshDelayStrategy =
515515
TokenCredentials.DEFAULT_REFRESH_DELAY_STRATEGY;
516516

517-
DefaultOAuthSettings(DefaultConnectionSettings<T> connectionSettings) {
517+
DefaultOAuth2Settings(DefaultConnectionSettings<T> connectionSettings) {
518518
this.connectionSettings = connectionSettings;
519519
}
520520

521521
@Override
522-
public OAuthSettings<T> tokenEndpointUri(String uri) {
522+
public OAuth2Settings<T> tokenEndpointUri(String uri) {
523523
this.connectionSettings.saslMechanism(SASL_MECHANISM_PLAIN);
524524
this.tokenEndpointUri = uri;
525525
return this;
526526
}
527527

528528
@Override
529-
public OAuthSettings<T> clientId(String clientId) {
529+
public OAuth2Settings<T> clientId(String clientId) {
530530
this.clientId = clientId;
531531
return this;
532532
}
533533

534534
@Override
535-
public OAuthSettings<T> clientSecret(String clientSecret) {
535+
public OAuth2Settings<T> clientSecret(String clientSecret) {
536536
this.clientSecret = clientSecret;
537537
return this;
538538
}
539539

540540
@Override
541-
public OAuthSettings<T> grantType(String grantType) {
541+
public OAuth2Settings<T> grantType(String grantType) {
542542
this.grantType = grantType;
543543
return this;
544544
}
545545

546546
@Override
547-
public OAuthSettings<T> parameter(String name, String value) {
547+
public OAuth2Settings<T> parameter(String name, String value) {
548548
if (value == null) {
549549
this.parameters.remove(name);
550550
} else {
@@ -554,12 +554,13 @@ public OAuthSettings<T> parameter(String name, String value) {
554554
}
555555

556556
@Override
557-
public OAuthSettings<T> shared(boolean shared) {
557+
public OAuth2Settings<T> shared(boolean shared) {
558558
this.shared = shared;
559559
return this;
560560
}
561561

562-
DefaultOAuthSettings<T> refreshDelayStrategy(Function<Instant, Duration> refreshDelayStrategy) {
562+
DefaultOAuth2Settings<T> refreshDelayStrategy(
563+
Function<Instant, Duration> refreshDelayStrategy) {
563564
this.refreshDelayStrategy = refreshDelayStrategy;
564565
return this;
565566
}
@@ -579,7 +580,7 @@ public T connection() {
579580
return this.connectionSettings.toReturn();
580581
}
581582

582-
void copyTo(DefaultOAuthSettings<?> copy) {
583+
void copyTo(DefaultOAuth2Settings<?> copy) {
583584
copy.tokenEndpointUri(this.tokenEndpointUri);
584585
copy.clientId(this.clientId);
585586
copy.clientSecret(this.clientSecret);
@@ -625,25 +626,25 @@ boolean tlsEnabled() {
625626
}
626627
}
627628

628-
static class DefaultOAuthTlsSettings<T> implements OAuthSettings.TlsSettings<T> {
629+
static class DefaultOAuthTlsSettings<T> implements OAuth2Settings.TlsSettings<T> {
629630

630-
private final OAuthSettings<T> oAuthSettings;
631+
private final OAuth2Settings<T> oAuth2Settings;
631632
private SSLContext sslContext;
632633
private boolean enabled = false;
633634

634-
DefaultOAuthTlsSettings(OAuthSettings<T> oAuthSettings) {
635-
this.oAuthSettings = oAuthSettings;
635+
DefaultOAuthTlsSettings(OAuth2Settings<T> oAuth2Settings) {
636+
this.oAuth2Settings = oAuth2Settings;
636637
}
637638

638639
@Override
639-
public OAuthSettings.TlsSettings<T> sslContext(SSLContext sslContext) {
640+
public OAuth2Settings.TlsSettings<T> sslContext(SSLContext sslContext) {
640641
this.sslContext = sslContext;
641642
return this;
642643
}
643644

644645
@Override
645-
public OAuthSettings<T> oauth() {
646-
return this.oAuthSettings;
646+
public OAuth2Settings<T> oauth2() {
647+
return this.oAuth2Settings;
647648
}
648649

649650
void enable() {

src/main/java/com/rabbitmq/client/amqp/impl/TokenCredentials.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
1818
package com.rabbitmq.client.amqp.impl;
1919

20-
import com.rabbitmq.client.amqp.oauth.Token;
21-
import com.rabbitmq.client.amqp.oauth.TokenRequester;
20+
import com.rabbitmq.client.amqp.oauth2.Token;
21+
import com.rabbitmq.client.amqp.oauth2.TokenRequester;
2222
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2323
import java.time.Duration;
2424
import java.time.Instant;

src/main/java/com/rabbitmq/client/amqp/oauth/GsonTokenParser.java renamed to src/main/java/com/rabbitmq/client/amqp/oauth2/GsonTokenParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//
1616
// If you have any questions regarding licensing, please contact us at
1717
18-
package com.rabbitmq.client.amqp.oauth;
18+
package com.rabbitmq.client.amqp.oauth2;
1919

2020
import com.google.gson.Gson;
2121
import com.google.gson.reflect.TypeToken;

src/main/java/com/rabbitmq/client/amqp/oauth/HttpTokenRequester.java renamed to src/main/java/com/rabbitmq/client/amqp/oauth2/HttpTokenRequester.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//
1616
// If you have any questions regarding licensing, please contact us at
1717
18-
package com.rabbitmq.client.amqp.oauth;
18+
package com.rabbitmq.client.amqp.oauth2;
1919

2020
import static java.nio.charset.StandardCharsets.UTF_8;
2121

@@ -46,7 +46,7 @@ public final class HttpTokenRequester implements TokenRequester {
4646
private final HttpClient client;
4747
private final Consumer<HttpRequest.Builder> requestBuilderConsumer;
4848

49-
private TokenParser parser;
49+
private final TokenParser parser;
5050

5151
public HttpTokenRequester(
5252
String tokenEndpointUri,
@@ -114,10 +114,10 @@ public Token request() {
114114
checkContentType(response.headers().firstValue("content-type").orElse(null));
115115
return this.parser.parse(response.body());
116116
} catch (IOException e) {
117-
throw new OAuthException("Error while retrieving OAuth 2 token", e);
117+
throw new OAuth2Exception("Error while retrieving OAuth 2 token", e);
118118
} catch (InterruptedException e) {
119119
Thread.currentThread().interrupt();
120-
throw new OAuthException("Error while retrieving OAuth 2 token", e);
120+
throw new OAuth2Exception("Error while retrieving OAuth 2 token", e);
121121
}
122122
}
123123

@@ -144,13 +144,13 @@ private static String encode(String value) {
144144

145145
private static void checkContentType(String contentType) {
146146
if (contentType == null || !contentType.toLowerCase().contains("json")) {
147-
throw new OAuthException("HTTP request for token retrieval is not JSON: " + contentType);
147+
throw new OAuth2Exception("HTTP request for token retrieval is not JSON: " + contentType);
148148
}
149149
}
150150

151151
private static void checkStatusCode(int statusCode) {
152152
if (statusCode != 200) {
153-
throw new OAuthException(
153+
throw new OAuth2Exception(
154154
"HTTP request for token retrieval did not " + "return 200 status code: " + statusCode);
155155
}
156156
}

0 commit comments

Comments
 (0)