made JWTAuthentication filter work again. Ensured realms not supporting
the JTWtoken based are not considdered when logging in via API key
This commit is contained in:
@ -43,6 +43,10 @@ public class APIExceptionInterceptor {
|
||||
// if an exception is thrown during processing, this is passed in to the catch block below
|
||||
proceedResponse = context.proceed();
|
||||
} catch (Exception ex) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Detailed stacktrace", new Object[]{ex});
|
||||
}
|
||||
|
||||
Response errorResponse;
|
||||
if (ex instanceof APIException) {
|
||||
errorResponse = ((APIException) ex).getHttpResponse();
|
||||
@ -56,12 +60,7 @@ public class APIExceptionInterceptor {
|
||||
throw (ConstraintViolationException) ex.getCause();
|
||||
} else {
|
||||
errorResponse = new APIException(ex, locale).getHttpResponse();
|
||||
}
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(ex.toString(), ex);
|
||||
}
|
||||
|
||||
}
|
||||
return errorResponse;
|
||||
}
|
||||
return proceedResponse;
|
||||
|
||||
@ -1,63 +1,63 @@
|
||||
/*
|
||||
* Copyright 2018 jomu.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package de.muehlencord.shared.jeeutil.restexfw;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.GenericEntity;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Request;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Variant;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jomu
|
||||
*/
|
||||
@Provider
|
||||
public class ConstraintViolationMapper implements ExceptionMapper<ConstraintViolationException> {
|
||||
|
||||
private static List<Variant> acceptableMediaTypes = Variant.mediaTypes(MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_XML_TYPE).build();
|
||||
|
||||
@Context
|
||||
protected Request request;
|
||||
|
||||
@Override
|
||||
public Response toResponse(ConstraintViolationException ex) {
|
||||
Set<ConstraintViolation<?>> constViolations = ex.getConstraintViolations();
|
||||
List<ConstraintViolationEntry> errorList = new ArrayList<>();
|
||||
for (ConstraintViolation<?> constraintViolation : constViolations) {
|
||||
errorList.add(new ConstraintViolationEntry(constraintViolation));
|
||||
}
|
||||
GenericEntity<List<ConstraintViolationEntry>> entity = new GenericEntity<List<ConstraintViolationEntry>>(errorList) {};
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(entity).type(getNegotiatedMediaType()).build();
|
||||
}
|
||||
|
||||
protected MediaType getNegotiatedMediaType() {
|
||||
final Variant selectedMediaType = request.selectVariant(acceptableMediaTypes);
|
||||
if (selectedMediaType == null) {
|
||||
return MediaType.APPLICATION_JSON_TYPE;
|
||||
}
|
||||
return selectedMediaType.getMediaType();
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2018 jomu.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package de.muehlencord.shared.jeeutil.restexfw;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.GenericEntity;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Request;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Variant;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jomu
|
||||
*/
|
||||
@Provider
|
||||
public class ConstraintViolationMapper implements ExceptionMapper<ConstraintViolationException> {
|
||||
|
||||
private static final List<Variant> ACCEPTABLE_MEDIA_TYPES = Variant.mediaTypes(MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_XML_TYPE).build();
|
||||
|
||||
@Context
|
||||
protected Request request;
|
||||
|
||||
@Override
|
||||
public Response toResponse(ConstraintViolationException ex) {
|
||||
Set<ConstraintViolation<?>> constViolations = ex.getConstraintViolations();
|
||||
List<ConstraintViolationEntry> errorList = new ArrayList<>();
|
||||
constViolations.forEach((constraintViolation) -> {
|
||||
errorList.add(new ConstraintViolationEntry(constraintViolation));
|
||||
});
|
||||
GenericEntity<List<ConstraintViolationEntry>> entity = new GenericEntity<List<ConstraintViolationEntry>>(errorList) {};
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(entity).type(getNegotiatedMediaType()).build();
|
||||
}
|
||||
|
||||
protected MediaType getNegotiatedMediaType() {
|
||||
final Variant selectedMediaType = request.selectVariant(ACCEPTABLE_MEDIA_TYPES);
|
||||
if (selectedMediaType == null) {
|
||||
return MediaType.APPLICATION_JSON_TYPE;
|
||||
}
|
||||
return selectedMediaType.getMediaType();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user