fix: adds a general error message and descriptions for some exceptions (#25806)
closes: #25746 Signed-off-by: Steve Hawkins <shawkins@redhat.com>
This commit is contained in:
parent
a64c00dbef
commit
d1d1d69840
5 changed files with 15 additions and 10 deletions
|
@ -85,6 +85,7 @@ public class KeycloakErrorHandler implements ExceptionMapper<Throwable> {
|
||||||
OAuth2ErrorRepresentation error = new OAuth2ErrorRepresentation();
|
OAuth2ErrorRepresentation error = new OAuth2ErrorRepresentation();
|
||||||
|
|
||||||
error.setError(getErrorCode(throwable));
|
error.setError(getErrorCode(throwable));
|
||||||
|
error.setErrorDescription("For more on this error consult the server log at the debug level.");
|
||||||
|
|
||||||
return Response.status(statusCode)
|
return Response.status(statusCode)
|
||||||
.header(HttpHeaders.CONTENT_TYPE, jakarta.ws.rs.core.MediaType.APPLICATION_JSON_TYPE.toString())
|
.header(HttpHeaders.CONTENT_TYPE, jakarta.ws.rs.core.MediaType.APPLICATION_JSON_TYPE.toString())
|
||||||
|
|
|
@ -197,7 +197,9 @@ public class ClientAttributeCertificateResource {
|
||||||
CertificateRepresentation info = new CertificateRepresentation();
|
CertificateRepresentation info = new CertificateRepresentation();
|
||||||
MultivaluedMap<String, FormPartValue> uploadForm = session.getContext().getHttpRequest().getMultiPartFormParameters();
|
MultivaluedMap<String, FormPartValue> uploadForm = session.getContext().getHttpRequest().getMultiPartFormParameters();
|
||||||
FormPartValue keystoreFormatPart = uploadForm.getFirst("keystoreFormat");
|
FormPartValue keystoreFormatPart = uploadForm.getFirst("keystoreFormat");
|
||||||
if (keystoreFormatPart == null) throw new BadRequestException();
|
if (keystoreFormatPart == null) {
|
||||||
|
throw new BadRequestException("keystoreFormat cannot be null");
|
||||||
|
}
|
||||||
String keystoreFormat = keystoreFormatPart.asString();
|
String keystoreFormat = keystoreFormatPart.asString();
|
||||||
FormPartValue inputParts = uploadForm.getFirst("file");
|
FormPartValue inputParts = uploadForm.getFirst("file");
|
||||||
if (keystoreFormat.equals(CERTIFICATE_PEM)) {
|
if (keystoreFormat.equals(CERTIFICATE_PEM)) {
|
||||||
|
|
|
@ -145,7 +145,7 @@ public class ComponentResource {
|
||||||
} catch (ComponentValidationException e) {
|
} catch (ComponentValidationException e) {
|
||||||
return localizedErrorResponse(e);
|
return localizedErrorResponse(e);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new BadRequestException(e);
|
throw new BadRequestException("Invalid provider type or no such provider", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ public class ComponentResource {
|
||||||
} catch (ComponentValidationException e) {
|
} catch (ComponentValidationException e) {
|
||||||
return localizedErrorResponse(e);
|
return localizedErrorResponse(e);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new BadRequestException();
|
throw new BadRequestException("Invalid provider type or no such provider", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@DELETE
|
@DELETE
|
||||||
|
|
|
@ -143,7 +143,7 @@ public class RoleContainerResource extends RoleResource {
|
||||||
auth.roles().requireManage(roleContainer);
|
auth.roles().requireManage(roleContainer);
|
||||||
|
|
||||||
if (rep.getName() == null) {
|
if (rep.getName() == null) {
|
||||||
throw new BadRequestException();
|
throw new BadRequestException("role has no name");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -26,7 +26,6 @@ import org.keycloak.util.JsonSerialization;
|
||||||
import org.keycloak.utils.MediaType;
|
import org.keycloak.utils.MediaType;
|
||||||
import org.openqa.selenium.By;
|
import org.openqa.selenium.By;
|
||||||
|
|
||||||
import jakarta.ws.rs.core.Response;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
@ -38,10 +37,13 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import jakarta.ws.rs.core.Response;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
import static org.hamcrest.core.Is.is;
|
import static org.hamcrest.core.Is.is;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.keycloak.utils.MediaType.APPLICATION_JSON;
|
import static org.keycloak.utils.MediaType.APPLICATION_JSON;
|
||||||
|
@ -95,7 +97,7 @@ public class UncaughtErrorPageTest extends AbstractKeycloakTest {
|
||||||
|
|
||||||
OAuth2ErrorRepresentation error = JsonSerialization.readValue(response.getEntity().getContent(), OAuth2ErrorRepresentation.class);
|
OAuth2ErrorRepresentation error = JsonSerialization.readValue(response.getEntity().getContent(), OAuth2ErrorRepresentation.class);
|
||||||
assertEquals(OAuthErrorException.INVALID_REQUEST, error.getError());
|
assertEquals(OAuthErrorException.INVALID_REQUEST, error.getError());
|
||||||
assertNull(error.getErrorDescription());
|
assertNotNull(error.getErrorDescription());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +117,7 @@ public class UncaughtErrorPageTest extends AbstractKeycloakTest {
|
||||||
|
|
||||||
OAuth2ErrorRepresentation error = JsonSerialization.readValue(response.getEntity().getContent(), OAuth2ErrorRepresentation.class);
|
OAuth2ErrorRepresentation error = JsonSerialization.readValue(response.getEntity().getContent(), OAuth2ErrorRepresentation.class);
|
||||||
assertEquals(OAuthErrorException.INVALID_REQUEST, error.getError());
|
assertEquals(OAuthErrorException.INVALID_REQUEST, error.getError());
|
||||||
assertNull(error.getErrorDescription());
|
assertNotNull(error.getErrorDescription());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue