Skip to content

Commit 91aa36c

Browse files
authored
Issue 31716 no class def found error for com.nimbusds.jose.shaded.json.json array (Azure#31743)
1 parent 0c54646 commit 91aa36c

File tree

3 files changed

+47
-21
lines changed

3 files changed

+47
-21
lines changed

sdk/spring/CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
## 4.5.0-beta.2 (Unreleased)
44
Upgrade Spring Boot dependencies version to 2.7.4 and Spring Cloud dependencies version to 2021.0.4
55

6+
### Spring Cloud Azure Autoconfigure
7+
This section includes changes in `spring-cloud-azure-autoconfigure` module.
8+
69
#### Bugs Fixed
710
- Fix bug: Put a value into Collections.emptyMap(). [#31190](https://github.com/Azure/azure-sdk-for-java/issues/31190).
811
- Fix bug: RestTemplate used to get access token should only contain 2 converters. [#31482](https://github.com/Azure/azure-sdk-for-java/issues/31482).
912
- Fix bug: RestOperations is not well configured when jwkResolver is null. [#31218](https://github.com/Azure/azure-sdk-for-java/issues/31218).
1013
- Fix bug: Duplicated "scope" parameter. [#31191](https://github.com/Azure/azure-sdk-for-java/issues/31191).
1114
- Fix bug: NimbusJwtDecoder still uses `RestTemplate()` instead `RestTemplateBuilder` [#31233](https://github.com/Azure/azure-sdk-for-java/issues/31233)
12-
- Fix bug: Proxy setting not work in Azure AD B2C web application [31593](https://github.com/Azure/azure-sdk-for-java/issues/31593)
15+
- Fix bug: Proxy setting not work in Azure AD B2C web application. [31593](https://github.com/Azure/azure-sdk-for-java/issues/31593)
16+
- Fix Bug: NoClassDefFoundError for JSONArray. [31716](https://github.com/Azure/azure-sdk-for-java/issues/31716)
1317

1418
## 4.4.0 (2022-09-26)
1519
Upgrade Spring Boot dependencies version to 2.7.3 and Spring Cloud dependencies version to 2021.0.3
@@ -477,7 +481,7 @@ This section includes changes in the `spring-cloud-azure-autoconfigure` module.
477481
* Property name "spring.cloud.azure.active-directory.graph-base-uri" changed to "spring.cloud.azure.active-directory.profile.environment.microsoft-graph-endpoint".
478482
* Property name "spring.cloud.azure.active-directory.graph-membership-uri" changed to "spring.cloud.azure.active-directory.profile.environment.microsoft-graph-endpoint" and "spring.cloud.azure.active-directory.user-group.use-transitive-members".
479483
- Change AAD B2C configuration properties to use the namespace for credential and environment properties [#25799](https://github.com/Azure/azure-sdk-for-java/pull/25799).
480-
- Change Event Hubs processor configuration properties `spring.cloud.azure.eventhbs.processor.partition-ownership-expiration-interval` to `spring.cloud.azure.eventhbs.processor.load-balancing.partition-ownership-expiration-interval` [#25851](https://github.com/Azure/azure-sdk-for-java/pull/25851).
484+
- Change Event Hubs processor configuration properties `spring.cloud.azure.eventhubs.processor.partition-ownership-expiration-interval` to `spring.cloud.azure.eventhubs.processor.load-balancing.partition-ownership-expiration-interval` [#25851](https://github.com/Azure/azure-sdk-for-java/pull/25851).
481485
- Change Event Hubs configuration properties `spring.cloud.azure.eventhubs.fqdn` to `spring.cloud.azure.eventhubs.fully-qualified-namespace` [#25851](https://github.com/Azure/azure-sdk-for-java/pull/25851).
482486
- Rename all `*CP` classes to `*ConfigurationProperties` [#26209](https://github.com/Azure/azure-sdk-for-java/pull/26209).
483487

sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/aad/filter/UserPrincipalManager.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import com.nimbusds.jose.proc.JWSKeySelector;
1717
import com.nimbusds.jose.proc.JWSVerificationKeySelector;
1818
import com.nimbusds.jose.proc.SecurityContext;
19-
import com.nimbusds.jose.shaded.json.JSONArray;
2019
import com.nimbusds.jose.util.ResourceRetriever;
2120
import com.nimbusds.jwt.JWT;
2221
import com.nimbusds.jwt.JWTClaimsSet;
@@ -149,17 +148,20 @@ public UserPrincipal buildUserPrincipal(String aadIssuedBearerToken) throws Pars
149148
final JWTClaimsSet jwtClaimsSet = validator.process(aadIssuedBearerToken, null);
150149
validator.getJWTClaimsSetVerifier().verify(jwtClaimsSet, null);
151150
UserPrincipal userPrincipal = new UserPrincipal(aadIssuedBearerToken, jwsObject, jwtClaimsSet);
152-
Set<String> roles = Optional.of(userPrincipal)
153-
.map(p -> p.getClaim(AadJwtClaimNames.ROLES))
154-
.map(JSONArray.class::cast)
155-
.map(Collection<Object>::stream)
156-
.orElseGet(Stream::empty)
157-
.map(Object::toString)
158-
.collect(Collectors.toSet());
159-
userPrincipal.setRoles(roles);
151+
userPrincipal.setRoles(getRoles(jwtClaimsSet));
160152
return userPrincipal;
161153
}
162154

155+
Set<String> getRoles(JWTClaimsSet set) {
156+
return Optional.of(set)
157+
.map(p -> p.getClaim(AadJwtClaimNames.ROLES))
158+
.map(Collection.class::cast)
159+
.map(Collection<Object>::stream)
160+
.orElseGet(Stream::empty)
161+
.map(Object::toString)
162+
.collect(Collectors.toSet());
163+
}
164+
163165
/**
164166
* Whether the token was issued by AAD.
165167
*

sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/aad/filter/UserPrincipalManagerTests.java

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.nimbusds.jose.jwk.JWKSet;
88
import com.nimbusds.jose.jwk.source.ImmutableJWKSet;
99
import com.nimbusds.jose.proc.SecurityContext;
10+
import com.nimbusds.jwt.JWTClaimsSet;
1011
import com.nimbusds.jwt.proc.BadJWTException;
1112
import org.junit.jupiter.api.BeforeAll;
1213
import org.junit.jupiter.api.Test;
@@ -19,10 +20,14 @@
1920
import java.nio.file.Paths;
2021
import java.security.cert.CertificateFactory;
2122
import java.security.cert.X509Certificate;
23+
import java.util.Arrays;
24+
import java.util.Set;
2225
import java.util.stream.Stream;
2326

2427
import static org.assertj.core.api.Assertions.assertThat;
2528
import static org.assertj.core.api.Assertions.assertThatCode;
29+
import static org.junit.jupiter.api.Assertions.assertEquals;
30+
import static org.junit.jupiter.api.Assertions.assertTrue;
2631

2732

2833
class UserPrincipalManagerTests {
@@ -33,8 +38,7 @@ class UserPrincipalManagerTests {
3338
static void setupClass() throws Exception {
3439
final X509Certificate cert = (X509Certificate) CertificateFactory.getInstance("X.509")
3540
.generateCertificate(Files.newInputStream(Paths.get("src/test/resources/aad/test-public-key.txt")));
36-
immutableJWKSet = new ImmutableJWKSet<>(new JWKSet(JWK.parse(
37-
cert)));
41+
immutableJWKSet = new ImmutableJWKSet<>(new JWKSet(JWK.parse(cert)));
3842
}
3943

4044
private UserPrincipalManager userPrincipalManager;
@@ -44,8 +48,7 @@ static void setupClass() throws Exception {
4448
void testAlgIsTakenFromJWT() throws Exception {
4549
userPrincipalManager = new UserPrincipalManager(immutableJWKSet);
4650
final UserPrincipal userPrincipal = userPrincipalManager.buildUserPrincipal(
47-
new String(Files.readAllBytes(
48-
Paths.get("src/test/resources/aad/jwt-signed.txt")), StandardCharsets.UTF_8));
51+
readFileToString("src/test/resources/aad/jwt-signed.txt"));
4952
assertThat(userPrincipal).isNotNull().extracting(UserPrincipal::getIssuer, UserPrincipal::getSubject)
5053
.containsExactly("https://sts.windows.net/test", "test@example.com");
5154
}
@@ -73,14 +76,31 @@ void nullIssuer() {
7376
.isInstanceOf(BadJWTException.class);
7477
}
7578

76-
private String readJwtValidIssuerTxt() throws IOException {
77-
return new String(Files.readAllBytes(
78-
Paths.get("src/test/resources/aad/jwt-null-issuer.txt")), StandardCharsets.UTF_8);
79+
@Test
80+
void testRolesExtracted() {
81+
JWTClaimsSet set = new JWTClaimsSet.Builder()
82+
.claim("roles", Arrays.asList("role1", "role2"))
83+
.build();
84+
Set<String> result = new UserPrincipalManager(null).getRoles(set);
85+
assertEquals(2, result.size());
86+
assertTrue(result.contains("role1"));
87+
assertTrue(result.contains("role2"));
88+
}
89+
90+
private String readJwtValidIssuerTxt() {
91+
return readFileToString("src/test/resources/aad/jwt-null-issuer.txt");
92+
}
93+
94+
private static Stream<String> readJwtValidIssuerTxtStream() {
95+
return Stream.of(readFileToString("src/test/resources/aad/jwt-valid-issuer.txt"));
7996
}
8097

81-
private static Stream<String> readJwtValidIssuerTxtStream() throws IOException {
82-
return Stream.of(new String(Files.readAllBytes(
83-
Paths.get("src/test/resources/aad/jwt-valid-issuer.txt")), StandardCharsets.UTF_8));
98+
private static String readFileToString(String path) {
99+
try {
100+
return new String(Files.readAllBytes(Paths.get(path)), StandardCharsets.UTF_8);
101+
} catch (IOException e) {
102+
throw new IllegalStateException(e);
103+
}
84104
}
85105

86106
}

0 commit comments

Comments
 (0)