use of org.commonjava.indy.util.ApplicationStatus in project indy by Commonjava.
the class KeycloakProxyAuthenticator method sendChallengeResponse.
// protected void sendClientCertChallenge(HttpWrapper exchange) {
// return new AuthChallenge() {
// @Override
// public boolean errorPage() {
// return false;
// }
//
// @Override
// public boolean challenge(HttpFacade exchange) {
// // do the same thing as client cert auth
// return false;
// }
// };
// }
protected void sendChallengeResponse(HttpWrapper http, String error, String description) throws IOException {
StringBuilder header = new StringBuilder("Bearer realm=\"");
header.append(httproxConfig.getProxyRealm()).append("\"");
if (error != null) {
header.append(", error=\"").append(error).append("\"");
}
if (description != null) {
header.append(", error_description=\"").append(description).append("\"");
}
final String challenge = header.toString();
ApplicationStatus stat = ApplicationStatus.UNAUTHORIZED;
http.writeStatus(stat.code(), stat.message());
http.writeHeader("WWW-Authenticate", challenge);
}
use of org.commonjava.indy.util.ApplicationStatus in project indy by Commonjava.
the class ContentAccessHandler method doDelete.
public Response doDelete(final String packageType, final String type, final String name, final String path, EventMetadata eventMetadata, final Consumer<ResponseBuilder> builderModifier) {
if (!PackageTypes.contains(packageType)) {
ResponseBuilder builder = Response.status(400);
if (builderModifier != null) {
builderModifier.accept(builder);
}
return builder.build();
}
final StoreType st = StoreType.get(type);
StoreKey sk = new StoreKey(packageType, st, name);
eventMetadata = eventMetadata.set(ContentManager.ENTRY_POINT_STORE, sk);
Response response;
try {
final ApplicationStatus result = contentController.delete(st, name, path, eventMetadata);
ResponseBuilder builder = Response.status(result.code());
if (builderModifier != null) {
builderModifier.accept(builder);
}
response = builder.build();
} catch (final IndyWorkflowException e) {
logger.error(String.format("Failed to tryDelete artifact: %s from: %s. Reason: %s", path, name, e.getMessage()), e);
response = formatResponse(e, builderModifier);
}
return response;
}
use of org.commonjava.indy.util.ApplicationStatus in project indy by Commonjava.
the class ResponseUtils method formulateResponse.
private static Response formulateResponse(final ApplicationStatus status, final Throwable error, final String message, final boolean throwIt, Consumer<ResponseBuilder> builderModifier) {
final String id = generateErrorId();
final String msg = formatEntity(id, error, message).toString();
Status code = Status.INTERNAL_SERVER_ERROR;
if (status != null) {
code = Status.fromStatusCode(status.code());
LOGGER.debug("got error code from parameter: {}", code);
} else if ((error instanceof IndyWorkflowException) && ((IndyWorkflowException) error).getStatus() > 0) {
final int sc = ((IndyWorkflowException) error).getStatus();
LOGGER.debug("got error code from exception: {}", sc);
code = Status.fromStatusCode(sc);
}
LOGGER.error("Sending error response: {} {}\n{}", code.getStatusCode(), code.getReasonPhrase(), msg);
ResponseBuilder builder = Response.status(code).type(MediaType.TEXT_PLAIN).entity(msg);
if (builderModifier != null) {
builderModifier.accept(builder);
}
Response response = builder.build();
if (throwIt) {
throw new WebApplicationException(error, response);
}
return response;
}
Aggregations