use of org.apache.cxf.message.Message in project tomee by apache.
the class KerberosAuthenticationFilter method filter.
@Override
public void filter(ContainerRequestContext context) {
List<String> authHeaders = messageContext.getHttpHeaders().getRequestHeader(HttpHeaders.AUTHORIZATION);
if (authHeaders == null || authHeaders.size() != 1) {
LOG.fine("No Authorization header is available");
throw ExceptionUtils.toNotAuthorizedException(null, getFaultResponse());
}
String[] authPair = authHeaders.get(0).split(" ");
if (authPair.length != 2 || !NEGOTIATE_SCHEME.equalsIgnoreCase(authPair[0])) {
LOG.fine("Negotiate Authorization scheme is expected");
throw ExceptionUtils.toNotAuthorizedException(null, getFaultResponse());
}
byte[] serviceTicket = getServiceTicket(authPair[1]);
try {
Subject serviceSubject = loginAndGetSubject();
GSSContext gssContext = createGSSContext();
Subject.doAs(serviceSubject, new ValidateServiceTicketAction(gssContext, serviceTicket));
GSSName srcName = gssContext.getSrcName();
if (srcName == null) {
throw ExceptionUtils.toNotAuthorizedException(null, getFaultResponse());
}
String complexUserName = srcName.toString();
String simpleUserName = complexUserName;
int index = simpleUserName.lastIndexOf('@');
if (index > 0) {
simpleUserName = simpleUserName.substring(0, index);
}
Message m = JAXRSUtils.getCurrentMessage();
m.put(SecurityContext.class, createSecurityContext(simpleUserName, complexUserName, gssContext));
if (!gssContext.getCredDelegState()) {
gssContext.dispose();
}
} catch (LoginException e) {
LOG.fine("Unsuccessful JAAS login for the service principal: " + e.getMessage());
throw ExceptionUtils.toNotAuthorizedException(e, getFaultResponse());
} catch (GSSException e) {
LOG.fine("GSS API exception: " + e.getMessage());
throw ExceptionUtils.toNotAuthorizedException(e, getFaultResponse());
} catch (PrivilegedActionException e) {
LOG.fine("PrivilegedActionException: " + e.getMessage());
throw ExceptionUtils.toNotAuthorizedException(e, getFaultResponse());
}
}
use of org.apache.cxf.message.Message in project tomee by apache.
the class CXFNonSpringJaxrsServlet method setInterceptors.
@SuppressWarnings("unchecked")
protected void setInterceptors(JAXRSServerFactoryBean bean, ServletConfig servletConfig, String paramName, String splitChar) throws ServletException {
String value = servletConfig.getInitParameter(paramName);
if (value == null) {
return;
}
String[] values = value.split(splitChar);
List<Interceptor<? extends Message>> list = new ArrayList<>();
for (String interceptorVal : values) {
Map<String, List<String>> props = new HashMap<>();
String theValue = getClassNameAndProperties(interceptorVal, props);
if (!theValue.isEmpty()) {
try {
Class<?> intClass = loadClass(theValue, "Interceptor");
Object object = intClass.newInstance();
injectProperties(object, props);
list.add((Interceptor<? extends Message>) object);
} catch (ServletException ex) {
throw ex;
} catch (Exception ex) {
LOG.warning("Interceptor class " + theValue + " can not be created");
throw new ServletException(ex);
}
}
}
if (!list.isEmpty()) {
if (OUT_INTERCEPTORS_PARAM.equals(paramName)) {
bean.setOutInterceptors(list);
} else if (OUT_FAULT_INTERCEPTORS_PARAM.equals(paramName)) {
bean.setOutFaultInterceptors(list);
} else {
bean.setInInterceptors(list);
}
}
}
use of org.apache.cxf.message.Message in project tomee by apache.
the class JAXRSUtils method selectResourceClass.
public static Map<ClassResourceInfo, MultivaluedMap<String, String>> selectResourceClass(List<ClassResourceInfo> resources, String path, Message message) {
LOG.fine(() -> new org.apache.cxf.common.i18n.Message("START_CRI_MATCH", BUNDLE, path).toString());
if (resources.size() == 1) {
MultivaluedMap<String, String> values = new MetadataMap<>();
return resources.get(0).getURITemplate().match(path, values) ? Collections.singletonMap(resources.get(0), values) : null;
}
SortedMap<ClassResourceInfo, MultivaluedMap<String, String>> candidateList = new TreeMap<ClassResourceInfo, MultivaluedMap<String, String>>(new ClassResourceInfoComparator(message));
for (ClassResourceInfo cri : resources) {
MultivaluedMap<String, String> map = new MetadataMap<>();
if (cri.getURITemplate().match(path, map)) {
candidateList.put(cri, map);
LOG.fine(() -> new org.apache.cxf.common.i18n.Message("CRI_SELECTED_POSSIBLY", BUNDLE, cri.getServiceClass().getName(), path, cri.getURITemplate().getValue()).toString());
} else {
LOG.fine(() -> new org.apache.cxf.common.i18n.Message("CRI_NO_MATCH", BUNDLE, path, cri.getServiceClass().getName()).toString());
}
}
if (!candidateList.isEmpty()) {
Map<ClassResourceInfo, MultivaluedMap<String, String>> cris = new LinkedHashMap<>(candidateList.size());
ClassResourceInfo firstCri = null;
for (Map.Entry<ClassResourceInfo, MultivaluedMap<String, String>> entry : candidateList.entrySet()) {
ClassResourceInfo cri = entry.getKey();
if (cris.isEmpty()) {
firstCri = cri;
cris.put(cri, entry.getValue());
} else if (firstCri != null && URITemplate.compareTemplates(firstCri.getURITemplate(), cri.getURITemplate()) == 0) {
cris.put(cri, entry.getValue());
} else {
break;
}
LOG.fine(() -> new org.apache.cxf.common.i18n.Message("CRI_SELECTED", BUNDLE, cri.getServiceClass().getName(), path, cri.getURITemplate().getValue()).toString());
}
return cris;
}
return null;
}
use of org.apache.cxf.message.Message 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.message.Message in project tomee by apache.
the class MultipartProvider method getHandlerForObject.
private <T> DataHandler getHandlerForObject(T obj, Class<T> cls, Type genericType, Annotation[] anns, String mimeType) {
MediaType mt = JAXRSUtils.toMediaType(mimeType);
mc.put(ProviderFactory.ACTIVE_JAXRS_PROVIDER_KEY, this);
final MessageBodyWriter<T> r;
try {
r = mc.getProviders().getMessageBodyWriter(cls, genericType, anns, mt);
} finally {
mc.put(ProviderFactory.ACTIVE_JAXRS_PROVIDER_KEY, null);
}
if (r == null) {
org.apache.cxf.common.i18n.Message message = new org.apache.cxf.common.i18n.Message("NO_MSG_WRITER", BUNDLE, cls);
LOG.severe(message.toString());
throw ExceptionUtils.toInternalServerErrorException(null, null);
}
return new MessageBodyWriterDataHandler<T>(r, obj, cls, genericType, anns, mt);
}
Aggregations