Skip to content

Commit 78bb112

Browse files
committed
Move jwksUrl and issuer in the init section instead of login
1 parent 9cf2d06 commit 78bb112

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

activemq-jaas/src/main/java/org/apache/activemq/jaas/OAuth2LoginModule.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,15 @@ public void initialize(Subject subject, CallbackHandler callbackHandler, Map<Str
118118
this.debug = Boolean.parseBoolean((String) options.get("debug"));
119119

120120
this.jwksUrl = (String) options.get(JWKS_URL_OPTION);
121+
if (jwksUrl == null || jwksUrl.isEmpty()) {
122+
throw new IllegalArgumentException("OAuth2 JWKS URL (" + JWKS_URL_OPTION + ") is required");
123+
}
124+
121125
this.issuer = (String) options.get(ISSUER_OPTION);
126+
if (issuer == null || issuer.isEmpty()) {
127+
throw new IllegalArgumentException("OAuth2 issuer (" + ISSUER_OPTION + ") is required");
128+
}
129+
122130
this.audience = (String) options.get(AUDIENCE_OPTION);
123131

124132
String userClaim = (String) options.get(USERNAME_CLAIM_OPTION);
@@ -135,13 +143,6 @@ public void initialize(Subject subject, CallbackHandler callbackHandler, Map<Str
135143

136144
@Override
137145
public boolean login() throws LoginException {
138-
if (jwksUrl == null || jwksUrl.isEmpty()) {
139-
throw new LoginException("OAuth2 JWKS URL (oauth2.jwksUrl) is required");
140-
}
141-
if (issuer == null || issuer.isEmpty()) {
142-
throw new LoginException("OAuth2 issuer (oauth2.issuer) is required");
143-
}
144-
145146
String token = getToken();
146147
if (token == null || token.isEmpty()) {
147148
throw new FailedLoginException("No JWT token provided");

activemq-jaas/src/test/java/org/apache/activemq/jaas/OAuth2LoginModuleTest.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,10 @@ public void testMissingJwksUrl() throws Exception {
307307

308308
Subject subject = new Subject();
309309
OAuth2LoginModule module = new OAuth2LoginModule();
310-
module.initialize(subject, new TokenCallbackHandler("token"), new HashMap<>(), options);
311-
312310
try {
313-
module.login();
314-
fail("Should have thrown LoginException for missing JWKS URL");
315-
} catch (LoginException e) {
311+
module.initialize(subject, new TokenCallbackHandler("token"), new HashMap<>(), options);
312+
fail("Should have thrown IllegalArgumentException for missing JWKS URL");
313+
} catch (IllegalArgumentException e) {
316314
assertTrue("Error should mention JWKS URL", e.getMessage().contains("JWKS URL"));
317315
}
318316
}
@@ -323,12 +321,10 @@ public void testMissingIssuer() throws Exception {
323321

324322
Subject subject = new Subject();
325323
OAuth2LoginModule module = new OAuth2LoginModule();
326-
module.initialize(subject, new TokenCallbackHandler("token"), new HashMap<>(), options);
327-
328324
try {
329-
module.login();
330-
fail("Should have thrown LoginException for missing issuer");
331-
} catch (LoginException e) {
325+
module.initialize(subject, new TokenCallbackHandler("token"), new HashMap<>(), options);
326+
fail("Should have thrown IllegalArgumentException for missing issuer");
327+
} catch (IllegalArgumentException e) {
332328
assertTrue("Error should mention issuer", e.getMessage().contains("issuer"));
333329
}
334330
}

0 commit comments

Comments
 (0)