Search in sources :

Example 1 with SecurityContextImpl

use of org.apache.cxf.jaxrs.impl.SecurityContextImpl in project tomee by apache.

the class JAXRSUtils method createContextValue.

public static <T> T createContextValue(Message m, Type genericType, Class<T> clazz) {
    Message contextMessage = getContextMessage(m);
    Object o = null;
    if (UriInfo.class.isAssignableFrom(clazz)) {
        o = createUriInfo(contextMessage);
    } else if (HttpHeaders.class.isAssignableFrom(clazz) || ProtocolHeaders.class.isAssignableFrom(clazz)) {
        o = createHttpHeaders(contextMessage, clazz);
    } else if (SecurityContext.class.isAssignableFrom(clazz)) {
        SecurityContext customContext = contextMessage.get(SecurityContext.class);
        o = customContext == null ? new SecurityContextImpl(contextMessage) : customContext;
    } else if (MessageContext.class.isAssignableFrom(clazz)) {
        o = new MessageContextImpl(m);
    } else if (ResourceInfo.class.isAssignableFrom(clazz)) {
        o = new ResourceInfoImpl(contextMessage);
    } else if (ResourceContext.class.isAssignableFrom(clazz)) {
        OperationResourceInfo operationResourceInfo = contextMessage.getExchange().get(OperationResourceInfo.class);
        if (operationResourceInfo != null) {
            o = new ResourceContextImpl(contextMessage, operationResourceInfo);
        }
    } else if (Request.class.isAssignableFrom(clazz)) {
        o = new RequestImpl(contextMessage);
    } else if (Providers.class.isAssignableFrom(clazz)) {
        o = new ProvidersImpl(contextMessage);
    } else if (ContextResolver.class.isAssignableFrom(clazz)) {
        o = createContextResolver(genericType, contextMessage);
    } else if (Configuration.class.isAssignableFrom(clazz)) {
        o = ProviderFactory.getInstance(contextMessage).getConfiguration(contextMessage);
    } else if (Application.class.isAssignableFrom(clazz)) {
        ProviderInfo<?> providerInfo = (ProviderInfo<?>) contextMessage.getExchange().getEndpoint().get(Application.class.getName());
        o = providerInfo == null ? null : providerInfo.getProvider();
    } else if (contextMessage != null) {
        ContextProvider<?> provider = ProviderFactory.getInstance(contextMessage).createContextProvider(clazz, contextMessage);
        if (provider != null) {
            o = provider.createContext(contextMessage);
        }
    }
    if (o == null && contextMessage != null && !MessageUtils.isRequestor(contextMessage)) {
        o = HttpUtils.createServletResourceValue(contextMessage, clazz);
    }
    return clazz.cast(o);
}
Also used : SecurityContextImpl(org.apache.cxf.jaxrs.impl.SecurityContextImpl) ResourceContext(javax.ws.rs.container.ResourceContext) Message(org.apache.cxf.message.Message) Configuration(javax.ws.rs.core.Configuration) ResourceInfoImpl(org.apache.cxf.jaxrs.impl.ResourceInfoImpl) ContextProvider(org.apache.cxf.jaxrs.ext.ContextProvider) Providers(javax.ws.rs.ext.Providers) ProvidersImpl(org.apache.cxf.jaxrs.impl.ProvidersImpl) ProviderInfo(org.apache.cxf.jaxrs.model.ProviderInfo) SecurityContext(javax.ws.rs.core.SecurityContext) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) MessageContext(org.apache.cxf.jaxrs.ext.MessageContext) ResourceContextImpl(org.apache.cxf.jaxrs.impl.ResourceContextImpl) RequestImpl(org.apache.cxf.jaxrs.impl.RequestImpl) MessageContextImpl(org.apache.cxf.jaxrs.ext.MessageContextImpl)

Example 2 with SecurityContextImpl

use of org.apache.cxf.jaxrs.impl.SecurityContextImpl in project cxf by apache.

the class JAXRSUtils method createContextValue.

public static <T> T createContextValue(Message m, Type genericType, Class<T> clazz) {
    Message contextMessage = getContextMessage(m);
    Object o = null;
    if (UriInfo.class.isAssignableFrom(clazz)) {
        o = createUriInfo(contextMessage);
    } else if (HttpHeaders.class.isAssignableFrom(clazz) || ProtocolHeaders.class.isAssignableFrom(clazz)) {
        o = createHttpHeaders(contextMessage, clazz);
    } else if (SecurityContext.class.isAssignableFrom(clazz)) {
        SecurityContext customContext = contextMessage.get(SecurityContext.class);
        o = customContext == null ? new SecurityContextImpl(contextMessage) : customContext;
    } else if (MessageContext.class.isAssignableFrom(clazz)) {
        o = new MessageContextImpl(m);
    } else if (ResourceInfo.class.isAssignableFrom(clazz)) {
        o = new ResourceInfoImpl(contextMessage);
    } else if (ResourceContext.class.isAssignableFrom(clazz)) {
        final OperationResourceInfo ori = contextMessage.getExchange().get(OperationResourceInfo.class);
        if (ori != null) {
            o = new ResourceContextImpl(contextMessage, ori);
        }
    } else if (Request.class.isAssignableFrom(clazz)) {
        o = new RequestImpl(contextMessage);
    } else if (Providers.class.isAssignableFrom(clazz)) {
        o = new ProvidersImpl(contextMessage);
    } else if (ContextResolver.class.isAssignableFrom(clazz)) {
        o = createContextResolver(genericType, contextMessage);
    } else if (Configuration.class.isAssignableFrom(clazz)) {
        o = ProviderFactory.getInstance(contextMessage).getConfiguration(contextMessage);
    } else if (Application.class.isAssignableFrom(clazz)) {
        ProviderInfo<?> providerInfo = (ProviderInfo<?>) contextMessage.getExchange().getEndpoint().get(Application.class.getName());
        o = providerInfo == null ? null : providerInfo.getProvider();
    } else if (contextMessage != null) {
        ContextProvider<?> provider = ProviderFactory.getInstance(contextMessage).createContextProvider(clazz, contextMessage);
        if (provider != null) {
            o = provider.createContext(contextMessage);
        }
    }
    if (o == null && contextMessage != null && !MessageUtils.isRequestor(contextMessage)) {
        o = HttpUtils.createServletResourceValue(contextMessage, clazz);
    }
    return clazz.cast(o);
}
Also used : SecurityContextImpl(org.apache.cxf.jaxrs.impl.SecurityContextImpl) ResourceContext(javax.ws.rs.container.ResourceContext) Message(org.apache.cxf.message.Message) Configuration(javax.ws.rs.core.Configuration) ResourceInfoImpl(org.apache.cxf.jaxrs.impl.ResourceInfoImpl) ContextProvider(org.apache.cxf.jaxrs.ext.ContextProvider) Providers(javax.ws.rs.ext.Providers) ProvidersImpl(org.apache.cxf.jaxrs.impl.ProvidersImpl) ProviderInfo(org.apache.cxf.jaxrs.model.ProviderInfo) SecurityContext(javax.ws.rs.core.SecurityContext) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) MessageContext(org.apache.cxf.jaxrs.ext.MessageContext) ResourceContextImpl(org.apache.cxf.jaxrs.impl.ResourceContextImpl) RequestImpl(org.apache.cxf.jaxrs.impl.RequestImpl) MessageContextImpl(org.apache.cxf.jaxrs.ext.MessageContextImpl)

Example 3 with SecurityContextImpl

use of org.apache.cxf.jaxrs.impl.SecurityContextImpl in project cxf by apache.

the class CustomJAXRSInvoker method invoke.

@Override
public Object invoke(Exchange exchange, Object requestParams, Object resourceObject) {
    OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
    Method m = ori.getMethodToInvoke();
    Class<?> realClass = ClassHelper.getRealClass(exchange.getBus(), resourceObject);
    Principal p = new SecurityContextImpl(exchange.getInMessage()).getUserPrincipal();
    if (realClass == SecureBookStore.class && "getThatBook".equals(m.getName()) && "baddy".equals(p.getName())) {
        return new MessageContentsList(Response.status(Response.Status.FORBIDDEN).build());
    }
    return super.invoke(exchange, requestParams, resourceObject);
}
Also used : SecurityContextImpl(org.apache.cxf.jaxrs.impl.SecurityContextImpl) MessageContentsList(org.apache.cxf.message.MessageContentsList) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) Method(java.lang.reflect.Method) Principal(java.security.Principal)

Example 4 with SecurityContextImpl

use of org.apache.cxf.jaxrs.impl.SecurityContextImpl in project camel by apache.

the class CxfRsInvoker method prepareExchange.

private org.apache.camel.Exchange prepareExchange(Exchange cxfExchange, Method method, Object[] paramArray, Object response) {
    ExchangePattern ep = ExchangePattern.InOut;
    if (method.getReturnType() == Void.class) {
        ep = ExchangePattern.InOnly;
    }
    final org.apache.camel.Exchange camelExchange = endpoint.createExchange(ep);
    if (response != null) {
        camelExchange.getOut().setBody(response);
    }
    CxfRsBinding binding = endpoint.getBinding();
    binding.populateExchangeFromCxfRsRequest(cxfExchange, camelExchange, method, paramArray);
    // the CXF in message property. Question: where should this property name be set up ? 
    if (endpoint.isPropagateContexts()) {
        camelExchange.setProperty(UriInfo.class.getName(), new UriInfoImpl(cxfExchange.getInMessage()));
        camelExchange.setProperty(Request.class.getName(), new RequestImpl(cxfExchange.getInMessage()));
        camelExchange.setProperty(HttpHeaders.class.getName(), new HttpHeadersImpl(cxfExchange.getInMessage()));
        camelExchange.setProperty(SecurityContext.class.getName(), new SecurityContextImpl(cxfExchange.getInMessage()));
    }
    return camelExchange;
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) SecurityContextImpl(org.apache.cxf.jaxrs.impl.SecurityContextImpl) Request(javax.ws.rs.core.Request) HttpHeadersImpl(org.apache.cxf.jaxrs.impl.HttpHeadersImpl) ExchangePattern(org.apache.camel.ExchangePattern) SecurityContext(javax.ws.rs.core.SecurityContext) UriInfo(javax.ws.rs.core.UriInfo) RequestImpl(org.apache.cxf.jaxrs.impl.RequestImpl) UriInfoImpl(org.apache.cxf.jaxrs.impl.UriInfoImpl)

Aggregations

SecurityContextImpl (org.apache.cxf.jaxrs.impl.SecurityContextImpl)4 SecurityContext (javax.ws.rs.core.SecurityContext)3 RequestImpl (org.apache.cxf.jaxrs.impl.RequestImpl)3 OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)3 ResourceContext (javax.ws.rs.container.ResourceContext)2 Configuration (javax.ws.rs.core.Configuration)2 Providers (javax.ws.rs.ext.Providers)2 ContextProvider (org.apache.cxf.jaxrs.ext.ContextProvider)2 MessageContext (org.apache.cxf.jaxrs.ext.MessageContext)2 MessageContextImpl (org.apache.cxf.jaxrs.ext.MessageContextImpl)2 ProvidersImpl (org.apache.cxf.jaxrs.impl.ProvidersImpl)2 ResourceContextImpl (org.apache.cxf.jaxrs.impl.ResourceContextImpl)2 ResourceInfoImpl (org.apache.cxf.jaxrs.impl.ResourceInfoImpl)2 ProviderInfo (org.apache.cxf.jaxrs.model.ProviderInfo)2 Message (org.apache.cxf.message.Message)2 Method (java.lang.reflect.Method)1 Principal (java.security.Principal)1 HttpHeaders (javax.ws.rs.core.HttpHeaders)1 Request (javax.ws.rs.core.Request)1 UriInfo (javax.ws.rs.core.UriInfo)1