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

Fix not properly returning error messages and error descriptions for idp mgt #752

Merged
merged 2 commits into from
Dec 4, 2024
Merged
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 @@ -3262,6 +3262,10 @@ private APIError handleIdPException(IdentityProviderManagementException e,
errorResponse = getErrorBuilder(errorEnum, data).build(log, e.getMessage());
}
errorResponse.setDescription(e.getMessage());
IdentityProviderManagementClientException clientException = (IdentityProviderManagementClientException) e;
if (StringUtils.isNotEmpty(clientException.getDescription())) {
errorResponse.setDescription(clientException.getDescription());
}
status = Response.Status.BAD_REQUEST;
} else if (e instanceof IdentityProviderManagementServerException) {
if (e.getErrorCode() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ private static void validateSystemDefinedFederatedAuthenticatorModel(Config conf
// The System-defined authenticator configs must not have endpoint configurations; throw an error if they do.
if (config.endpoint != null) {
Constants.ErrorMessage error = Constants.ErrorMessage.ERROR_CODE_ENDPOINT_PROVIDED_FOR_SYSTEM_AUTH;
throw new IdentityProviderManagementClientException(error.getCode(), String.format(error.getDescription(),
config.authenticatorName));
throw new IdentityProviderManagementClientException(error.getCode(), error.getMessage(),
String.format(error.getDescription(), config.authenticatorName));
}

validateAuthenticatorProperties(config.authenticatorName, config.properties);
Expand All @@ -199,7 +199,8 @@ private static UserDefinedFederatedAuthenticatorConfig createUserDefinedFederate
return authConfig;
} catch (NoSuchElementException | IllegalArgumentException e) {
throw new IdentityProviderManagementClientException(Constants.ErrorMessage
.ERROR_CODE_INVALID_INPUT.getCode(), e.getMessage());
.ERROR_CODE_INVALID_INPUT.getCode(), Constants.ErrorMessage.ERROR_CODE_INVALID_INPUT.getMessage(),
e.getMessage());
}
}

Expand All @@ -209,14 +210,14 @@ private static void validateUserDefinedFederatedAuthenticatorModel(Config config
// The User-defined authenticator configs must not have properties configurations; throw an error if they do.
if (config.properties != null) {
Constants.ErrorMessage error = Constants.ErrorMessage.ERROR_CODE_PROPERTIES_PROVIDED_FOR_USER_AUTH;
throw new IdentityProviderManagementClientException(error.getCode(),
throw new IdentityProviderManagementClientException(error.getCode(), error.getMessage(),
String.format(error.getDescription(), config.authenticatorName));
}

// The User-defined authenticator configs must have endpoint configurations; throw an error if they don't.
if (config.endpoint == null) {
Constants.ErrorMessage error = Constants.ErrorMessage.ERROR_CODE_NO_ENDPOINT_PROVIDED;
throw new IdentityProviderManagementClientException(error.getCode(),
throw new IdentityProviderManagementClientException(error.getCode(), error.getMessage(),
String.format(error.getDescription(), config.authenticatorName));
}
}
Expand All @@ -238,7 +239,8 @@ private static void validateAuthenticatorProperties(String authenticatorName, Li

if (!areAllDistinct(properties)) {
Constants.ErrorMessage error = Constants.ErrorMessage.ERROR_CODE_INVALID_INPUT;
throw new IdentityProviderManagementClientException(error.getCode(), error.getDescription());
throw new IdentityProviderManagementClientException(error.getCode(), error.getMessage(),
error.getDescription());
}
}

Expand Down Expand Up @@ -282,7 +284,8 @@ private static void validateSamlMetadata(List<Property> samlAuthenticatorPropert
samlAuthenticatorProperties.set(positionOfMetadataKey, metadataProperty);
} else {
Constants.ErrorMessage error = Constants.ErrorMessage.ERROR_CODE_INVALID_SAML_METADATA;
throw new IdentityProviderManagementClientException(error.getCode(), error.getDescription());
throw new IdentityProviderManagementClientException(error.getCode(), error.getMessage(),
error.getDescription());
}
}
}
Expand Down Expand Up @@ -313,7 +316,8 @@ private static void validateDuplicateOpenIDConnectScopes(List<Property> oidcAuth
}
if (scopesFieldFilled && queryParamsScopesFilled) {
Constants.ErrorMessage error = Constants.ErrorMessage.ERROR_CODE_DUPLICATE_OIDC_SCOPES;
throw new IdentityProviderManagementClientException(error.getCode(), error.getDescription());
throw new IdentityProviderManagementClientException(error.getCode(), error.getMessage(),
error.getDescription());
}
}
}
Expand All @@ -333,7 +337,8 @@ private static void validateDefaultOpenIDConnectScopes(List<Property> oidcAuthen
String scopes = oidcAuthenticatorProperty.getValue();
if (StringUtils.isNotBlank(scopes) && !scopes.contains("openid")) {
Constants.ErrorMessage error = Constants.ErrorMessage.ERROR_CODE_INVALID_OIDC_SCOPES;
throw new IdentityProviderManagementClientException(error.getCode(), error.getDescription());
throw new IdentityProviderManagementClientException(error.getCode(), error.getMessage(),
error.getDescription());
}
}
}
Expand Down Expand Up @@ -389,7 +394,8 @@ private static String getDisplayNameOfAuthenticator(String authenticatorName)
}
} catch (IdentityProviderManagementException e) {
Constants.ErrorMessage error = Constants.ErrorMessage.ERROR_CODE_ERROR_ADDING_IDP;
throw new IdentityProviderManagementClientException(error.getCode(), error.getDescription());
throw new IdentityProviderManagementClientException(error.getCode(), error.getMessage(),
error.getDescription());
}
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@
<maven.buildnumber.plugin.version>1.4</maven.buildnumber.plugin.version>
<org.apache.felix.annotations.version>1.2.4</org.apache.felix.annotations.version>
<identity.governance.version>1.11.11</identity.governance.version>
<carbon.identity.framework.version>7.7.16</carbon.identity.framework.version>
<carbon.identity.framework.version>7.7.18</carbon.identity.framework.version>
<maven.findbugsplugin.version>3.0.5</maven.findbugsplugin.version>
<findsecbugs-plugin.version>1.12.0</findsecbugs-plugin.version>
<maven.checkstyleplugin.excludes>**/gen/**/*</maven.checkstyleplugin.excludes>
Expand Down
Loading