/** * Registers an OAuth consumer application. * * @param application <code>OAuthConsumerAppDTO</code> with application information * @throws IdentityOAuthAdminException Error when persisting the application information to the persistence store. */ public void registerOAuthApplicationData(OAuthConsumerAppDTO application) throws IdentityOAuthAdminException { registerAndRetrieveOAuthApplicationData(application); }
/** * Regenerate consumer secret for the application. * * @param consumerKey Consumer key for the application. * @throws IdentityOAuthAdminException Error while regenerating the consumer secret. */ public void updateOauthSecretKey(String consumerKey) throws IdentityOAuthAdminException { updateAndRetrieveOauthSecretKey(consumerKey); }
/** * @param oauthParams * @return * @throws RegistryException * @throws IdentityException */ private Parameters generateOauthToken(Parameters oauthParams) throws IdentityOAuthAdminException { OAuthConsumerDAO dao = new OAuthConsumerDAO(); String oauthToken = org.wso2.carbon.identity.oauth.OAuthUtil.getRandomNumber(); String oauthSecret = org.wso2.carbon.identity.oauth.OAuthUtil.getRandomNumber(); dao.createOAuthRequestToken(oauthParams.getOauthConsumerKey(), oauthToken, oauthSecret, oauthParams.getOauthCallback(), oauthParams.getScope()); Parameters params = new Parameters(); params.setOauthConsumerKey(oauthParams.getOauthConsumerKey()); params.setOauthToken(oauthToken); params.setOauthTokenSecret(oauthSecret); return params; }
/** * Get OAuth application data by the application name. * * @param appName OAuth application name * @return <code>OAuthConsumerAppDTO</code> with application information * @throws IdentityOAuthAdminException Error when reading application information from persistence store. */ public OAuthConsumerAppDTO getOAuthApplicationDataByAppName(String appName) throws IdentityOAuthAdminException { OAuthConsumerAppDTO dto; OAuthAppDAO dao = new OAuthAppDAO(); try { OAuthAppDO app = dao.getAppInformationByAppName(appName); if (app != null) { dto = buildConsumerAppDTO(app); } else { dto = new OAuthConsumerAppDTO(); } return dto; } catch (InvalidOAuthClientException | IdentityOAuth2Exception e) { throw handleError("Error while retrieving the app information by app name: " + appName, e); } }
private void triggerPreRevokeListeners(OAuthRevocationRequestDTO revokeRequestDTO) throws IdentityOAuthAdminException { OAuthEventInterceptor oAuthEventInterceptorProxy = OAuthComponentServiceHolder.getInstance() .getOAuthEventInterceptorProxy(); if (oAuthEventInterceptorProxy != null && oAuthEventInterceptorProxy.isEnabled()) { try { oAuthEventInterceptorProxy.onPreTokenRevocationByResourceOwner(revokeRequestDTO); } catch (IdentityOAuth2Exception e) { throw new IdentityOAuthAdminException("Error occurred with Oauth pre-revoke listener ", e); } } }
private void triggerPreRevokeListeners(OAuthRevocationRequestDTO revokeRequestDTO) throws IdentityOAuthAdminException { OAuthEventInterceptor oAuthEventInterceptorProxy = OAuthComponentServiceHolder.getInstance() .getOAuthEventInterceptorProxy(); if (oAuthEventInterceptorProxy != null && oAuthEventInterceptorProxy.isEnabled()) { try { Map<String, Object> paramMap = new HashMap<>(); oAuthEventInterceptorProxy.onPreTokenRevocationByResourceOwner(revokeRequestDTO, paramMap); } catch (IdentityOAuth2Exception e) { throw handleError("Error occurred with Oauth pre-revoke listener ", e); } } }
/** * To insert oidc scopes and claims in the related db tables. * * @param scope an oidc scope * @throws IdentityOAuthAdminException if an error occurs when inserting scopes or claims. */ public void addScope(String scope, String[] claims) throws IdentityOAuthAdminException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); try { if (StringUtils.isNotEmpty(scope)) { OAuthTokenPersistenceFactory.getInstance().getScopeClaimMappingDAO().addScope(tenantId, scope, claims); } else { throw new IdentityOAuthAdminException("The scope can not be empty."); } } catch (IdentityOAuth2Exception e) { throw handleError("Error while inserting OIDC scopes and claims.", e); } }
public static void clearOAuthCache(String consumerKey, String authorizedUser) { boolean isUsernameCaseSensitive = IdentityUtil.isUserStoreInUsernameCaseSensitive(authorizedUser); if (!isUsernameCaseSensitive) { authorizedUser = authorizedUser.toLowerCase(); } clearOAuthCache(consumerKey + ":" + authorizedUser); }
/** * This is used to handle the OAuthAdminService exceptions. This will log the error message and return an * IdentityOAuthAdminException exception * @param message error message * @param exception Exception. * @return */ public static IdentityOAuthAdminException handleError(String message, Exception exception) { log.error(message); if (exception == null) { return new IdentityOAuthAdminException(message); } else { if (log.isDebugEnabled()) { log.debug(exception); } return new IdentityOAuthAdminException(message, exception); } }
public void deleteRequestObjectReferenceByTokenId(String tokenId) throws IdentityOAuthAdminException { try (Connection connection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement prepStmt = connection.prepareStatement(SQLQueries.DELETE_REQ_OBJECT_BY_TOKEN_ID)) { prepStmt.setString(1, tokenId); prepStmt.execute(); connection.commit(); } catch (SQLException e) { throw handleError("Error when executing the SQL : " + SQLQueries.DELETE_REQ_OBJECT_BY_TOKEN_ID, e); } }
/** * @param oauthParams * @return * @throws RegistryException * @throws IdentityException */ private Parameters generateOauthToken(Parameters oauthParams) throws IdentityOAuthAdminException { OAuthConsumerDAO dao = new OAuthConsumerDAO(); String oauthToken = org.wso2.carbon.identity.oauth.OAuthUtil.getRandomNumber(); String oauthSecret = org.wso2.carbon.identity.oauth.OAuthUtil.getRandomNumber(); dao.createOAuthRequestToken(oauthParams.getOauthConsumerKey(), oauthToken, oauthSecret, oauthParams.getOauthCallback(), oauthParams.getScope()); Parameters params = new Parameters(); params.setOauthConsumerKey(oauthParams.getOauthConsumerKey()); params.setOauthToken(oauthToken); params.setOauthTokenSecret(oauthSecret); return params; }
public static void clearOAuthCache(String consumerKey, String authorizedUser, String scope) { boolean isUsernameCaseSensitive = IdentityUtil.isUserStoreInUsernameCaseSensitive(authorizedUser); if (!isUsernameCaseSensitive) { authorizedUser = authorizedUser.toLowerCase(); } clearOAuthCache(consumerKey + ":" + authorizedUser + ":" + scope); }
public void deleteRequestObjectReferenceByCode(String codeId) throws IdentityOAuthAdminException { try (Connection connection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement prepStmt = connection.prepareStatement(SQLQueries.DELETE_REQ_OBJECT_BY_CODE_ID)) { prepStmt.setString(1, codeId); prepStmt.execute(); connection.commit(); } catch (SQLException e) { throw handleError("Error when executing the SQL : " + SQLQueries.DELETE_REQ_OBJECT_BY_CODE_ID, e); } } }
public static void clearOAuthCache(String consumerKey, String authorizedUser) { boolean isUsernameCaseSensitive = IdentityUtil.isUserStoreInUsernameCaseSensitive(authorizedUser); if (!isUsernameCaseSensitive) { authorizedUser = authorizedUser.toLowerCase(); } clearOAuthCache(consumerKey + ":" + authorizedUser); }
private void deleteRequestObjectReferenceforCode(String tokenId) throws IdentityOAuthAdminException { try (Connection connection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement prepStmt = connection.prepareStatement(SQLQueries.DELETE_REQ_OBJECT_TOKEN_FOR_CODE)) { prepStmt.setString(1, tokenId); prepStmt.execute(); connection.commit(); } catch (SQLException e) { throw handleError("Can not delete existing entry for the same token id" + tokenId, e); } }
public static void clearOAuthCache(String consumerKey, String authorizedUser, String scope) { boolean isUsernameCaseSensitive = IdentityUtil.isUserStoreInUsernameCaseSensitive(authorizedUser); if (!isUsernameCaseSensitive) { authorizedUser = authorizedUser.toLowerCase(); } clearOAuthCache(consumerKey + ":" + authorizedUser + ":" + scope); }
public static void clearOAuthCache(String consumerKey, User authorizedUser, String scope) { String user = UserCoreUtil.addDomainToName(authorizedUser.getUserName(), authorizedUser.getUserStoreDomain()); user = UserCoreUtil.addTenantDomainToEntry(user, authorizedUser.getTenantDomain()); clearOAuthCache(consumerKey, user, scope); }
public static void clearOAuthCache(String consumerKey, User authorizedUser, String scope) { String user = UserCoreUtil.addDomainToName(authorizedUser.getUserName(), authorizedUser.getUserStoreDomain()); user = UserCoreUtil.addTenantDomainToEntry(user, authorizedUser.getTenantDomain()); clearOAuthCache(consumerKey, user, scope); }
public static void clearOAuthCache(String consumerKey, User authorizedUser) { String user = UserCoreUtil.addDomainToName(authorizedUser.getUserName(), authorizedUser.getUserStoreDomain()); user = UserCoreUtil.addTenantDomainToEntry(user, authorizedUser.getTenantDomain()); clearOAuthCache(consumerKey, user); }
public static void clearOAuthCache(String consumerKey, User authorizedUser) { String user = UserCoreUtil.addDomainToName(authorizedUser.getUserName(), authorizedUser.getUserStoreDomain()); user = UserCoreUtil.addTenantDomainToEntry(user, authorizedUser.getTenantDomain()); clearOAuthCache(consumerKey, user); }