Search in sources :

Example 66 with Message

use of org.apache.cxf.message.Message in project jbossws-cxf by jbossws.

the class JaspiServerAuthenticator method validateRequest.

public void validateRequest(SoapMessage message) {
    SOAPMessage soapMessage = message.getContent(SOAPMessage.class);
    MessageInfo messageInfo = new GenericMessageInfo(soapMessage, null);
    AuthStatus authStatus;
    try {
        authStatus = sctx.validateRequest(messageInfo, null, null);
    } catch (AuthException e) {
        if (isSOAP12(message)) {
            SoapFault soap12Fault = new SoapFault(e.getMessage(), Soap12.getInstance().getReceiver());
            throw soap12Fault;
        } else {
            throw new SoapFault(e.getMessage(), new QName("", "jaspi AuthException"));
        }
    }
    Message response = null;
    if (messageInfo.getResponseMessage() != null && !message.getExchange().isOneWay()) {
        Endpoint e = message.getExchange().getEndpoint();
        response = new MessageImpl();
        response.setExchange(message.getExchange());
        response = e.getBinding().createMessage(response);
        message.getExchange().setOutMessage(response);
        response.setContent(SOAPMessage.class, messageInfo.getResponseMessage());
        if (AuthStatus.SEND_CONTINUE == authStatus) {
            response.put(Message.RESPONSE_CODE, Integer.valueOf(303));
        }
        if (AuthStatus.SEND_FAILURE == authStatus) {
            response.put(Message.RESPONSE_CODE, Integer.valueOf(500));
        }
        message.getInterceptorChain().abort();
        InterceptorChain chain = OutgoingChainInterceptor.getOutInterceptorChain(message.getExchange());
        response.setInterceptorChain(chain);
        chain.doInterceptStartingAfter(response, SoapPreProtocolOutInterceptor.class.getName());
    }
}
Also used : InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) SoapFault(org.apache.cxf.binding.soap.SoapFault) SoapPreProtocolOutInterceptor(org.apache.cxf.binding.soap.interceptor.SoapPreProtocolOutInterceptor) Message(org.apache.cxf.message.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) SOAPMessage(javax.xml.soap.SOAPMessage) Endpoint(org.apache.cxf.endpoint.Endpoint) AuthStatus(javax.security.auth.message.AuthStatus) QName(javax.xml.namespace.QName) GenericMessageInfo(org.jboss.security.auth.message.GenericMessageInfo) AuthException(javax.security.auth.message.AuthException) SOAPMessage(javax.xml.soap.SOAPMessage) MessageImpl(org.apache.cxf.message.MessageImpl) MessageInfo(javax.security.auth.message.MessageInfo) GenericMessageInfo(org.jboss.security.auth.message.GenericMessageInfo)

Example 67 with Message

use of org.apache.cxf.message.Message in project jbossws-cxf by jbossws.

the class JBossWSInvokerTest method getTestExchange.

// build up a fake exchange instance, the minimum required to let the flow proceed till the JBossWSInvoker
private Exchange getTestExchange() {
    Exchange exchange = new ExchangeImpl();
    Message message = new MessageImpl();
    message.setExchange(exchange);
    exchange.setInMessage(message);
    exchange.put(BindingOperationInfo.class, new BindingOperationInfo());
    Service service = new ServiceImpl();
    MethodDispatcher md = new MethodDispatcher() {

        @Override
        public Method getMethod(BindingOperationInfo op) {
            return this.getClass().getMethods()[0];
        }

        @Override
        public BindingOperationInfo getBindingOperation(Method m, Endpoint endpoint) {
            return null;
        }

        @Override
        public void bind(OperationInfo o, Method... methods) {
        }
    };
    service.put(MethodDispatcher.class.getName(), md);
    exchange.put(Service.class, service);
    return exchange;
}
Also used : Exchange(org.apache.cxf.message.Exchange) OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.message.Message) Endpoint(org.apache.cxf.endpoint.Endpoint) ServiceImpl(org.apache.cxf.service.ServiceImpl) Service(org.apache.cxf.service.Service) MethodDispatcher(org.apache.cxf.service.invoker.MethodDispatcher) Method(java.lang.reflect.Method) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 68 with Message

use of org.apache.cxf.message.Message in project testcases by coheigea.

the class WSS4JBasicAuthFilter method filter.

public void filter(ContainerRequestContext requestContext) throws IOException {
    Message message = JAXRSUtils.getCurrentMessage();
    AuthorizationPolicy policy = message.get(AuthorizationPolicy.class);
    if (policy == null || policy.getUserName() == null || policy.getPassword() == null) {
        requestContext.abortWith(Response.status(401).header("WWW-Authenticate", "Basic realm=\"IdP\"").build());
        return;
    }
    try {
        super.validate(message);
    } catch (Exception ex) {
        throw ExceptionUtils.toInternalServerErrorException(ex, null);
    }
}
Also used : AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) Message(org.apache.cxf.message.Message) IOException(java.io.IOException)

Example 69 with Message

use of org.apache.cxf.message.Message in project testcases by coheigea.

the class WSS4JBasicAuthFilter method filter.

public void filter(ContainerRequestContext requestContext) throws IOException {
    Message message = JAXRSUtils.getCurrentMessage();
    AuthorizationPolicy policy = message.get(AuthorizationPolicy.class);
    if (policy == null || policy.getUserName() == null || policy.getPassword() == null) {
        requestContext.abortWith(Response.status(401).header("WWW-Authenticate", "Basic realm=\"IdP\"").build());
        return;
    }
    try {
        super.validate(message);
    } catch (Exception ex) {
        throw ExceptionUtils.toInternalServerErrorException(ex, null);
    }
}
Also used : AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) Message(org.apache.cxf.message.Message) IOException(java.io.IOException)

Example 70 with Message

use of org.apache.cxf.message.Message in project wildfly by wildfly.

the class UsernameTokenCallbackHandler method handle.

public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof DelegationCallback) {
            DelegationCallback callback = (DelegationCallback) callbacks[i];
            Message message = callback.getCurrentMessage();
            String username = (String) message.getContextualProperty(SecurityConstants.USERNAME);
            String password = (String) message.getContextualProperty(SecurityConstants.PASSWORD);
            if (username != null) {
                Node contentNode = message.getContent(Node.class);
                Document doc = null;
                if (contentNode != null) {
                    doc = contentNode.getOwnerDocument();
                } else {
                    doc = DOMUtils.createDocument();
                }
                UsernameToken usernameToken = createWSSEUsernameToken(username, password, doc);
                callback.setToken(usernameToken.getElement());
            }
        } else {
            throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
        }
    }
}
Also used : Message(org.apache.cxf.message.Message) Node(org.w3c.dom.Node) UsernameToken(org.apache.wss4j.dom.message.token.UsernameToken) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) Document(org.w3c.dom.Document) DelegationCallback(org.apache.cxf.ws.security.trust.delegation.DelegationCallback)

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