Search in sources :

Example 1 with ApplicationStatus

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);
}
Also used : ApplicationStatus(org.commonjava.indy.util.ApplicationStatus)

Example 2 with ApplicationStatus

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;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) ApplicationStatus(org.commonjava.indy.util.ApplicationStatus) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 3 with ApplicationStatus

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;
}
Also used : ApplicationStatus(org.commonjava.indy.util.ApplicationStatus) Status(javax.ws.rs.core.Response.Status) Response(javax.ws.rs.core.Response) WebApplicationException(javax.ws.rs.WebApplicationException) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder)

Aggregations

ApplicationStatus (org.commonjava.indy.util.ApplicationStatus)3 Response (javax.ws.rs.core.Response)2 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)2 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)2 WebApplicationException (javax.ws.rs.WebApplicationException)1 Status (javax.ws.rs.core.Response.Status)1 ResponseUtils.formatResponse (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse)1 StoreKey (org.commonjava.indy.model.core.StoreKey)1 StoreType (org.commonjava.indy.model.core.StoreType)1