use of org.wso2.carbon.stratos.common.exception.StratosException in project carbon-identity-framework by wso2.
the class TenantConsentMgtListener method deleteAllConsents.
/**
* Delete all consents belongs to a given tenant id.
*
* @param tenantId The id of the tenant.
* @throws StratosException throws when an error occurs in deleting consents.
*/
protected void deleteAllConsents(int tenantId) throws StratosException {
try {
PrivilegedConsentManager privilegedConsentManager = IdentityConsentDataHolder.getInstance().getPrivilegedConsentManager();
privilegedConsentManager.deletePurposeCategories(tenantId);
privilegedConsentManager.deletePIICategories(tenantId);
privilegedConsentManager.deletePurposes(tenantId);
privilegedConsentManager.deleteReceipts(tenantId);
} catch (ConsentManagementException e) {
throw new StratosException("Error in deleting consents of tenant:" + tenantId, e);
}
}
use of org.wso2.carbon.stratos.common.exception.StratosException in project carbon-identity-framework by wso2.
the class TenantManagementListener method onTenantCreate.
/**
* Add the default Resident Identity Provider entry when a new tenant is registered.
*
* @param tenantInfo Information about the newly created tenant
*/
@Override
public void onTenantCreate(TenantInfoBean tenantInfo) throws StratosException {
try {
String tenantDomain = tenantInfo.getTenantDomain();
IdentityProvider identityProvider = new IdentityProvider();
identityProvider.setIdentityProviderName(IdentityApplicationConstants.RESIDENT_IDP_RESERVED_NAME);
identityProvider.setHomeRealmId("localhost");
identityProvider.setPrimary(true);
IdentityProviderManager.getInstance().addResidentIdP(identityProvider, tenantDomain);
} catch (IdentityProviderManagementException e) {
String message = "Error when adding Resident Identity Provider entry for tenant " + tenantInfo.getTenantDomain();
throw new StratosException(message, e);
}
}
use of org.wso2.carbon.stratos.common.exception.StratosException in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuthTenantMgtListenerImpl method clearTokenData.
private void clearTokenData(int tenantId) throws StratosException {
try {
Set<AccessTokenDO> accessTokenDOs = OAuthTokenPersistenceFactory.getInstance().getAccessTokenDAO().getAccessTokensByTenant(tenantId);
Map<String, AccessTokenDO> latestAccessTokens = new HashMap<>();
for (AccessTokenDO accessTokenDO : accessTokenDOs) {
String keyString = accessTokenDO.getConsumerKey() + ":" + accessTokenDO.getAuthzUser() + ":" + OAuth2Util.buildScopeString(accessTokenDO.getScope()) + ":" + accessTokenDO.getAuthzUser().getFederatedIdPName();
AccessTokenDO accessTokenDOFromMap = latestAccessTokens.get(keyString);
if (accessTokenDOFromMap != null) {
if (accessTokenDOFromMap.getIssuedTime().before(accessTokenDO.getIssuedTime())) {
latestAccessTokens.put(keyString, accessTokenDO);
}
} else {
latestAccessTokens.put(keyString, accessTokenDO);
}
// Clear cache
OAuthUtil.clearOAuthCache(accessTokenDO.getConsumerKey(), accessTokenDO.getAuthzUser(), OAuth2Util.buildScopeString(accessTokenDO.getScope()));
OAuthUtil.clearOAuthCache(accessTokenDO.getConsumerKey(), accessTokenDO.getAuthzUser());
OAuthUtil.clearOAuthCache(accessTokenDO);
}
ArrayList<String> tokensToRevoke = new ArrayList<>();
for (Map.Entry entry : latestAccessTokens.entrySet()) {
tokensToRevoke.add(((AccessTokenDO) entry.getValue()).getAccessToken());
}
OAuthTokenPersistenceFactory.getInstance().getAccessTokenDAO().revokeAccessTokens(tokensToRevoke.toArray(new String[tokensToRevoke.size()]), OAuth2Util.isHashEnabled());
List<AuthzCodeDO> latestAuthzCodes = OAuthTokenPersistenceFactory.getInstance().getAuthorizationCodeDAO().getLatestAuthorizationCodesByTenant(tenantId);
for (AuthzCodeDO authzCodeDO : latestAuthzCodes) {
// remove the authorization code from the cache
OAuthUtil.clearOAuthCache(authzCodeDO.getConsumerKey() + ":" + authzCodeDO.getAuthorizationCode());
}
OAuthTokenPersistenceFactory.getInstance().getAuthorizationCodeDAO().deactivateAuthorizationCodes(latestAuthzCodes);
} catch (IdentityOAuth2Exception e) {
throw new StratosException("Error occurred while revoking the access tokens in tenant " + tenantId, e);
}
}
use of org.wso2.carbon.stratos.common.exception.StratosException in project identity-inbound-auth-oauth by wso2-extensions.
the class TenantCreationEventListener method revokeTokens.
private void revokeTokens(int tenantId) throws StratosException {
try {
Set<AccessTokenDO> accessTokenDOs = OAuthTokenPersistenceFactory.getInstance().getAccessTokenDAO().getAccessTokensByTenant(tenantId);
Map<String, AccessTokenDO> latestAccessTokens = new HashMap<>();
for (AccessTokenDO accessTokenDO : accessTokenDOs) {
String keyString = accessTokenDO.getConsumerKey() + ":" + accessTokenDO.getAuthzUser() + ":" + OAuth2Util.buildScopeString(accessTokenDO.getScope()) + ":" + accessTokenDO.getAuthzUser().getFederatedIdPName();
AccessTokenDO accessTokenDOFromMap = latestAccessTokens.get(keyString);
if (accessTokenDOFromMap != null) {
if (accessTokenDOFromMap.getIssuedTime().before(accessTokenDO.getIssuedTime())) {
latestAccessTokens.put(keyString, accessTokenDO);
}
} else {
latestAccessTokens.put(keyString, accessTokenDO);
}
OAuthUtil.clearOAuthCache(accessTokenDO.getConsumerKey(), accessTokenDO.getAuthzUser(), OAuth2Util.buildScopeString(accessTokenDO.getScope()));
OAuthUtil.clearOAuthCache(accessTokenDO.getConsumerKey(), accessTokenDO.getAuthzUser());
OAuthUtil.clearOAuthCache(accessTokenDO);
}
OAuthTokenPersistenceFactory.getInstance().getAccessTokenDAO().revokeAccessTokens(latestAccessTokens.values().stream().map(AccessTokenDO::getAccessToken).toArray(String[]::new), OAuth2Util.isHashEnabled());
List<AuthzCodeDO> latestAuthzCodes = OAuthTokenPersistenceFactory.getInstance().getAuthorizationCodeDAO().getLatestAuthorizationCodesByTenant(tenantId);
// Remove the authorization code from the cache.
latestAuthzCodes.stream().map(authzCodeDO -> authzCodeDO.getConsumerKey() + ":" + authzCodeDO.getAuthorizationCode()).forEach(OAuthUtil::clearOAuthCache);
OAuthTokenPersistenceFactory.getInstance().getAuthorizationCodeDAO().deactivateAuthorizationCodes(latestAuthzCodes);
} catch (IdentityOAuth2Exception e) {
throw new StratosException("Error occurred while revoking Access Token of tenant: " + tenantId, e);
}
}
use of org.wso2.carbon.stratos.common.exception.StratosException in project identity-governance by wso2-extensions.
the class TenantManagementListener method onPreDelete.
@Override
public void onPreDelete(int tenantId) throws StratosException {
try {
UserRecoveryDataStore userRecoveryDataStore = JDBCRecoveryDataStore.getInstance();
userRecoveryDataStore.deleteRecoveryDataByTenantId(tenantId);
} catch (IdentityRecoveryException e) {
throw new StratosException("Error in deleting recovery data of the tenant:" + tenantId, e);
}
}
Aggregations