Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: throw an exception if reference in uaa.yml is missing #2952

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ private static Matcher getDynamicValueMatcher(String value) {
}

private static String getDynamicValue(Matcher m) {
ApplicationContext applicationContext = ApplicationContextProvider.getApplicationContext();
/* return a reference from application environment only if in default zone */
if (!(new IdentityZoneManagerImpl().isCurrentZoneUaa())) {
if (applicationContext == null || !(new IdentityZoneManagerImpl().isCurrentZoneUaa())) {
return null;
}
ApplicationContext applicationContext = ApplicationContextProvider.getApplicationContext();
return applicationContext != null ? applicationContext.getEnvironment().getProperty(m.group("name")) : null;
return Optional.ofNullable(applicationContext.getEnvironment().getProperty(m.group("name"))).orElseThrow( () -> new BadCredentialsException("Missing referenced signing entry"));
}

private static String getDefaultValue(Matcher m) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void testGetClientAssertionUnknownSingingKey() throws ParseException {
}

@Test
void testGetClientAssertionUsingCustomSingingKeyFromEnivoronment() throws ParseException, JOSEException {
void testGetClientAssertionUsingCustomSingingKeyFromEnvironment() throws ParseException, JOSEException {
// Given: register 2 keys
mockKeyInfoService("key-id-321", JwtHelperX5tTest.CERTIFICATE_1);
HashMap customClaims = new HashMap<>();
Expand All @@ -201,7 +201,7 @@ void testGetClientAssertionUsingCustomSingingKeyFromEnivoronment() throws ParseE
}

@Test
void testGetClientAssertionUsingCustomSingingKeyFromEnivoronmentNoDefault() throws ParseException, JOSEException {
void testGetClientAssertionUsingCustomSingingKeyFromEnvironmentNoDefault() throws ParseException, JOSEException {
// Given: register 2 keys
mockKeyInfoService("key-id-321", JwtHelperX5tTest.CERTIFICATE_1);
HashMap customClaims = new HashMap<>();
Expand All @@ -222,7 +222,7 @@ void testGetClientAssertionUsingCustomSingingKeyFromEnivoronmentNoDefault() thro
}

@Test
void testGetClientAssertionUsingCustomSingingKeyFromEnivoronmentUseDefault() throws ParseException, JOSEException {
void testGetClientAssertionUsingCustomSingingKeyFromEnvironmentButEntryIsMissing() throws ParseException, JOSEException {
// Given: register 2 keys
mockKeyInfoService("key-id-321", JwtHelperX5tTest.CERTIFICATE_1);
HashMap customClaims = new HashMap<>();
Expand All @@ -231,20 +231,14 @@ void testGetClientAssertionUsingCustomSingingKeyFromEnivoronmentUseDefault() thr
config.setJwtClientAuthentication(customClaims);
// empty application context
mockApplicationContext(Map.of());
// When
MultiValueMap<String, String> params = jwtClientAuthentication.getClientAuthenticationParameters(new LinkedMultiValueMap<>(), config);
// Then
assertTrue(params.containsKey("client_assertion"));
assertTrue(params.containsKey("client_assertion_type"));
String clientAssertion = (String) params.get("client_assertion").get(0);
validateClientAssertionOidcComplaint(clientAssertion);
JWSHeader header = getJwtHeader(clientAssertion);
assertEquals(KEY_ID, header.getKeyID());
assertNull(header.getJWKURL());
Exception exception = assertThrows(BadCredentialsException.class, () ->
jwtClientAuthentication.getClientAuthenticationParameters(new LinkedMultiValueMap<>(), config));
assertEquals("Missing referenced signing entry", exception.getMessage());
}

@Test
void testGetClientAssertionUsingCustomSingingKeyFromEnivoronmentButNotInDefaultZone() throws JOSEException {
void testGetClientAssertionUsingCustomSingingKeyFromEnvironmentButNotInDefaultZone() throws JOSEException {
// Given: register 2 keys
mockKeyInfoService("key-id-321", JwtHelperX5tTest.CERTIFICATE_1);
HashMap customClaims = new HashMap<>();
Expand Down Expand Up @@ -285,7 +279,7 @@ void testGetClientAssertionCustomSingingKeyButNoCertificate() throws ParseExcept
}

@Test
void testGetClientAssertionUsingCustomSingingPrivateKeyFromEnivoronment() throws ParseException, JOSEException {
void testGetClientAssertionUsingCustomSingingPrivateKeyFromEnvironment() throws ParseException, JOSEException {
// Given: register 2 keys
mockKeyInfoService("key-id-321", JwtHelperX5tTest.CERTIFICATE_1);
// add reference in jwtClientAuthentication to customer one key-id-321
Expand Down
Loading