Search in sources :

Example 16 with UsernameToken

use of org.apache.wss4j.dom.message.token.UsernameToken in project wildfly by wildfly.

the class UsernameTokenCallbackHandler method getUsernameTokenElement.

/**
 * Provide UsernameToken as a DOM Element.
 *
 * @param ctx
 * @return
 */
public Element getUsernameTokenElement(Map<String, Object> ctx) {
    Document doc = DOMUtils.createDocument();
    Element result = null;
    UsernameToken usernameToken = null;
    String username = (String) ctx.get(SecurityConstants.USERNAME);
    String password = (String) ctx.get(SecurityConstants.PASSWORD);
    if (username != null) {
        usernameToken = createWSSEUsernameToken(username, password, doc);
        result = usernameToken.getElement();
    }
    return result;
}
Also used : Element(org.w3c.dom.Element) UsernameToken(org.apache.wss4j.dom.message.token.UsernameToken) Document(org.w3c.dom.Document)

Example 17 with UsernameToken

use of org.apache.wss4j.dom.message.token.UsernameToken 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 18 with UsernameToken

use of org.apache.wss4j.dom.message.token.UsernameToken in project wildfly by wildfly.

the class UsernameTokenCallbackHandler method getUsernameTokenString.

/**
 * Provide UsernameToken as a string.
 *
 * @param ctx
 * @return
 */
public String getUsernameTokenString(Map<String, Object> ctx) {
    Document doc = DOMUtils.createDocument();
    String result = null;
    String username = (String) ctx.get(SecurityConstants.USERNAME);
    String password = (String) ctx.get(SecurityConstants.PASSWORD);
    if (username != null) {
        UsernameToken usernameToken = createWSSEUsernameToken(username, password, doc);
        result = toString(usernameToken.getElement().getFirstChild().getParentNode());
    }
    return result;
}
Also used : UsernameToken(org.apache.wss4j.dom.message.token.UsernameToken) Document(org.w3c.dom.Document)

Example 19 with UsernameToken

use of org.apache.wss4j.dom.message.token.UsernameToken in project cxf by apache.

the class STSLoginModule method convertToToken.

private UsernameToken convertToToken(String username, String password) throws Exception {
    Document doc = DOMUtils.getEmptyDocument();
    UsernameToken token = new UsernameToken(false, doc, WSS4JConstants.PASSWORD_TEXT);
    token.setName(username);
    token.setPassword(password);
    return token;
}
Also used : UsernameToken(org.apache.wss4j.dom.message.token.UsernameToken) Document(org.w3c.dom.Document)

Example 20 with UsernameToken

use of org.apache.wss4j.dom.message.token.UsernameToken in project cxf by apache.

the class STSStaxTokenValidator method convertToDOM.

// Convert to DOM to send the token to the STS - it does not copy Nonce/Created/Iteration
// values
private Element convertToDOM(String username, String password, String passwordType, String id) {
    Document doc = DOMUtils.getEmptyDocument();
    UsernameToken usernameToken = new UsernameToken(true, doc, passwordType);
    usernameToken.setName(username);
    usernameToken.setPassword(password);
    usernameToken.setID(id);
    usernameToken.addWSSENamespace();
    usernameToken.addWSUNamespace();
    return usernameToken.getElement();
}
Also used : UsernameToken(org.apache.wss4j.dom.message.token.UsernameToken) Document(org.w3c.dom.Document)

Aggregations

UsernameToken (org.apache.wss4j.dom.message.token.UsernameToken)46 Document (org.w3c.dom.Document)32 Credential (org.apache.wss4j.dom.validate.Credential)16 RequestData (org.apache.wss4j.dom.handler.RequestData)15 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)12 Element (org.w3c.dom.Element)10 Principal (java.security.Principal)9 WSUsernameTokenPrincipalImpl (org.apache.wss4j.common.principal.WSUsernameTokenPrincipalImpl)5 Test (org.junit.Test)5 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)4 JAXBElement (javax.xml.bind.JAXBElement)4 AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)4 Message (org.apache.cxf.message.Message)4 ReceivedToken (org.apache.cxf.sts.request.ReceivedToken)4 UsernameTokenType (org.apache.cxf.ws.security.sts.provider.model.secext.UsernameTokenType)4 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)4 CustomTokenPrincipal (org.apache.wss4j.common.principal.CustomTokenPrincipal)4 CallbackHandler (javax.security.auth.callback.CallbackHandler)3 Fault (org.apache.cxf.interceptor.Fault)3 STSPropertiesMBean (org.apache.cxf.sts.STSPropertiesMBean)3