use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO in project carbon-identity-framework by wso2.
the class DefaultApplicationValidator method validateInboundAuthKey.
/**
* Validate whether the configured inbound authentication key is already being used by another application.
*
* @param inboundConfig Inbound authentication request configuration.
* @param appId Application ID.
* @param tenantDomain Application tenant domain.
* @throws IdentityApplicationManagementException IdentityApplicationManagementException.
*/
private void validateInboundAuthKey(InboundAuthenticationRequestConfig inboundConfig, int appId, String tenantDomain) throws IdentityApplicationManagementException {
if (inboundConfig == null) {
return;
}
/*
* We need to directly retrieve the application from DB since {@link ServiceProviderByInboundAuthCache} cache
* can have inconsistent applications stored against the <inbound-auth-key, inbound-auth-type, tenant-domain>
* cache key which is not unique.
*/
ApplicationDAO applicationDAO = new ApplicationDAOImpl();
String existingAppName = applicationDAO.getServiceProviderNameByClientId(inboundConfig.getInboundAuthKey(), inboundConfig.getInboundAuthType(), CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
if (StringUtils.isBlank(existingAppName)) {
if (log.isDebugEnabled()) {
log.debug("Cannot find application name for the inbound auth key: " + inboundConfig.getInboundAuthKey() + " of inbound auth type: " + inboundConfig.getInboundAuthType());
}
return;
}
ServiceProvider existingApp = applicationDAO.getApplication(existingAppName, tenantDomain);
if (existingApp != null && existingApp.getApplicationID() != appId) {
String msg = "Inbound key: '" + inboundConfig.getInboundAuthKey() + "' of inbound auth type: '" + inboundConfig.getInboundAuthType() + "' is already configured for the application :'" + existingApp.getApplicationName() + "'";
/*
* Since this is a conflict scenario, we need to use a different error code. Hence throwing an
* 'IdentityApplicationManagementClientException' here with the correct error code.
*/
throw buildClientException(IdentityApplicationConstants.Error.INBOUND_KEY_ALREADY_EXISTS, msg);
}
}
Aggregations