/** * Get OAuth application data by the consumer key. * * @param consumerKey Consumer Key * @return <code>OAuthConsumerAppDTO</code> with application information * @throws IdentityOAuthAdminException Error when reading application information from persistence store. */ public OAuthConsumerAppDTO getOAuthApplicationData(String consumerKey) throws IdentityOAuthAdminException { OAuthConsumerAppDTO dto; OAuthAppDAO dao = new OAuthAppDAO(); try { OAuthAppDO app = dao.getAppInformation(consumerKey); if (app != null) { dto = buildConsumerAppDTO(app); if (log.isDebugEnabled()) { log.debug("Found App :" + dto.getApplicationName() + " for consumerKey: " + consumerKey); } } else { dto = new OAuthConsumerAppDTO(); } return dto; } catch (InvalidOAuthClientException | IdentityOAuth2Exception e) { throw handleError("Error while retrieving the app information using consumerKey: " + consumerKey, e); } }
private Application buildResponse(OAuthConsumerAppDTO createdApp) { Application application = new Application(); application.setClient_name(createdApp.getApplicationName()); application.setClient_id(createdApp.getOauthConsumerKey()); application.setClient_secret(createdApp.getOauthConsumerSecret()); List<String> redirectUrisList = new ArrayList<>(); redirectUrisList.add(createdApp.getCallbackUrl()); application.setRedirect_uris(redirectUrisList); return application; }
/** * Delete OAuth2/OIDC application with client_id * @param clientId * @throws DCRMException */ public void deleteApplication(String clientId) throws DCRMException { OAuthConsumerAppDTO appDTO = getApplicationById(clientId); String applicationOwner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); deleteServiceProvider(appDTO.getApplicationName(), tenantDomain, applicationOwner); }
private OAuthConsumerAppDTO getApplicationById(String clientId) throws DCRMException { if (StringUtils.isEmpty(clientId)) { String errorMessage = "Invalid client_id"; throw DCRMUtils.generateClientException( DCRMConstants.ErrorMessages.BAD_REQUEST_INVALID_INPUT, errorMessage); } try { OAuthConsumerAppDTO dto = oAuthAdminService.getOAuthApplicationData(clientId); if (dto == null || StringUtils.isEmpty(dto.getApplicationName())) { throw DCRMUtils.generateClientException( DCRMConstants.ErrorMessages.NOT_FOUND_APPLICATION_WITH_ID, clientId); } else if (!isUserAuthorized(clientId)) { throw DCRMUtils.generateClientException( DCRMConstants.ErrorMessages.FORBIDDEN_UNAUTHORIZED_USER, clientId); } return dto; } catch (IdentityOAuthAdminException e) { if (e.getCause() instanceof InvalidOAuthClientException) { throw DCRMUtils.generateClientException(DCRMConstants.ErrorMessages.NOT_FOUND_APPLICATION_WITH_ID, clientId); } throw DCRMUtils.generateServerException( DCRMConstants.ErrorMessages.FAILED_TO_GET_APPLICATION_BY_ID, clientId, e); } }
createdApp = oAuthAdminService.getOAuthApplicationDataByAppName(oAuthConsumerApp.getApplicationName()); } catch (IdentityOAuthAdminException e) { throw DCRMUtils.generateServerException( DCRMConstants.ErrorMessages.FAILED_TO_GET_APPLICATION, oAuthConsumerApp.getApplicationName(), e); log.debug("Retrieved Details of OAuth App: " + createdApp.getApplicationName() + " in tenant: " + tenantDomain);
private void validateTokenExpiryConfigurations(OAuthConsumerAppDTO oAuthConsumerAppDTO) { if (oAuthConsumerAppDTO.getUserAccessTokenExpiryTime() == 0) { oAuthConsumerAppDTO.setUserAccessTokenExpiryTime( OAuthServerConfiguration.getInstance().getUserAccessTokenValidityPeriodInSeconds()); logOnInvalidConfig(oAuthConsumerAppDTO.getApplicationName(), "user access token", oAuthConsumerAppDTO.getUserAccessTokenExpiryTime()); } if (oAuthConsumerAppDTO.getApplicationAccessTokenExpiryTime() == 0) { oAuthConsumerAppDTO.setApplicationAccessTokenExpiryTime( OAuthServerConfiguration.getInstance().getApplicationAccessTokenValidityPeriodInSeconds()); logOnInvalidConfig(oAuthConsumerAppDTO.getApplicationName(), "application access token", oAuthConsumerAppDTO.getApplicationAccessTokenExpiryTime()); } if (oAuthConsumerAppDTO.getRefreshTokenExpiryTime() == 0) { oAuthConsumerAppDTO.setRefreshTokenExpiryTime( OAuthServerConfiguration.getInstance().getRefreshTokenValidityPeriodInSeconds()); logOnInvalidConfig(oAuthConsumerAppDTO.getApplicationName(), "refresh token", oAuthConsumerAppDTO.getRefreshTokenExpiryTime()); } if (oAuthConsumerAppDTO.getIdTokenExpiryTime() == 0) { oAuthConsumerAppDTO.setIdTokenExpiryTime( OAuthServerConfiguration.getInstance().getOpenIDConnectIDTokenExpiryTimeInSeconds()); logOnInvalidConfig(oAuthConsumerAppDTO.getApplicationName(), "id token", oAuthConsumerAppDTO.getIdTokenExpiryTime()); } }
oAuthAdminService.registerOAuthApplicationData(oAuthConsumerAppDTO); createdApp = oAuthAdminService.getOAuthApplicationDataByAppName(oAuthConsumerAppDTO .getApplicationName()); } else { createdApp = oAuthAdminService.registerAndRetrieveOAuthApplicationData(oAuthConsumerAppDTO); log.debug("Retrieved Details for OAuth App " + createdApp.getApplicationName()); OAUTH_REDIRECT_URIS, createdApp.getCallbackUrl()); oAuthApplicationInfo.addParameter(ApplicationConstants. OAUTH_CLIENT_NAME, createdApp.getApplicationName()); oAuthApplicationInfo.addParameter(ApplicationConstants. OAUTH_CLIENT_GRANT, createdApp.getGrantTypes());
app.setApplicationName(application.getApplicationName()); if ((application.getGrantTypes().contains(AUTHORIZATION_CODE) || application.getGrantTypes() .contains(IMPLICIT)) && StringUtils.isEmpty(application.getCallbackUrl())) { AppInfoCache.getInstance().addToCache(app.getOauthConsumerKey(), app); if (log.isDebugEnabled()) { log.debug("Oauth Application registration success : " + application.getApplicationName() + " in " + "tenant domain: " + tenantDomain); if (application != null) { log.debug("No authenticated user found. Failed to register OAuth App: " + application.getApplicationName()); } else { log.debug("No authenticated user found. Failed to register OAuth App");
oauthappdo.setOauthConsumerSecret(consumerAppDTO.getOauthConsumerSecret()); oauthappdo.setCallbackUrl(consumerAppDTO.getCallbackUrl()); oauthappdo.setApplicationName(consumerAppDTO.getApplicationName()); oauthappdo.setPkceMandatory(consumerAppDTO.getPkceMandatory()); oauthappdo.setPkceSupportPlain(consumerAppDTO.getPkceSupportPlain()); AppInfoCache.getInstance().addToCache(oauthappdo.getOauthConsumerKey(), oauthappdo); if (log.isDebugEnabled()) { log.debug("Oauth Application update success : " + consumerAppDTO.getApplicationName() + " in " + "tenant domain: " + tenantDomain);
ServiceProvider sp = getServiceProvider(appDTO.getApplicationName(), tenantDomain); if (StringUtils.isNotEmpty(clientName)) {
/** * Convert {@link org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO} to an * {@link org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo} * * @param createdApp Response from OAuthAdminService * @return Converted {@link org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo} */ private OAuthApplicationInfo createOAuthAppInfoFromDTO(OAuthConsumerAppDTO createdApp) { OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo(); oAuthApplicationInfo.setClientId(createdApp.getOauthConsumerKey()); oAuthApplicationInfo.setCallBackURL(createdApp.getCallbackUrl()); oAuthApplicationInfo.setClientSecret(createdApp.getOauthConsumerSecret()); oAuthApplicationInfo.addParameter(ApplicationConstants. OAUTH_REDIRECT_URIS, createdApp.getCallbackUrl()); oAuthApplicationInfo.addParameter(ApplicationConstants. OAUTH_CLIENT_NAME, createdApp.getApplicationName()); oAuthApplicationInfo.addParameter(ApplicationConstants. OAUTH_CLIENT_GRANT, createdApp.getGrantTypes()); return oAuthApplicationInfo; } }
oauthappdo.setOauthConsumerSecret(consumerAppDTO.getOauthConsumerSecret()); oauthappdo.setCallbackUrl(consumerAppDTO.getCallbackUrl()); oauthappdo.setApplicationName(consumerAppDTO.getApplicationName()); oauthappdo.setPkceMandatory(consumerAppDTO.getPkceMandatory()); oauthappdo.setPkceSupportPlain(consumerAppDTO.getPkceSupportPlain());
log.debug("Retrieved Details for OAuth App " + createdApp.getApplicationName()); registrationResponseProfile.getRedirectUrls().add(createdApp.getCallbackUrl()); registrationResponseProfile.setClientSecret(oauthConsumerSecret); registrationResponseProfile.setClientName(createdApp.getApplicationName()); registrationResponseProfile.setClientSecretExpiresAt(DEFAULT_CLIENT_SECRET_EXPIRY_TIME); if (StringUtils.isNotBlank(createdApp.getGrantTypes())) {
OAuthAppDO app = new OAuthAppDO(); if (application != null) { app.setApplicationName(application.getApplicationName()); if ((application.getGrantTypes().contains(AUTHORIZATION_CODE) || application.getGrantTypes() .contains(IMPLICIT)) && StringUtils.isEmpty(application.getCallbackUrl())) {
oAuthAdminService.getOAuthApplicationDataByAppName(oAuthConsumerApp.getApplicationName()); if (log.isDebugEnabled()) { log.debug("Retrieved Details for OAuth App " + createdApp.getApplicationName()); oAuthApplicationInfo.setCallBackURL(createdApp.getCallbackUrl()); oAuthApplicationInfo.setClientSecret(oauthConsumerSecret); oAuthApplicationInfo.setClientName(createdApp.getApplicationName());
for (String appName : revokeRequestDTO.getApps()) { for (OAuthConsumerAppDTO appDTO : appDTOs) { if (appDTO.getApplicationName().equals(appName)) { Set<AccessTokenDO> accessTokenDOs = null; try {
for (String appName : revokeRequestDTO.getApps()) { for (OAuthConsumerAppDTO appDTO : appDTOs) { if (appDTO.getApplicationName().equals(appName)) { Set<AccessTokenDO> accessTokenDOs; try {