/** * Regenerate consumer secret for the application and retrieve application details. * * @param consumerKey Consumer key for the application. * @return OAuthConsumerAppDTO OAuth application details. * @throws IdentityOAuthAdminException Error while regenerating the consumer secret. */ public OAuthConsumerAppDTO updateAndRetrieveOauthSecretKey(String consumerKey) throws IdentityOAuthAdminException { OAuthConsumerAppDTO oAuthConsumerAppDTO = new OAuthConsumerAppDTO(); String newSecretKey = OAuthUtil.getRandomNumber(); CacheEntry clientCredentialDO = new ClientCredentialDO(newSecretKey); oAuthConsumerAppDTO.setOauthConsumerKey(consumerKey); oAuthConsumerAppDTO.setOauthConsumerSecret(newSecretKey); Properties properties = new Properties(); properties.setProperty(OAuthConstants.OAUTH_APP_NEW_SECRET_KEY, newSecretKey); properties.setProperty(OAuthConstants.ACTION_PROPERTY_KEY, OAuthConstants.ACTION_REGENERATE); updateAppAndRevokeTokensAndAuthzCodes(consumerKey, properties); OAuthCache.getInstance().addToCache(new OAuthCacheKey(consumerKey), clientCredentialDO); if (log.isDebugEnabled()) { log.debug("Client Secret for OAuth app with consumerKey: " + consumerKey + " updated in OAuthCache."); } return oAuthConsumerAppDTO; }
/** * @param consumerKey * @param newState * @throws IdentityOAuthAdminException */ public void updateConsumerAppState(String consumerKey, String newState) throws IdentityOAuthAdminException { OAuthAppDAO oAuthAppDAO = new OAuthAppDAO(); try { OAuthAppDO oAuthAppDO = AppInfoCache.getInstance().getValueFromCache(consumerKey); if (oAuthAppDO == null) { oAuthAppDO = oAuthAppDAO.getAppInformation(consumerKey); } // change the state oAuthAppDO.setState(newState); Properties properties = new Properties(); properties.setProperty(OAuthConstants.OAUTH_APP_NEW_STATE, newState); properties.setProperty(OAuthConstants.ACTION_PROPERTY_KEY, OAuthConstants.ACTION_REVOKE); updateAppAndRevokeTokensAndAuthzCodes(consumerKey, properties); AppInfoCache.getInstance().addToCache(consumerKey, oAuthAppDO); if (log.isDebugEnabled()) { log.debug("App state is updated to:" + newState + " in the AppInfoCache for OAuth App with " + "consumerKey: " + consumerKey); } } catch (InvalidOAuthClientException | IdentityOAuth2Exception e) { throw handleError("Error while updating state of OAuth app with consumerKey: " + consumerKey, e); } }