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);
}
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);
}
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);
}
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;
}
Aggregations