Skip to content

Commit

Permalink
Merge pull request #2669 from Thumimku/updateSPAudienceInDCR
Browse files Browse the repository at this point in the history
Fix DCR PUT request not updating application role audience
  • Loading branch information
Thumimku authored Jan 9, 2025
2 parents 5c971ae + 4a0382c commit 7e302b5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,24 @@ public Application updateApplication(ApplicationUpdateRequest updateRequest, Str
sp.setJwksUri(updateRequest.getJwksURI());
}
// Todo: validate version input. Create a function at app mgt.
sp.setApplicationVersion(applicationVersion);
// Need to create a deep clone, since modifying the fields of the original object,
// will modify the cached SP object.
ServiceProvider clonedSP = cloneServiceProvider(sp);
if (StringUtils.isNotBlank(applicationVersion)) {
sp.setApplicationVersion(applicationVersion);
}
}
if (StringUtils.isNotEmpty(updateRequest.getExtAllowedAudience()) &&
(updateRequest.getExtAllowedAudience().equalsIgnoreCase(ORG_ROLE_AUDIENCE)
|| updateRequest.getExtAllowedAudience().equalsIgnoreCase(APP_ROLE_AUDIENCE))) {
AssociatedRolesConfig associatedRolesConfig = new AssociatedRolesConfig();
associatedRolesConfig.setAllowedAudience(updateRequest.getExtAllowedAudience().toLowerCase());
sp.setAssociatedRolesConfig(associatedRolesConfig);
}
// Need to create a deep clone, since modifying the fields of the original object,
// will modify the cached SP object.
ServiceProvider clonedSP = cloneServiceProvider(sp);
if (StringUtils.isNotEmpty(clientName)) {
clonedSP.setApplicationName(clientName);
updateServiceProvider(clonedSP, tenantDomain, applicationOwner);
}
updateServiceProvider(clonedSP, tenantDomain, applicationOwner);

// Update application
try {
Expand Down Expand Up @@ -413,14 +424,6 @@ public Application updateApplication(ApplicationUpdateRequest updateRequest, Str
appDTO.setPkceSupportPlain(updateRequest.isExtPkceSupportPlain());
appDTO.setBypassClientCredentials(updateRequest.isExtPublicClient());
oAuthAdminService.updateConsumerApplication(appDTO);

if (StringUtils.isNotEmpty(updateRequest.getExtAllowedAudience()) &&
(updateRequest.getExtAllowedAudience().equalsIgnoreCase(ORG_ROLE_AUDIENCE)
|| updateRequest.getExtAllowedAudience().equalsIgnoreCase(APP_ROLE_AUDIENCE))) {
AssociatedRolesConfig associatedRolesConfig = new AssociatedRolesConfig();
associatedRolesConfig.setAllowedAudience(updateRequest.getExtAllowedAudience().toLowerCase());
sp.setAssociatedRolesConfig(associatedRolesConfig);
}
} catch (IdentityOAuthClientException e) {
throw new DCRMClientException(DCRMConstants.ErrorCodes.INVALID_CLIENT_METADATA, e.getMessage(), e);
} catch (IdentityOAuthAdminException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public class DCRMServiceTest {
private String dummyCallbackUrl = "dummyCallbackUrl";
private final String dummyTemplateName = "dummyTemplateName";
private final String dummyBackchannelLogoutUri = "http://backchannel.com/";
private static final String ORG_ROLE_AUDIENCE = "organization";

@Mock
private OAuthConsumerAppDTO dto;
Expand Down Expand Up @@ -1007,6 +1008,7 @@ public void updateApplicationTest(List<String> redirectUri1, String roleAudience
assertEquals(application.getClientId(), dummyConsumerKey);
assertEquals(application.getClientName(), dummyClientName);
assertEquals(application.getClientSecret(), dummyConsumerSecret);
assertEquals(application.getExtAllowedAudience(), roleAudience);
}

@Test
Expand Down

0 comments on commit 7e302b5

Please sign in to comment.