Search in sources :

Example 1 with DelegationCallback

use of org.apache.cxf.ws.security.trust.delegation.DelegationCallback 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)

Example 2 with DelegationCallback

use of org.apache.cxf.ws.security.trust.delegation.DelegationCallback in project cxf by apache.

the class AbstractSTSClient method getDelegationSecurityToken.

protected Element getDelegationSecurityToken(Object delegationObject) throws Exception {
    if (delegationObject != null) {
        final boolean isString = delegationObject instanceof String;
        final boolean isElement = delegationObject instanceof Element;
        final boolean isCallbackHandler = delegationObject instanceof CallbackHandler;
        if (isString) {
            final Document doc = StaxUtils.read(new StringReader((String) delegationObject));
            return doc.getDocumentElement();
        } else if (isElement) {
            return (Element) delegationObject;
        } else if (isCallbackHandler) {
            DelegationCallback callback = new DelegationCallback(message);
            ((CallbackHandler) delegationObject).handle(new Callback[] { callback });
            return callback.getToken();
        }
    }
    return null;
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) Document(org.w3c.dom.Document) DelegationCallback(org.apache.cxf.ws.security.trust.delegation.DelegationCallback)

Example 3 with DelegationCallback

use of org.apache.cxf.ws.security.trust.delegation.DelegationCallback in project jbossws-cxf by jbossws.

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

DelegationCallback (org.apache.cxf.ws.security.trust.delegation.DelegationCallback)3 Document (org.w3c.dom.Document)3 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)2 Message (org.apache.cxf.message.Message)2 UsernameToken (org.apache.wss4j.dom.message.token.UsernameToken)2 Node (org.w3c.dom.Node)2 StringReader (java.io.StringReader)1 CallbackHandler (javax.security.auth.callback.CallbackHandler)1 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)1 Element (org.w3c.dom.Element)1