org.jboss.resteasy.spi.HttpResponse Java Examples

The following examples show how to use org.jboss.resteasy.spi.HttpResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CookieHelper.java    From keycloak with Apache License 2.0 6 votes vote down vote up
/**
 * Set a response cookie.  This solely exists because JAX-RS 1.1 does not support setting HttpOnly cookies
 * @param name
 * @param value
 * @param path
 * @param domain
 * @param comment
 * @param maxAge
 * @param secure
 * @param httpOnly
 * @param sameSite
 */
public static void addCookie(String name, String value, String path, String domain, String comment, int maxAge, boolean secure, boolean httpOnly, SameSiteAttributeValue sameSite) {
    SameSiteAttributeValue sameSiteParam = sameSite;
    // when expiring a cookie we shouldn't set the sameSite attribute; if we set e.g. SameSite=None when expiring a cookie, the new cookie (with maxAge == 0)
    // might be rejected by the browser in some cases resulting in leaving the original cookie untouched; that can even prevent user from accessing their application
    if (maxAge == 0) {
        sameSite = null;
    }

    boolean secure_sameSite = sameSite == SameSiteAttributeValue.NONE || secure; // when SameSite=None, Secure attribute must be set

    HttpResponse response = Resteasy.getContextData(HttpResponse.class);
    StringBuffer cookieBuf = new StringBuffer();
    ServerCookie.appendCookieValue(cookieBuf, 1, name, value, path, domain, comment, maxAge, secure_sameSite, httpOnly, sameSite);
    String cookie = cookieBuf.toString();
    response.getOutputHeaders().add(HttpHeaders.SET_COOKIE, cookie);

    // a workaround for browser in older Apple OSs – browsers ignore cookies with SameSite=None
    if (sameSiteParam == SameSiteAttributeValue.NONE) {
        addCookie(name + LEGACY_COOKIE, value, path, domain, comment, maxAge, secure, httpOnly, null);
    }
}
 
Example #2
Source File: ClientInitialAccessResource.java    From keycloak with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new initial access token.
 *
 * @param config
 * @return
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public ClientInitialAccessPresentation create(ClientInitialAccessCreatePresentation config, @Context final HttpResponse response) {
    auth.clients().requireManage();

    int expiration = config.getExpiration() != null ? config.getExpiration() : 0;
    int count = config.getCount() != null ? config.getCount() : 1;

    ClientInitialAccessModel clientInitialAccessModel = session.realms().createClientInitialAccessModel(realm, expiration, count);

    adminEvent.operation(OperationType.CREATE).resourcePath(session.getContext().getUri(), clientInitialAccessModel.getId()).representation(config).success();

    ClientInitialAccessPresentation rep = wrap(clientInitialAccessModel);

    String token = ClientRegistrationTokenUtils.createInitialAccessToken(session, realm, clientInitialAccessModel);
    rep.setToken(token);

    response.setStatus(Response.Status.CREATED.getStatusCode());
    response.getOutputHeaders().add(HttpHeaders.LOCATION, session.getContext().getUri().getAbsolutePathBuilder().path(clientInitialAccessModel.getId()).build().toString());

    return rep;
}
 
Example #3
Source File: QuarkusConstructorInjector.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public Object construct(HttpRequest request, HttpResponse response, boolean unwrapAsync)
        throws Failure, WebApplicationException, ApplicationException {
    if (QuarkusInjectorFactory.CONTAINER == null) {
        return delegate.construct(request, response, unwrapAsync);
    }
    if (factory == null) {
        factory = QuarkusInjectorFactory.CONTAINER.instanceFactory(this.ctor.getDeclaringClass());
    }
    if (factory == null) {
        return delegate.construct(request, response, unwrapAsync);
    }
    return factory.create().get();
}
 
Example #4
Source File: SecretQuestionAuthenticator.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public void addCookie(AuthenticationFlowContext context, String name, String value, String path, String domain, String comment, int maxAge, boolean secure, boolean httpOnly) {
    HttpResponse response = context.getSession().getContext().getContextObject(HttpResponse.class);
    StringBuffer cookieBuf = new StringBuffer();
    ServerCookie.appendCookieValue(cookieBuf, 1, name, value, path, domain, comment, maxAge, secure, httpOnly, null);
    String cookie = cookieBuf.toString();
    response.getOutputHeaders().add(HttpHeaders.SET_COOKIE, cookie);
}
 
Example #5
Source File: PluginRequestDispatcher.java    From redpipe with Apache License 2.0 5 votes vote down vote up
private void service(int i, Context context, HttpServerRequest req, HttpServerResponse resp, HttpRequest vertxReq,
		HttpResponse vertxResp, boolean handleNotFound) throws IOException {
	if(i < plugins.size())
		plugins.get(i).aroundRequest(vertxReq, () -> service(i+1, context, req, resp, vertxReq, vertxResp, handleNotFound));
	else
		super.service(context, req, resp, vertxReq, vertxResp, handleNotFound);
}
 
Example #6
Source File: SynchronousDispatcherInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    Object ret) throws Throwable {
    HttpResponse response = (HttpResponse) allArguments[1];
    AbstractSpan span = ContextManager.activeSpan();
    if (response.getStatus() >= 400) {
        span.errorOccurred();
        Tags.STATUS_CODE.set(span, Integer.toString(response.getStatus()));
    }
    ContextManager.stopSpan();
    return ret;
}
 
Example #7
Source File: GuiceRsApplicationServlet.java    From digdag with Apache License 2.0 5 votes vote down vote up
@Override
public Object createResource(HttpRequest request, HttpResponse response, ResteasyProviderFactory factory)
{
    Object resource = provider.get();
    contextPropertyInjector.inject(request, response, resource);
    return resource;
}
 
Example #8
Source File: SisuResourceFactory.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object createResource(final HttpRequest request,
                             final HttpResponse response,
                             final ResteasyProviderFactory factory)
{
  final Object resource = entry.getValue();
  propertyInjector.inject(request, response, resource);
  return resource;
}
 
Example #9
Source File: DubboResourceFactory.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public void requestFinished(HttpRequest request, HttpResponse response,
                            Object resource) {
}
 
Example #10
Source File: P3PHelper.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public static void addP3PHeader() {
    HttpResponse response = Resteasy.getContextData(HttpResponse.class);
    response.getOutputHeaders().putSingle("P3P", "CP=\"This is not a P3P policy!\"");
}
 
Example #11
Source File: CacheControlUtil.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public static void noBackButtonCacheControlHeader() {
    HttpResponse response = Resteasy.getContextData(HttpResponse.class);
    response.getOutputHeaders().putSingle("Cache-Control", "no-store, must-revalidate, max-age=0");
}
 
Example #12
Source File: Cors.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public void build(HttpResponse response) {
    String origin = request.getHttpHeaders().getRequestHeaders().getFirst(ORIGIN_HEADER);
    if (origin == null) {
        logger.trace("No origin header ignoring");
        return;
    }

    if (!preflight && (allowedOrigins == null || (!allowedOrigins.contains(origin) && !allowedOrigins.contains(ACCESS_CONTROL_ALLOW_ORIGIN_WILDCARD)))) {
        if (logger.isDebugEnabled()) {
            logger.debugv("Invalid CORS request: origin {0} not in allowed origins {1}", origin, allowedOrigins);
        }
        return;
    }

    if (allowedOrigins.contains(ACCESS_CONTROL_ALLOW_ORIGIN_WILDCARD)) {
        response.getOutputHeaders().add(ACCESS_CONTROL_ALLOW_ORIGIN, ACCESS_CONTROL_ALLOW_ORIGIN_WILDCARD);
    } else {
        response.getOutputHeaders().add(ACCESS_CONTROL_ALLOW_ORIGIN, origin);
    }

    if (preflight) {
        if (allowedMethods != null) {
            response.getOutputHeaders().add(ACCESS_CONTROL_ALLOW_METHODS, CollectionUtil.join(allowedMethods));
        } else {
            response.getOutputHeaders().add(ACCESS_CONTROL_ALLOW_METHODS, DEFAULT_ALLOW_METHODS);
        }
    }

    if (!preflight && exposedHeaders != null) {
        response.getOutputHeaders().add(ACCESS_CONTROL_EXPOSE_HEADERS, CollectionUtil.join(exposedHeaders));
    }

    response.getOutputHeaders().add(ACCESS_CONTROL_ALLOW_CREDENTIALS, Boolean.toString(auth));

    if (preflight) {
        if (auth) {
            response.getOutputHeaders().add(ACCESS_CONTROL_ALLOW_HEADERS, String.format("%s, %s", DEFAULT_ALLOW_HEADERS, AUTHORIZATION_HEADER));
        } else {
            response.getOutputHeaders().add(ACCESS_CONTROL_ALLOW_HEADERS, DEFAULT_ALLOW_HEADERS);
        }
    }

    if (preflight) {
        response.getOutputHeaders().add(ACCESS_CONTROL_MAX_AGE, DEFAULT_MAX_AGE);
    }

    logger.debug("Added CORS headers to response");
}
 
Example #13
Source File: DubboResourceFactory.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public void requestFinished(HttpRequest request, HttpResponse response,
                            Object resource) {
}
 
Example #14
Source File: DubboResourceFactory.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public Object createResource(HttpRequest request, HttpResponse response,
                             ResteasyProviderFactory factory) {
    return resourceInstance;
}
 
Example #15
Source File: GuiceRsApplicationServlet.java    From digdag with Apache License 2.0 4 votes vote down vote up
@Override
public void requestFinished(HttpRequest request, HttpResponse response, Object resource)
{ }
 
Example #16
Source File: SisuResourceFactory.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void requestFinished(final HttpRequest request, final HttpResponse response, final Object resource) {
  // ignore
}
 
Example #17
Source File: Pac4JProfileInjectorFactory.java    From jax-rs-pac4j with Apache License 2.0 4 votes vote down vote up
@Override
public Object inject(HttpRequest request, HttpResponse response) {
    return provider.apply(new RestEasyRequestContext(providerFactory, request));
}
 
Example #18
Source File: DubboResourceFactory.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
@Override
public Object createResource(HttpRequest request, HttpResponse response,
                             ResteasyProviderFactory factory) {
    return resourceInstance;
}
 
Example #19
Source File: DubboResourceFactory.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public Object createResource(HttpRequest request, HttpResponse response,
                             ResteasyProviderFactory factory) {
    return resourceInstance;
}
 
Example #20
Source File: DubboResourceFactory.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
public void requestFinished(HttpRequest request, HttpResponse response,
                            Object resource) {
}
 
Example #21
Source File: DubboResourceFactory.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
public Object createResource(HttpRequest request, HttpResponse response,
                             ResteasyProviderFactory factory) {
    return resourceInstance;
}
 
Example #22
Source File: DubboResourceFactory.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public void requestFinished(HttpRequest request, HttpResponse response,
                            Object resource) {
}
 
Example #23
Source File: DubboResourceFactory.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public Object createResource(HttpRequest request, HttpResponse response,
                             ResteasyProviderFactory factory) {
    return resourceInstance;
}
 
Example #24
Source File: PluginRequestDispatcher.java    From redpipe with Apache License 2.0 4 votes vote down vote up
@Override
public void service(Context context, HttpServerRequest req, HttpServerResponse resp, HttpRequest vertxReq,
		HttpResponse vertxResp, boolean handleNotFound) throws IOException {
	service(0, context, req, resp, vertxReq, vertxResp, handleNotFound);
}
 
Example #25
Source File: CustomerInject.java    From sofa-rpc with Apache License 2.0 4 votes vote down vote up
@Override
public Object inject(HttpRequest request, HttpResponse response) {
    return null;
}
 
Example #26
Source File: SofaSynchronousDispatcher.java    From sofa-rpc with Apache License 2.0 4 votes vote down vote up
@Override
public void invoke(HttpRequest request, HttpResponse response, ResourceInvoker invoker) {
    // 可以执行一下逻辑,例如切换ClassLoader等
    super.invoke(request, response, invoker);
}
 
Example #27
Source File: QuarkusConstructorInjector.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public Object injectableArguments(HttpRequest request, HttpResponse response, boolean unwrapAsync)
        throws Failure {
    return this.delegate.injectableArguments(request, response, unwrapAsync);
}
 
Example #28
Source File: QuarkusInjectorFactory.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public CompletionStage<Void> inject(HttpRequest request, HttpResponse response, Object target, boolean unwrapAsync)
        throws Failure, WebApplicationException, ApplicationException {
    return delegate.inject(request, response, PROXY_UNWRAPPER.apply(target), unwrapAsync);
}
 
Example #29
Source File: SetCookieResource.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@GET
public void setCookies(@Context HttpResponse response) {
    response.getOutputHeaders().add(HttpHeaders.SET_COOKIE, "c1=c1");
    response.getOutputHeaders().add(HttpHeaders.SET_COOKIE, "c2=c2");
    response.getOutputHeaders().add(HttpHeaders.SET_COOKIE, "c3=c3");
}
 
Example #30
Source File: DubboResourceFactory.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
@Override
public void requestFinished(HttpRequest request, HttpResponse response,
                            Object resource) {
}