Skip to content

Commit c5d989a

Browse files
committed
update SP Audience DCR
1 parent 4387c65 commit c5d989a

File tree

2 files changed

+19
-13
lines changed
  • components/org.wso2.carbon.identity.oauth.dcr/src

2 files changed

+19
-13
lines changed

components/org.wso2.carbon.identity.oauth.dcr/src/main/java/org/wso2/carbon/identity/oauth/dcr/service/DCRMService.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,24 @@ public Application updateApplication(ApplicationUpdateRequest updateRequest, Str
310310
sp.setJwksUri(updateRequest.getJwksURI());
311311
}
312312
// Todo: validate version input. Create a function at app mgt.
313-
sp.setApplicationVersion(applicationVersion);
314-
// Need to create a deep clone, since modifying the fields of the original object,
315-
// will modify the cached SP object.
316-
ServiceProvider clonedSP = cloneServiceProvider(sp);
313+
if (StringUtils.isNotBlank(applicationVersion)) {
314+
sp.setApplicationVersion(applicationVersion);
315+
}
316+
}
317+
if (StringUtils.isNotEmpty(updateRequest.getExtAllowedAudience()) &&
318+
(updateRequest.getExtAllowedAudience().equalsIgnoreCase(ORG_ROLE_AUDIENCE)
319+
|| updateRequest.getExtAllowedAudience().equalsIgnoreCase(APP_ROLE_AUDIENCE))) {
320+
AssociatedRolesConfig associatedRolesConfig = new AssociatedRolesConfig();
321+
associatedRolesConfig.setAllowedAudience(updateRequest.getExtAllowedAudience().toLowerCase());
322+
sp.setAssociatedRolesConfig(associatedRolesConfig);
323+
}
324+
// Need to create a deep clone, since modifying the fields of the original object,
325+
// will modify the cached SP object.
326+
ServiceProvider clonedSP = cloneServiceProvider(sp);
327+
if (StringUtils.isNotEmpty(clientName)) {
317328
clonedSP.setApplicationName(clientName);
318-
updateServiceProvider(clonedSP, tenantDomain, applicationOwner);
319329
}
330+
updateServiceProvider(clonedSP, tenantDomain, applicationOwner);
320331

321332
// Update application
322333
try {
@@ -413,14 +424,6 @@ public Application updateApplication(ApplicationUpdateRequest updateRequest, Str
413424
appDTO.setPkceSupportPlain(updateRequest.isExtPkceSupportPlain());
414425
appDTO.setBypassClientCredentials(updateRequest.isExtPublicClient());
415426
oAuthAdminService.updateConsumerApplication(appDTO);
416-
417-
if (StringUtils.isNotEmpty(updateRequest.getExtAllowedAudience()) &&
418-
(updateRequest.getExtAllowedAudience().equalsIgnoreCase(ORG_ROLE_AUDIENCE)
419-
|| updateRequest.getExtAllowedAudience().equalsIgnoreCase(APP_ROLE_AUDIENCE))) {
420-
AssociatedRolesConfig associatedRolesConfig = new AssociatedRolesConfig();
421-
associatedRolesConfig.setAllowedAudience(updateRequest.getExtAllowedAudience().toLowerCase());
422-
sp.setAssociatedRolesConfig(associatedRolesConfig);
423-
}
424427
} catch (IdentityOAuthClientException e) {
425428
throw new DCRMClientException(DCRMConstants.ErrorCodes.INVALID_CLIENT_METADATA, e.getMessage(), e);
426429
} catch (IdentityOAuthAdminException e) {

components/org.wso2.carbon.identity.oauth.dcr/src/test/java/org/wso2/carbon/identity/oauth/dcr/service/DCRMServiceTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public class DCRMServiceTest {
108108
private String dummyCallbackUrl = "dummyCallbackUrl";
109109
private final String dummyTemplateName = "dummyTemplateName";
110110
private final String dummyBackchannelLogoutUri = "http://backchannel.com/";
111+
private static final String ORG_ROLE_AUDIENCE = "organization";
111112

112113
@Mock
113114
private OAuthConsumerAppDTO dto;
@@ -1007,6 +1008,8 @@ public void updateApplicationTest(List<String> redirectUri1, String roleAudience
10071008
assertEquals(application.getClientId(), dummyConsumerKey);
10081009
assertEquals(application.getClientName(), dummyClientName);
10091010
assertEquals(application.getClientSecret(), dummyConsumerSecret);
1011+
assertEquals(application.getExtAllowedAudience(), ORG_ROLE_AUDIENCE);
1012+
assertEquals(application.getExtAllowedAudience(), roleAudience);
10101013
}
10111014

10121015
@Test

0 commit comments

Comments
 (0)