diff --git a/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/IdPManagementFacade.java b/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/IdPManagementFacade.java index 8d342de4299d..d81da034e0ab 100644 --- a/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/IdPManagementFacade.java +++ b/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/IdPManagementFacade.java @@ -311,7 +311,7 @@ public List getAllUserDefinedFederatedAuthenticato } private IdentityProvider populateEndpointConfig(IdentityProvider identityProvider, String tenantDomain) - throws IdentityProviderManagementServerException { + throws IdentityProviderManagementException { if (identityProvider == null || identityProvider.getFederatedAuthenticatorConfigs().length != 1) { return identityProvider; @@ -322,7 +322,7 @@ private IdentityProvider populateEndpointConfig(IdentityProvider identityProvide } private void addEndpointConfig(IdentityProvider identityProvider, String tenantDomain) - throws IdentityProviderManagementServerException { + throws IdentityProviderManagementException { if (identityProvider == null || identityProvider.getFederatedAuthenticatorConfigs().length != 1) { return; @@ -333,7 +333,7 @@ private void addEndpointConfig(IdentityProvider identityProvider, String tenantD private void updateEndpointConfig(IdentityProvider newIdentityProvider, IdentityProvider oldIdentityProvider, String tenantDomain) - throws IdentityProviderManagementServerException { + throws IdentityProviderManagementException { if (newIdentityProvider == null || newIdentityProvider.getFederatedAuthenticatorConfigs().length != 1) { return; @@ -354,7 +354,7 @@ private void updateEndpointConfig(IdentityProvider newIdentityProvider, Identity } private void deleteEndpointConfig(IdentityProvider identityProvider, String tenantDomain) - throws IdentityProviderManagementServerException { + throws IdentityProviderManagementException { if (identityProvider == null || identityProvider.getFederatedAuthenticatorConfigs().length != 1) { return; diff --git a/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/util/UserDefinedAuthenticatorEndpointConfigManager.java b/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/util/UserDefinedAuthenticatorEndpointConfigManager.java index e0d8e656ace0..0c10c854c771 100644 --- a/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/util/UserDefinedAuthenticatorEndpointConfigManager.java +++ b/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/util/UserDefinedAuthenticatorEndpointConfigManager.java @@ -18,6 +18,7 @@ package org.wso2.carbon.idp.mgt.util; +import org.wso2.carbon.identity.action.management.exception.ActionMgtClientException; import org.wso2.carbon.identity.action.management.exception.ActionMgtException; import org.wso2.carbon.identity.action.management.model.Action; import org.wso2.carbon.identity.action.management.model.EndpointConfig; @@ -26,6 +27,8 @@ import org.wso2.carbon.identity.application.common.model.UserDefinedAuthenticatorEndpointConfig; import org.wso2.carbon.identity.application.common.model.UserDefinedFederatedAuthenticatorConfig; import org.wso2.carbon.identity.base.AuthenticatorPropertyConstants; +import org.wso2.carbon.idp.mgt.IdentityProviderManagementClientException; +import org.wso2.carbon.idp.mgt.IdentityProviderManagementException; import org.wso2.carbon.idp.mgt.IdentityProviderManagementServerException; import org.wso2.carbon.idp.mgt.internal.IdpMgtServiceComponentHolder; import org.wso2.carbon.idp.mgt.util.IdPManagementConstants.ErrorMessage; @@ -50,7 +53,7 @@ public class UserDefinedAuthenticatorEndpointConfigManager { * @throws IdentityProviderManagementServerException If an error occurs while adding the action. */ public void addEndpointConfig(FederatedAuthenticatorConfig config, String tenantDomain) - throws IdentityProviderManagementServerException { + throws IdentityProviderManagementException { if (config.getDefinedByType() != AuthenticatorPropertyConstants.DefinedByType.USER) { return; @@ -69,9 +72,7 @@ public void addEndpointConfig(FederatedAuthenticatorConfig config, String tenant endpointProperty.setConfidential(false); config.setProperties(new Property[]{endpointProperty}); } catch (ActionMgtException e) { - ErrorMessage error = ErrorMessage.ERROR_CODE_ADDING_ENDPOINT_CONFIG; - throw new IdentityProviderManagementServerException(error.getCode(), String.format(error.getMessage(), - config.getName()), e); + throw handleActionMgtException(ErrorMessage.ERROR_CODE_ADDING_ENDPOINT_CONFIG, e, config.getName()); } } @@ -84,7 +85,7 @@ public void addEndpointConfig(FederatedAuthenticatorConfig config, String tenant * @throws IdentityProviderManagementServerException If an error occurs while updating associated action. */ public void updateEndpointConfig(FederatedAuthenticatorConfig newConfig, FederatedAuthenticatorConfig oldConfig, - String tenantDomain) throws IdentityProviderManagementServerException { + String tenantDomain) throws IdentityProviderManagementException { if (oldConfig.getDefinedByType() != AuthenticatorPropertyConstants.DefinedByType.USER) { return; @@ -100,9 +101,7 @@ public void updateEndpointConfig(FederatedAuthenticatorConfig newConfig, Federat tenantDomain); newConfig.setProperties(oldConfig.getProperties()); } catch (ActionMgtException e) { - ErrorMessage error = ErrorMessage.ERROR_CODE_UPDATING_ENDPOINT_CONFIG; - throw new IdentityProviderManagementServerException(error.getCode(), String.format(error.getMessage(), - newConfig.getName()), e); + throw handleActionMgtException(ErrorMessage.ERROR_CODE_UPDATING_ENDPOINT_CONFIG, e, newConfig.getName()); } } @@ -115,7 +114,7 @@ public void updateEndpointConfig(FederatedAuthenticatorConfig newConfig, Federat * @throws IdentityProviderManagementServerException If an error occurs retrieving updating associated action. */ public FederatedAuthenticatorConfig resolveEndpointConfig(FederatedAuthenticatorConfig config, - String tenantDomain) throws IdentityProviderManagementServerException { + String tenantDomain) throws IdentityProviderManagementException { if (config.getDefinedByType() != AuthenticatorPropertyConstants.DefinedByType.USER) { return config; @@ -132,9 +131,7 @@ public FederatedAuthenticatorConfig resolveEndpointConfig(FederatedAuthenticator castedConfig.setEndpointConfig(buildUserDefinedAuthenticatorEndpointConfig(action.getEndpoint())); return castedConfig; } catch (ActionMgtException e) { - ErrorMessage error = ErrorMessage.ERROR_CODE_RETRIEVING_ENDPOINT_CONFIG; - throw new IdentityProviderManagementServerException(error.getCode(), String.format(error.getMessage(), - config.getName()), e); + throw handleActionMgtException(ErrorMessage.ERROR_CODE_RETRIEVING_ENDPOINT_CONFIG, e, config.getName()); } } @@ -160,7 +157,7 @@ private UserDefinedAuthenticatorEndpointConfig buildUserDefinedAuthenticatorEndp * @throws IdentityProviderManagementServerException If an error occurs while deleting associated action. */ public void deleteEndpointConfig(FederatedAuthenticatorConfig config, String tenantDomain) throws - IdentityProviderManagementServerException { + IdentityProviderManagementException { if (config.getDefinedByType() != AuthenticatorPropertyConstants.DefinedByType.USER) { return; @@ -173,9 +170,7 @@ public void deleteEndpointConfig(FederatedAuthenticatorConfig config, String ten actionId, tenantDomain); } catch (ActionMgtException e) { - ErrorMessage error = ErrorMessage.ERROR_CODE_DELETING_ENDPOINT_CONFIG; - throw new IdentityProviderManagementServerException(error.getCode(), String.format(error.getMessage(), - config.getName()), e); + throw handleActionMgtException(ErrorMessage.ERROR_CODE_DELETING_ENDPOINT_CONFIG, e, config.getName()); } } @@ -209,4 +204,18 @@ private String getActionIdFromProperty(Property[] properties, String authenticat "No action Id was found in the properties of the authenticator configurations for the " + "authenticator: " + authenticatorName)); } + + private static IdentityProviderManagementClientException handleActionMgtException(ErrorMessage idpMgtError, + Throwable actionException, String... data) + throws IdentityProviderManagementException { + + if (actionException instanceof ActionMgtClientException) { + ActionMgtClientException error = (ActionMgtClientException) actionException; + throw new IdentityProviderManagementClientException( + idpMgtError.getCode(), idpMgtError.getMessage(), error.getDescription()); + } + + throw new IdentityProviderManagementServerException(idpMgtError.getCode(), + String.format(idpMgtError.getMessage(), data), actionException); + } }