Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error codes for user defined local authenticator mgt #760

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ public enum ErrorMessage {
"Filter needs to be in the format <attribute>+<operation>+<value>. Eg: tag+eq+2FA"),
ERROR_CODE_UNSUPPORTED_FILTER_ATTRIBUTE("60002", "Unsupported filter attribute.",
"The filter attribute '%s' is not supported."),
ERROR_CODE_INVALID_ENDPOINT_CONFIG("60003", "Invalid endpoint configuration provided.",
"Invalid endpoint configuration is provided for the authenticator %s."),
ERROR_CODE_ERROR_AUTHENTICATOR_NOT_FOUND("60004", "Authenticator not found.",
"Authenticator not found by the given name: %s."),

ERROR_CODE_ERROR_LISTING_AUTHENTICATORS("65001", "Unable to list the existing authenticators.",
"Server encountered an error while listing the authenticators."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig;
import org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig;
import org.wso2.carbon.identity.application.common.model.UserDefinedLocalAuthenticatorConfig;
import org.wso2.carbon.identity.application.common.util.AuthenticatorMgtExceptionBuilder.AuthenticatorMgtError;
import org.wso2.carbon.identity.base.AuthenticatorPropertyConstants.DefinedByType;
import org.wso2.carbon.identity.base.IdentityException;
import org.wso2.carbon.identity.core.model.ExpressionNode;
Expand Down Expand Up @@ -265,8 +266,10 @@ public Authenticator updateUserDefinedLocalAuthenticator(
LocalAuthenticatorConfig existingAuthenticator = getApplicationAuthenticatorService()
.getLocalAuthenticatorByName(authenticatorName, tenantDomain);
if (existingAuthenticator == null) {
throw handleException(Response.Status.NOT_FOUND,
Constants.ErrorMessage.ERROR_CODE_ERROR_AUTHENTICATOR_NOT_FOUND, authenticatorName);
AuthenticatorMgtError error = AuthenticatorMgtError.ERROR_CODE_ERROR_AUTHENTICATOR_NOT_FOUND;
throw handleAuthenticatorException(new AuthenticatorMgtClientException(error.getCode(),
error.getMessage(), String.format(error.getMessage(), authenticatorName)),
Response.Status.NOT_FOUND);
}
UserDefinedLocalAuthenticatorConfig updatedConfig = getApplicationAuthenticatorService()
.updateUserDefinedLocalAuthenticator(
Expand Down Expand Up @@ -1008,13 +1011,16 @@ private APIError handleIdPException(IdentityProviderManagementException e,
* @param e IdentityProviderManagementException.
* @return APIError.
*/
private APIError handleAuthenticatorException(AuthenticatorMgtException e) {
private APIError handleAuthenticatorException(AuthenticatorMgtException e, Response.Status... responseStatus) {

ErrorResponse.Builder errorResponseBuilder = new ErrorResponse.Builder()
.withCode(e.getErrorCode())
.withMessage(e.getMessage())
.withDescription(e.getDescription());
Response.Status status;
Response.Status status = null;
if (ArrayUtils.isNotEmpty(responseStatus)) {
status = responseStatus[0];
}
ErrorResponse errorResponse;

if (e instanceof AuthenticatorMgtClientException) {
Expand All @@ -1027,7 +1033,9 @@ private APIError handleAuthenticatorException(AuthenticatorMgtException e) {
errorResponse.setCode(errorCode);
}
errorResponse.setDescription(e.getDescription());
status = Response.Status.BAD_REQUEST;
if (status == null) {
status = Response.Status.BAD_REQUEST;
}
} else if (e instanceof AuthenticatorMgtServerException) {
errorResponse = errorResponseBuilder.build(log, e, e.getMessage());
if (e.getErrorCode() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package org.wso2.carbon.identity.api.server.authenticators.v1.impl;

import org.wso2.carbon.identity.api.server.authenticators.common.Constants;
import org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator;
import org.wso2.carbon.identity.api.server.authenticators.v1.model.Endpoint;
import org.wso2.carbon.identity.api.server.authenticators.v1.model.UserDefinedLocalAuthenticatorCreation;
Expand All @@ -28,6 +27,7 @@
import org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig;
import org.wso2.carbon.identity.application.common.model.UserDefinedAuthenticatorEndpointConfig;
import org.wso2.carbon.identity.application.common.model.UserDefinedLocalAuthenticatorConfig;
import org.wso2.carbon.identity.application.common.util.AuthenticatorMgtExceptionBuilder.AuthenticatorMgtError;
import org.wso2.carbon.identity.base.AuthenticatorPropertyConstants;

import java.util.Arrays;
Expand All @@ -36,7 +36,6 @@
import java.util.stream.Collectors;

import static org.wso2.carbon.identity.api.server.authenticators.common.Constants.CONFIGS_AUTHENTICATOR_PATH_COMPONENT;
import static org.wso2.carbon.identity.api.server.authenticators.common.Constants.ErrorMessage.ERROR_CODE_INVALID_ENDPOINT_CONFIG;
import static org.wso2.carbon.identity.api.server.common.Constants.V1_API_PATH_COMPONENT;
import static org.wso2.carbon.identity.api.server.common.Util.base64URLEncode;

Expand Down Expand Up @@ -128,7 +127,7 @@ private static UserDefinedAuthenticatorEndpointConfig buildEndpointConfig(Endpoi
Map.Entry::getKey, entry -> entry.getValue().toString())));
return endpointConfigBuilder.build();
} catch (NoSuchElementException | IllegalArgumentException e) {
Constants.ErrorMessage error = ERROR_CODE_INVALID_ENDPOINT_CONFIG;
AuthenticatorMgtError error = AuthenticatorMgtError.ERROR_CODE_INVALID_ENDPOINT_CONFIG;
throw new AuthenticatorMgtClientException(error.getCode(), error.getMessage(), e.getMessage());
}
}
Expand Down
Loading