Skip to content

Commit ade1f30

Browse files
Improve application access validation in client authentication
1 parent 0f245af commit ade1f30

File tree

2 files changed

+31
-0
lines changed
  • components/org.wso2.carbon.identity.oauth/src

2 files changed

+31
-0
lines changed

components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/util/OAuth2Util.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,9 @@ public static boolean authenticateClient(String clientId, String clientSecretPro
615615
public static boolean authenticateClient(String clientId, String clientSecretProvided, String appTenant)
616616
throws IdentityOAuthAdminException, IdentityOAuth2Exception, InvalidOAuthClientException {
617617

618+
if (!isApplicationAccessible(clientId, appTenant)) {
619+
throw new InvalidOAuthClientException("Application is disabled for the client_id: " + clientId);
620+
}
618621
OAuthAppDO appDO = OAuth2Util.getAppInformationByClientId(clientId, appTenant);
619622
if (appDO == null) {
620623
if (log.isDebugEnabled()) {
@@ -660,6 +663,30 @@ public static boolean authenticateClient(String clientId, String clientSecretPro
660663
return true;
661664
}
662665

666+
private static boolean isApplicationAccessible(String clientId, String appTenant)
667+
throws IdentityOAuth2Exception {
668+
669+
ServiceProvider serviceProvider = OAuth2Util.getServiceProvider(clientId, appTenant);
670+
DiagnosticLog.DiagnosticLogBuilder diagnosticLogBuilder = null;
671+
if (LoggerUtils.isDiagnosticLogsEnabled()) {
672+
diagnosticLogBuilder = new DiagnosticLog.DiagnosticLogBuilder(
673+
OAuthConstants.LogConstants.OAUTH_INBOUND_SERVICE,
674+
OAuthConstants.LogConstants.ActionIDs.VALIDATE_APPLICATION_ENABLED_STATUS);
675+
diagnosticLogBuilder.inputParam(LogConstants.InputKeys.CLIENT_ID, clientId)
676+
.logDetailLevel(DiagnosticLog.LogDetailLevel.APPLICATION);
677+
}
678+
if (!serviceProvider.isApplicationEnabled()) {
679+
if (diagnosticLogBuilder != null) {
680+
diagnosticLogBuilder
681+
.resultMessage("Application is disabled.")
682+
.resultStatus(DiagnosticLog.ResultStatus.FAILED);
683+
LoggerUtils.triggerDiagnosticLogEvent(diagnosticLogBuilder);
684+
}
685+
return false;
686+
}
687+
return true;
688+
}
689+
663690
private static boolean isTenantActive(String tenantDomain) throws IdentityOAuth2Exception {
664691
try {
665692
TenantManager tenantManager = OAuthComponentServiceHolder.getInstance()

components/org.wso2.carbon.identity.oauth/src/test/java/org/wso2/carbon/identity/oauth2/util/OAuth2UtilTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,10 @@ public void testAuthenticateClientWithAppTenant() throws Exception {
581581
(mock, context) -> {
582582
when(mock.getAppInformation(eq(clientId), anyInt())).thenReturn(appDO);
583583
})) {
584+
ApplicationManagementService applicationManagementService = mock(ApplicationManagementService.class);
585+
OAuth2ServiceComponentHolder.setApplicationMgtService(applicationManagementService);
586+
when(applicationManagementService.getServiceProviderByClientId(anyString(), anyString(), anyString()))
587+
.thenReturn(new ServiceProvider());
584588
identityTenantUtil.when(() -> IdentityTenantUtil.getTenantId(clientTenantDomain))
585589
.thenReturn(clientTenantId);
586590

0 commit comments

Comments
 (0)