use of org.apache.cxf.message.Message in project midpoint by Evolveum.
the class MidpointRestAuthenticationHandler method filter.
@Override
public void filter(ContainerRequestContext requestCtx) throws IOException {
Message m = JAXRSUtils.getCurrentMessage();
AuthorizationPolicy policy = (AuthorizationPolicy) m.get(AuthorizationPolicy.class);
if (policy != null) {
passwordAuthenticator.handleRequest(policy, m, requestCtx);
return;
}
String authorization = requestCtx.getHeaderString("Authorization");
if (StringUtils.isBlank(authorization)) {
RestServiceUtil.createAbortMessage(requestCtx);
return;
}
String[] parts = authorization.split(" ");
String authenticationType = parts[0];
if (parts.length == 1) {
if (RestAuthenticationMethod.SECURITY_QUESTIONS.equals(authenticationType)) {
RestServiceUtil.createSecurityQuestionAbortMessage(requestCtx, "{\"user\" : \"username\"}");
return;
}
}
if (parts.length != 2 || (!RestAuthenticationMethod.SECURITY_QUESTIONS.equals(authenticationType))) {
RestServiceUtil.createAbortMessage(requestCtx);
return;
}
String base64Credentials = (parts.length == 2) ? parts[1] : null;
try {
String decodedCredentials = new String(Base64Utility.decode(base64Credentials));
if (RestAuthenticationMethod.SECURITY_QUESTIONS.equals(authenticationType)) {
policy = new AuthorizationPolicy();
policy.setAuthorizationType(RestAuthenticationMethod.SECURITY_QUESTIONS.getMethod());
policy.setAuthorization(decodedCredentials);
}
securityQuestionAuthenticator.handleRequest(policy, m, requestCtx);
} catch (Base64Exception e) {
RestServiceUtil.createSecurityQuestionAbortMessage(requestCtx, "{\"user\" : \"username\"}");
return;
}
}
use of org.apache.cxf.message.Message in project libresonic by Libresonic.
the class SonosService method getUsername.
private String getUsername() {
MessageContext messageContext = context.getMessageContext();
if (messageContext == null || !(messageContext instanceof WrappedMessageContext)) {
LOG.error("Message context is null or not an instance of WrappedMessageContext.");
return null;
}
Message message = ((WrappedMessageContext) messageContext).getWrappedMessage();
List<Header> headers = CastUtils.cast((List<?>) message.get(Header.HEADER_LIST));
if (headers != null) {
for (Header h : headers) {
Object o = h.getObject();
// Unwrap the node using JAXB
if (o instanceof Node) {
JAXBContext jaxbContext;
try {
// TODO: Check performance
jaxbContext = new JAXBDataBinding(Credentials.class).getContext();
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
o = unmarshaller.unmarshal((Node) o);
} catch (JAXBException e) {
// failed to get the credentials object from the headers
LOG.error("JAXB error trying to unwrap credentials", e);
}
}
if (o instanceof Credentials) {
Credentials c = (Credentials) o;
// Note: We're using the username as session ID.
String username = c.getSessionId();
if (username == null) {
LOG.debug("No session id in credentials object, get from login");
username = c.getLogin().getUsername();
}
return username;
} else {
LOG.error("No credentials object");
}
}
} else {
LOG.error("No headers found");
}
return null;
}
use of org.apache.cxf.message.Message in project camel by apache.
the class MessageLossSimulator method handleMessage.
public void handleMessage(Message message) throws Fault {
Object maps = RMContextUtils.retrieveMAPs(message, false, true);
// RMContextUtils.ensureExposedVersion(maps);
String action = getAction(maps);
if (RMContextUtils.isRMProtocolMessage(action)) {
return;
}
appMessageCount++;
// do not discard odd-numbered messages
if (0 != (appMessageCount % 2)) {
return;
}
// discard even-numbered message
InterceptorChain chain = message.getInterceptorChain();
ListIterator<Interceptor<? extends Message>> it = chain.getIterator();
while (it.hasNext()) {
PhaseInterceptor<?> pi = (PhaseInterceptor<?>) it.next();
if (MessageSenderInterceptor.class.getName().equals(pi.getId())) {
chain.remove(pi);
LOG.debug("Removed MessageSenderInterceptor from interceptor chain.");
break;
}
}
message.setContent(OutputStream.class, new WrappedOutputStream(message));
message.getInterceptorChain().add(new AbstractPhaseInterceptor<Message>(Phase.PREPARE_SEND_ENDING) {
public void handleMessage(Message message) throws Fault {
try {
message.getContent(OutputStream.class).close();
} catch (IOException e) {
throw new Fault(e);
}
}
});
}
use of org.apache.cxf.message.Message in project camel by apache.
the class CxfConsumer method isAsyncInvocationSupported.
protected boolean isAsyncInvocationSupported(Exchange cxfExchange) {
Message cxfMessage = cxfExchange.getInMessage();
Object addressingProperties = cxfMessage.get(CxfConstants.WSA_HEADERS_INBOUND);
if (addressingProperties != null && !ContextUtils.isGenericAddress(getReplyTo(addressingProperties))) {
//caught by underlying transport. So we should use the SyncInvocation this time
return false;
}
// we assume it should support AsyncInvocation out of box
return true;
}
use of org.apache.cxf.message.Message in project camel by apache.
the class CxfBeanDestination method process.
public void process(Exchange camelExchange) throws Exception {
LOG.trace("Received request : {}", camelExchange);
org.apache.cxf.message.Message cxfMessage = endpoint.getCxfBeanBinding().createCxfMessageFromCamelExchange(camelExchange, endpoint.getHeaderFilterStrategy());
cxfMessage.put(CamelTransportConstants.CAMEL_EXCHANGE, camelExchange);
((MessageImpl) cxfMessage).setDestination(this);
// Handling the incoming message
// The response message will be send back by the outgoing chain
incomingObserver.onMessage(cxfMessage);
}
Aggregations