Search in sources :

Example 1 with Message

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;
    }
}
Also used : AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) Message(org.apache.cxf.message.Message) Base64Exception(org.apache.cxf.common.util.Base64Exception)

Example 2 with Message

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;
}
Also used : Message(org.apache.cxf.message.Message) Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) Header(org.apache.cxf.headers.Header) WrappedMessageContext(org.apache.cxf.jaxws.context.WrappedMessageContext) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) MessageContext(javax.xml.ws.handler.MessageContext) WrappedMessageContext(org.apache.cxf.jaxws.context.WrappedMessageContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 3 with Message

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);
            }
        }
    });
}
Also used : Message(org.apache.cxf.message.Message) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) PhaseInterceptor(org.apache.cxf.phase.PhaseInterceptor) Fault(org.apache.cxf.interceptor.Fault) IOException(java.io.IOException) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) MessageSenderInterceptor(org.apache.cxf.interceptor.MessageSenderInterceptor) AbstractWrappedOutputStream(org.apache.cxf.io.AbstractWrappedOutputStream) Interceptor(org.apache.cxf.interceptor.Interceptor) MessageSenderInterceptor(org.apache.cxf.interceptor.MessageSenderInterceptor) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) PhaseInterceptor(org.apache.cxf.phase.PhaseInterceptor)

Example 4 with Message

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;
}
Also used : Message(org.apache.cxf.message.Message)

Example 5 with Message

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);
}
Also used : Message(org.apache.cxf.message.Message) MessageImpl(org.apache.cxf.message.MessageImpl)

Aggregations

Message (org.apache.cxf.message.Message)1002 Test (org.junit.Test)507 MessageImpl (org.apache.cxf.message.MessageImpl)291 Exchange (org.apache.cxf.message.Exchange)199 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)169 Endpoint (org.apache.cxf.endpoint.Endpoint)91 Interceptor (org.apache.cxf.interceptor.Interceptor)87 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)85 ArrayList (java.util.ArrayList)83 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)76 List (java.util.List)75 IOException (java.io.IOException)73 OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)73 Method (java.lang.reflect.Method)69 Bus (org.apache.cxf.Bus)69 QName (javax.xml.namespace.QName)62 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)55 HashMap (java.util.HashMap)53 Fault (org.apache.cxf.interceptor.Fault)51 ByteArrayInputStream (java.io.ByteArrayInputStream)49