Skip to content

Commit

Permalink
Improve error codes for user defined federated authenticator mgt.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Dec 17, 2024
1 parent 8960263 commit d7648c8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public List<FederatedAuthenticatorConfig> getAllUserDefinedFederatedAuthenticato
}

private IdentityProvider populateEndpointConfig(IdentityProvider identityProvider, String tenantDomain)
throws IdentityProviderManagementServerException {
throws IdentityProviderManagementException {

if (identityProvider == null || identityProvider.getFederatedAuthenticatorConfigs().length != 1) {
return identityProvider;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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());
}
}

Expand All @@ -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;
Expand All @@ -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());
}
}

Expand All @@ -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;
Expand All @@ -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());
}
}

Expand All @@ -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;
Expand All @@ -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());
}
}

Expand Down Expand Up @@ -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);
}
}

0 comments on commit d7648c8

Please sign in to comment.