org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO Java Examples
The following examples show how to use
org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RegistrationServiceImpl.java From carbon-apimgt with Apache License 2.0 | 6 votes |
/** * Retrieve the existing application of given name * * @param applicationName application name * @param saasApp value of IsSaasApp attribute of application. * @return existing Application */ private OAuthApplicationInfo getExistingApp(String applicationName, boolean saasApp) { OAuthApplicationInfo appToReturn = null; OAuthAdminService oAuthAdminService = new OAuthAdminService(); try { OAuthConsumerAppDTO consumerAppDTO = oAuthAdminService. getOAuthApplicationDataByAppName(applicationName); Map<String, String> valueMap = new HashMap<String, String>(); valueMap.put(OAUTH_CLIENT_GRANT, consumerAppDTO.getGrantTypes()); appToReturn = this.fromAppDTOToApplicationInfo(consumerAppDTO.getOauthConsumerKey(), consumerAppDTO.getApplicationName(), consumerAppDTO.getCallbackUrl(), consumerAppDTO.getOauthConsumerSecret(), saasApp, null, valueMap); } catch (IdentityOAuthAdminException e) { log.error("error occurred while trying to get OAuth Application data", e); } return appToReturn; }
Example #2
Source File: OAuthAdminService.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Get OAuth application data by the application name. * * @param appName OAuth application name * @return <code>OAuthConsumerAppDTO</code> with application information * @throws Exception Error when reading application information from persistence store. */ public OAuthConsumerAppDTO getOAuthApplicationDataByAppName(String appName) throws IdentityOAuthAdminException { OAuthConsumerAppDTO dto = new OAuthConsumerAppDTO(); OAuthAppDAO dao = new OAuthAppDAO(); try { OAuthAppDO app = dao.getAppInformationByAppName(appName); if (app != null) { dto.setApplicationName(app.getApplicationName()); dto.setCallbackUrl(app.getCallbackUrl()); dto.setOauthConsumerKey(app.getOauthConsumerKey()); dto.setOauthConsumerSecret(app.getOauthConsumerSecret()); dto.setOAuthVersion(app.getOauthVersion()); dto.setGrantTypes(app.getGrantTypes()); } return dto; }catch (InvalidOAuthClientException | IdentityOAuth2Exception e){ throw new IdentityOAuthAdminException("Error while retrieving the app information by app name", e); } }
Example #3
Source File: OAuthAdminService.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Get OAuth application data by the consumer key. * * @param consumerKey Consumer Key * @return <code>OAuthConsumerAppDTO</code> with application information * @throws Exception Error when reading application information from persistence store. */ public OAuthConsumerAppDTO getOAuthApplicationData(String consumerKey) throws IdentityOAuthAdminException { OAuthConsumerAppDTO dto = new OAuthConsumerAppDTO(); OAuthAppDAO dao = new OAuthAppDAO(); try { OAuthAppDO app = dao.getAppInformation(consumerKey); if (app != null) { dto.setApplicationName(app.getApplicationName()); dto.setCallbackUrl(app.getCallbackUrl()); dto.setOauthConsumerKey(app.getOauthConsumerKey()); dto.setOauthConsumerSecret(app.getOauthConsumerSecret()); dto.setOAuthVersion(app.getOauthVersion()); dto.setGrantTypes(app.getGrantTypes()); } return dto; } catch (InvalidOAuthClientException | IdentityOAuth2Exception e) { throw new IdentityOAuthAdminException("Error while retrieving the app information using consumer key", e); } }
Example #4
Source File: OAuthConsumerAppToApiModel.java From identity-api-server with Apache License 2.0 | 6 votes |
@Override public OpenIDConnectConfiguration apply(OAuthConsumerAppDTO oauthAppDTO) { return new OpenIDConnectConfiguration() .clientId(oauthAppDTO.getOauthConsumerKey()) .clientSecret(oauthAppDTO.getOauthConsumerSecret()) .state(OpenIDConnectConfiguration.StateEnum.valueOf(oauthAppDTO.getState())) .grantTypes(buildGrantTypeList(oauthAppDTO)) .publicClient(oauthAppDTO.isBypassClientCredentials()) .callbackURLs(getCallbackUrls(oauthAppDTO)) .allowedOrigins(getAllowedOrigins(oauthAppDTO)) .pkce(buildPKCEConfiguration(oauthAppDTO)) .accessToken(buildTokenConfiguration(oauthAppDTO)) .refreshToken(buildRefreshTokenConfiguration(oauthAppDTO)) .idToken(buildIdTokenConfiguration(oauthAppDTO)) .logout(buildLogoutConfiguration(oauthAppDTO)) .scopeValidators(getScopeValidators(oauthAppDTO)) .validateRequestObjectSignature(oauthAppDTO.isRequestObjectSignatureValidationEnabled()) .accessTokenBindingType(oauthAppDTO.getTokenBindingType()); }
Example #5
Source File: OAuthConsumerAppToApiModel.java From identity-api-server with Apache License 2.0 | 5 votes |
private AccessTokenConfiguration buildTokenConfiguration(OAuthConsumerAppDTO oAuthConsumerAppDTO) { return new AccessTokenConfiguration() .type(oAuthConsumerAppDTO.getTokenType()) .userAccessTokenExpiryInSeconds(oAuthConsumerAppDTO.getUserAccessTokenExpiryTime()) .applicationAccessTokenExpiryInSeconds(oAuthConsumerAppDTO.getApplicationAccessTokenExpiryTime()); }
Example #6
Source File: SessionDataPublisherImpl.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Method to build a OAuthConsumerAppDTO type object * @param appDO required param * @return OAuthConsumerAppDTO type object */ private OAuthConsumerAppDTO buildConsumerAppDTO(OAuthAppDO appDO) { OAuthConsumerAppDTO dto = new OAuthConsumerAppDTO(); dto.setApplicationName(appDO.getApplicationName()); dto.setCallbackUrl(appDO.getCallbackUrl()); dto.setOauthConsumerKey(appDO.getOauthConsumerKey()); dto.setOauthConsumerSecret(appDO.getOauthConsumerSecret()); dto.setOAuthVersion(appDO.getOauthVersion()); dto.setGrantTypes(appDO.getGrantTypes()); dto.setScopeValidators(appDO.getScopeValidators()); dto.setUsername(appDO.getAppOwner().toFullQualifiedUsername()); dto.setState(appDO.getState()); dto.setPkceMandatory(appDO.isPkceMandatory()); dto.setPkceSupportPlain(appDO.isPkceSupportPlain()); dto.setUserAccessTokenExpiryTime(appDO.getUserAccessTokenExpiryTime()); dto.setApplicationAccessTokenExpiryTime(appDO.getApplicationAccessTokenExpiryTime()); dto.setRefreshTokenExpiryTime(appDO.getRefreshTokenExpiryTime()); dto.setIdTokenExpiryTime(appDO.getIdTokenExpiryTime()); dto.setAudiences(appDO.getAudiences()); dto.setRequestObjectSignatureValidationEnabled(appDO.isRequestObjectSignatureValidationEnabled()); dto.setIdTokenEncryptionEnabled(appDO.isIdTokenEncryptionEnabled()); dto.setIdTokenEncryptionAlgorithm(appDO.getIdTokenEncryptionAlgorithm()); dto.setIdTokenEncryptionMethod(appDO.getIdTokenEncryptionMethod()); dto.setBackChannelLogoutUrl(appDO.getBackChannelLogoutUrl()); dto.setTokenType(appDO.getTokenType()); dto.setBypassClientCredentials(appDO.isBypassClientCredentials()); return dto; }
Example #7
Source File: RegistrationServiceImpl.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Method to create a OAuth App with client credentials * * @param appName application name * @param grantTypes grant types * @param userName username of the application * @return created Oauth App */ private OAuthConsumerAppDTO createOAuthApp(String appName, OAuthApplicationInfo applicationInfo, String grantTypes, String userName) { OAuthConsumerAppDTO createdApp = null; OAuthAdminService oauthAdminService = new OAuthAdminService(); OAuthConsumerAppDTO oauthConsumerAppDTO = new OAuthConsumerAppDTO(); oauthConsumerAppDTO.setApplicationName(appName); if (StringUtils.isNotBlank(applicationInfo.getCallBackURL())) { oauthConsumerAppDTO.setCallbackUrl(applicationInfo.getCallBackURL()); } oauthConsumerAppDTO.setUsername(userName); oauthConsumerAppDTO.setOAuthVersion(OAuthConstants.OAuthVersions.VERSION_2); oauthConsumerAppDTO.setGrantTypes(grantTypes.trim()); try { boolean isHashDisabled = OAuth2Util.isHashDisabled(); if (isHashDisabled) { //Creating the Oauth app oauthAdminService.registerOAuthApplicationData(oauthConsumerAppDTO); //Retrieving the created OAuth application createdApp = oauthAdminService.getOAuthApplicationDataByAppName (oauthConsumerAppDTO.getApplicationName()); } else { createdApp = oauthAdminService.registerAndRetrieveOAuthApplicationData(oauthConsumerAppDTO); } } catch (IdentityOAuthAdminException e) { log.error("Error occurred while creating the OAuth app", e); } if (log.isDebugEnabled()) { log.debug("Created OAuth App " + appName); } return createdApp; }
Example #8
Source File: OAuthAdminService.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * Update existing consumer application. * * @param consumerAppDTO <code>OAuthConsumerAppDTO</code> with updated application information * @throws IdentityOAuthAdminException Error when updating the underlying identity persistence store. */ public void updateConsumerApplication(OAuthConsumerAppDTO consumerAppDTO) throws IdentityOAuthAdminException { String userName = CarbonContext.getThreadLocalCarbonContext().getUsername(); String tenantAwareUsername = MultitenantUtils.getTenantAwareUsername(userName); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain(); OAuthAppDAO dao = new OAuthAppDAO(); OAuthAppDO oauthappdo = new OAuthAppDO(); AuthenticatedUser user = new AuthenticatedUser(); user.setUserName(UserCoreUtil.removeDomainFromName(tenantAwareUsername)); user.setTenantDomain(tenantDomain); user.setUserStoreDomain(IdentityUtil.extractDomainFromName(userName)); oauthappdo.setUser(user); oauthappdo.setOauthConsumerKey(consumerAppDTO.getOauthConsumerKey()); oauthappdo.setOauthConsumerSecret(consumerAppDTO.getOauthConsumerSecret()); oauthappdo.setCallbackUrl(consumerAppDTO.getCallbackUrl()); oauthappdo.setApplicationName(consumerAppDTO.getApplicationName()); if (OAuthConstants.OAuthVersions.VERSION_2.equals(consumerAppDTO.getOAuthVersion())) { List<String> allowedGrants = new ArrayList<>(Arrays.asList(getAllowedGrantTypes())); String[] requestGrants = consumerAppDTO.getGrantTypes().split("\\s"); for (String requestedGrant : requestGrants) { if (StringUtils.isBlank(requestedGrant)) { continue; } if (!allowedGrants.contains(requestedGrant)) { throw new IdentityOAuthAdminException(requestedGrant + " not allowed"); } } oauthappdo.setGrantTypes(consumerAppDTO.getGrantTypes()); } dao.updateConsumerApplication(oauthappdo); if (OAuthServerConfiguration.getInstance().isCacheEnabled()) { appInfoCache.addToCache(oauthappdo.getOauthConsumerKey(), oauthappdo); } }
Example #9
Source File: OAuthConsumerAppToApiModel.java From identity-api-server with Apache License 2.0 | 5 votes |
private List<String> getCallbackUrls(OAuthConsumerAppDTO oauthApp) { List<String> callbackUris = new ArrayList<>(); if (StringUtils.isNotBlank(oauthApp.getCallbackUrl())) { callbackUris.add(oauthApp.getCallbackUrl()); } return callbackUris; }
Example #10
Source File: OAuthConsumerAppToApiModel.java From identity-api-server with Apache License 2.0 | 5 votes |
private List<String> buildGrantTypeList(OAuthConsumerAppDTO oauthApp) { if (StringUtils.isNotBlank(oauthApp.getGrantTypes())) { return Arrays.asList(oauthApp.getGrantTypes().split("\\s+")); } else { return Collections.emptyList(); } }
Example #11
Source File: OAuthConsumerAppToApiModel.java From identity-api-server with Apache License 2.0 | 5 votes |
private IdTokenEncryptionConfiguration buildIdTokenEncryptionConfiguration(OAuthConsumerAppDTO appDTO) { return new IdTokenEncryptionConfiguration() .enabled(appDTO.isIdTokenEncryptionEnabled()) .algorithm(StringUtils.equals(appDTO.getIdTokenEncryptionAlgorithm(), "null") || StringUtils.isBlank(appDTO.getIdTokenEncryptionAlgorithm()) ? "" : appDTO.getIdTokenEncryptionAlgorithm()) .method(StringUtils.equals(appDTO.getIdTokenEncryptionMethod(), "null") || StringUtils.isBlank(appDTO.getIdTokenEncryptionMethod()) ? "" : appDTO.getIdTokenEncryptionMethod()); }
Example #12
Source File: OAuthConsumerAppToApiModel.java From identity-api-server with Apache License 2.0 | 5 votes |
private List<String> getAudiences(OAuthConsumerAppDTO oAuthConsumerAppDTO) { if (oAuthConsumerAppDTO.getAudiences() == null) { return Collections.emptyList(); } else { return Arrays.asList(oAuthConsumerAppDTO.getAudiences()); } }
Example #13
Source File: OAuthConsumerAppToApiModel.java From identity-api-server with Apache License 2.0 | 5 votes |
private IdTokenConfiguration buildIdTokenConfiguration(OAuthConsumerAppDTO oAuthConsumerAppDTO) { return new IdTokenConfiguration() .expiryInSeconds(oAuthConsumerAppDTO.getIdTokenExpiryTime()) .audience(getAudiences(oAuthConsumerAppDTO)) .encryption(buildIdTokenEncryptionConfiguration(oAuthConsumerAppDTO)); }
Example #14
Source File: ApiModelToOAuthConsumerApp.java From identity-api-server with Apache License 2.0 | 5 votes |
@Override public OAuthConsumerAppDTO apply(String appName, OpenIDConnectConfiguration oidcModel) { OAuthConsumerAppDTO consumerAppDTO = new OAuthConsumerAppDTO(); consumerAppDTO.setApplicationName(appName); consumerAppDTO.setOauthConsumerKey(oidcModel.getClientId()); consumerAppDTO.setOauthConsumerSecret(oidcModel.getClientSecret()); consumerAppDTO.setCallbackUrl(getCallbackUrl(oidcModel.getCallbackURLs())); consumerAppDTO.setOAuthVersion(OAuthConstants.OAuthVersions.VERSION_2); consumerAppDTO.setUsername(ContextLoader.getUsernameFromContext()); consumerAppDTO.setGrantTypes(getGrantTypes(oidcModel)); consumerAppDTO.setScopeValidators(getScopeValidators(oidcModel)); consumerAppDTO.setBypassClientCredentials(oidcModel.getPublicClient()); consumerAppDTO.setRequestObjectSignatureValidationEnabled(oidcModel.getValidateRequestObjectSignature()); consumerAppDTO.setTokenBindingType(oidcModel.getAccessTokenBindingType()); updateAllowedOrigins(consumerAppDTO, oidcModel.getAllowedOrigins()); updatePkceConfigurations(consumerAppDTO, oidcModel.getPkce()); updateAccessTokenConfiguration(consumerAppDTO, oidcModel.getAccessToken()); updateRefreshTokenConfiguration(consumerAppDTO, oidcModel.getRefreshToken()); updateIdTokenConfiguration(consumerAppDTO, oidcModel.getIdToken()); updateOidcLogoutConfiguration(consumerAppDTO, oidcModel.getLogout()); return consumerAppDTO; }
Example #15
Source File: OAuthInboundFunctions.java From identity-api-server with Apache License 2.0 | 5 votes |
public static OpenIDConnectConfiguration regenerateClientSecret(String clientId) { try { OAuthConsumerAppDTO oAuthConsumerAppDTO = ApplicationManagementServiceHolder.getInstance() .getOAuthAdminService().updateAndRetrieveOauthSecretKey(clientId); return new OAuthConsumerAppToApiModel().apply(oAuthConsumerAppDTO); } catch (IdentityOAuthAdminException e) { throw buildServerError("Error while regenerating client secret of oauth application.", e); } }
Example #16
Source File: OAuthInboundFunctions.java From identity-api-server with Apache License 2.0 | 5 votes |
public static OpenIDConnectConfiguration getOAuthConfiguration(InboundAuthenticationRequestConfig inboundAuth) { String clientId = inboundAuth.getInboundAuthKey(); try { OAuthConsumerAppDTO oauthApp = ApplicationManagementServiceHolder.getInstance().getOAuthAdminService().getOAuthApplicationData (clientId); return new OAuthConsumerAppToApiModel().apply(oauthApp); } catch (IdentityOAuthAdminException e) { throw buildServerError("Error while retrieving oauth application for clientId: " + clientId, e); } }
Example #17
Source File: OAuthInboundFunctions.java From identity-api-server with Apache License 2.0 | 5 votes |
public static InboundAuthenticationRequestConfig createOAuthInbound(String appName, OpenIDConnectConfiguration oidcModel) { // Build a consumer apps object. OAuthConsumerAppDTO consumerApp = new ApiModelToOAuthConsumerApp().apply(appName, oidcModel); try { OAuthConsumerAppDTO createdOAuthApp = ApplicationManagementServiceHolder.getInstance() .getOAuthAdminService() .registerAndRetrieveOAuthApplicationData(consumerApp); return createInboundAuthRequestConfig(createdOAuthApp.getOauthConsumerKey()); } catch (IdentityOAuthAdminException e) { throw handleOAuthException(e); } }
Example #18
Source File: OAuthInboundFunctions.java From identity-api-server with Apache License 2.0 | 5 votes |
public static InboundAuthenticationRequestConfig putOAuthInbound(ServiceProvider application, OpenIDConnectConfiguration oidcConfigModel) { // First we identify whether this is a insert or update. try { String currentClientId = InboundFunctions.getInboundAuthKey(application, StandardInboundProtocols.OAUTH2); if (currentClientId != null) { // This is an update. OAuthConsumerAppDTO oauthApp = ApplicationManagementServiceHolder.getInstance().getOAuthAdminService ().getOAuthApplicationData(currentClientId); if (!StringUtils.equals(oauthApp.getOauthConsumerKey(), oidcConfigModel.getClientId())) { throw buildBadRequestError("Invalid ClientID provided for update."); } if (!StringUtils.equals(oauthApp.getOauthConsumerSecret(), oidcConfigModel.getClientSecret())) { throw buildBadRequestError("Invalid ClientSecret provided for update."); } OAuthConsumerAppDTO appToUpdate = new ApiModelToOAuthConsumerApp().apply(application .getApplicationName(), oidcConfigModel); ApplicationManagementServiceHolder.getInstance().getOAuthAdminService().updateConsumerApplication (appToUpdate); String updatedClientId = appToUpdate.getOauthConsumerKey(); return createInboundAuthRequestConfig(updatedClientId); } else { return createOAuthInbound(application.getApplicationName(), oidcConfigModel); } } catch (IdentityOAuthAdminException e) { throw handleOAuthException(e); } }
Example #19
Source File: ApiModelToOAuthConsumerApp.java From identity-api-server with Apache License 2.0 | 5 votes |
private void updatePkceConfigurations(OAuthConsumerAppDTO consumerAppDTO, OAuth2PKCEConfiguration pkce) { if (pkce != null) { consumerAppDTO.setPkceMandatory(pkce.getMandatory()); consumerAppDTO.setPkceSupportPlain(pkce.getSupportPlainTransformAlgorithm()); } }
Example #20
Source File: ApiModelToOAuthConsumerApp.java From identity-api-server with Apache License 2.0 | 5 votes |
private void updateAccessTokenConfiguration(OAuthConsumerAppDTO consumerAppDTO, AccessTokenConfiguration accessToken) { if (accessToken != null) { consumerAppDTO.setTokenType(accessToken.getType()); consumerAppDTO.setUserAccessTokenExpiryTime(accessToken.getUserAccessTokenExpiryInSeconds()); consumerAppDTO.setApplicationAccessTokenExpiryTime(accessToken.getApplicationAccessTokenExpiryInSeconds()); } }
Example #21
Source File: ApiModelToOAuthConsumerApp.java From identity-api-server with Apache License 2.0 | 5 votes |
private void updateRefreshTokenConfiguration(OAuthConsumerAppDTO consumerAppDTO, RefreshTokenConfiguration refreshToken) { if (refreshToken != null) { consumerAppDTO.setRefreshTokenExpiryTime(refreshToken.getExpiryInSeconds()); String renewRefreshToken = refreshToken.getRenewRefreshToken() != null ? String.valueOf(refreshToken.getRenewRefreshToken()) : null; consumerAppDTO.setRenewRefreshTokenEnabled(renewRefreshToken); } }
Example #22
Source File: ApiModelToOAuthConsumerApp.java From identity-api-server with Apache License 2.0 | 5 votes |
private void updateIdTokenConfiguration(OAuthConsumerAppDTO consumerAppDTO, IdTokenConfiguration idToken) { if (idToken != null) { consumerAppDTO.setIdTokenExpiryTime(idToken.getExpiryInSeconds()); consumerAppDTO.setAudiences(Optional.ofNullable(idToken.getAudience()) .map(audiences -> audiences.toArray(new String[0])) .orElse(new String[0]) ); consumerAppDTO.setIdTokenEncryptionEnabled(idToken.getEncryption().getEnabled()); if (idToken.getEncryption().getEnabled()) { consumerAppDTO.setIdTokenEncryptionAlgorithm(idToken.getEncryption().getAlgorithm()); consumerAppDTO.setIdTokenEncryptionMethod(idToken.getEncryption().getMethod()); } } }
Example #23
Source File: ApiModelToOAuthConsumerApp.java From identity-api-server with Apache License 2.0 | 5 votes |
private void updateOidcLogoutConfiguration(OAuthConsumerAppDTO consumerAppDTO, OIDCLogoutConfiguration logout) { if (logout != null) { consumerAppDTO.setBackChannelLogoutUrl(logout.getBackChannelLogoutUrl()); consumerAppDTO.setFrontchannelLogoutUrl(logout.getFrontChannelLogoutUrl()); } }
Example #24
Source File: OAuthConsumerAppToApiModel.java From identity-api-server with Apache License 2.0 | 4 votes |
private OAuth2PKCEConfiguration buildPKCEConfiguration(OAuthConsumerAppDTO oAuthConsumerAppDTO) { return new OAuth2PKCEConfiguration() .mandatory(oAuthConsumerAppDTO.getPkceMandatory()) .supportPlainTransformAlgorithm(oAuthConsumerAppDTO.getPkceSupportPlain()); }
Example #25
Source File: OAuthConsumerAppToApiModel.java From identity-api-server with Apache License 2.0 | 4 votes |
private OIDCLogoutConfiguration buildLogoutConfiguration(OAuthConsumerAppDTO oAuthConsumerAppDTO) { return new OIDCLogoutConfiguration() .backChannelLogoutUrl(oAuthConsumerAppDTO.getBackChannelLogoutUrl()) .frontChannelLogoutUrl(oAuthConsumerAppDTO.getFrontchannelLogoutUrl()); }
Example #26
Source File: OAuthConsumerAppToApiModel.java From identity-api-server with Apache License 2.0 | 4 votes |
private RefreshTokenConfiguration buildRefreshTokenConfiguration(OAuthConsumerAppDTO oAuthConsumerAppDTO) { return new RefreshTokenConfiguration() .expiryInSeconds(oAuthConsumerAppDTO.getRefreshTokenExpiryTime()) .renewRefreshToken(Boolean.parseBoolean(oAuthConsumerAppDTO.getRenewRefreshTokenEnabled())); }
Example #27
Source File: OAuthConsumerAppToApiModel.java From identity-api-server with Apache License 2.0 | 4 votes |
private List<String> getScopeValidators(OAuthConsumerAppDTO oauthAppDTO) { return oauthAppDTO.getScopeValidators() != null ? Arrays.asList(oauthAppDTO.getScopeValidators()) : Collections.emptyList(); }
Example #28
Source File: OAuthAdminService.java From carbon-identity with Apache License 2.0 | 4 votes |
/** * Registers an OAuth consumer application. * * @param application <code>OAuthConsumerAppDTO</code> with application information * @throws Exception Error when persisting the application information to the persistence store */ public void registerOAuthApplicationData(OAuthConsumerAppDTO application) throws IdentityOAuthAdminException{ String userName = CarbonContext.getThreadLocalCarbonContext().getUsername(); if (userName != null) { String tenantUser = MultitenantUtils.getTenantAwareUsername(userName); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain(); OAuthAppDAO dao = new OAuthAppDAO(); 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())) { throw new IdentityOAuthAdminException("Callback Url is required for Code or Implicit grant types"); } app.setCallbackUrl(application.getCallbackUrl()); if (application.getOauthConsumerKey() == null) { app.setOauthConsumerKey(OAuthUtil.getRandomNumber()); app.setOauthConsumerSecret(OAuthUtil.getRandomNumber()); } else { app.setOauthConsumerKey(application.getOauthConsumerKey()); app.setOauthConsumerSecret(application.getOauthConsumerSecret()); } String applicationUser = application.getUsername(); if (applicationUser != null && applicationUser.trim().length() > 0) { try { if (CarbonContext.getThreadLocalCarbonContext().getUserRealm(). getUserStoreManager().isExistingUser(application.getUsername())) { tenantUser = applicationUser; } else { log.warn("OAuth application registrant user name " + applicationUser + " does not exist in the user store. Using logged-in user name " + tenantUser + " as registrant name"); } } catch (UserStoreException e) { throw new IdentityOAuthAdminException("Error while retrieving the user store manager", e); } } AuthenticatedUser user = new AuthenticatedUser(); user.setUserName(UserCoreUtil.removeDomainFromName(tenantUser)); user.setTenantDomain(tenantDomain); user.setUserStoreDomain(IdentityUtil.extractDomainFromName(userName)); app.setUser(user); if (application.getOAuthVersion() != null) { app.setOauthVersion(application.getOAuthVersion()); } else { // by default, assume OAuth 2.0, if it is not set. app.setOauthVersion(OAuthConstants.OAuthVersions.VERSION_2); } if (OAuthConstants.OAuthVersions.VERSION_2.equals(application.getOAuthVersion())) { List<String> allowedGrants = new ArrayList<>(Arrays.asList(getAllowedGrantTypes())); String[] requestGrants = application.getGrantTypes().split("\\s"); for (String requestedGrant : requestGrants) { if (StringUtils.isBlank(requestedGrant)){ continue; } if (!allowedGrants.contains(requestedGrant)) { throw new IdentityOAuthAdminException(requestedGrant + " not allowed"); } } app.setGrantTypes(application.getGrantTypes()); } dao.addOAuthApplication(app); if (OAuthServerConfiguration.getInstance().isCacheEnabled()) { appInfoCache.addToCache(app.getOauthConsumerKey(), app); } } } }
Example #29
Source File: ApiModelToOAuthConsumerApp.java From identity-api-server with Apache License 2.0 | 4 votes |
private void updateAllowedOrigins(OAuthConsumerAppDTO consumerAppDTO, List<String> allowedOrigins) { if (CollectionUtils.isNotEmpty(allowedOrigins)) { throw Utils.buildNotImplementedError("Allowed origins are not supported for OAuth apps yet."); } }
Example #30
Source File: OAuthConsumerAppToApiModel.java From identity-api-server with Apache License 2.0 | 2 votes |
private List<String> getAllowedOrigins(OAuthConsumerAppDTO oauthApp) { return Collections.emptyList(); }