Search in sources :

Example 1 with AttributedString

use of org.apache.cxf.ws.security.sts.provider.model.secext.AttributedString in project ddf by codice.

the class WssBasicAuthenticationHandler method getBaseAuthenticationToken.

protected BaseAuthenticationToken getBaseAuthenticationToken(String realm, String username, String password) {
    if (null == parser) {
        throw new IllegalStateException("XMLParser must be configured.");
    }
    UsernameTokenType usernameTokenType = new UsernameTokenType();
    AttributedString user = new AttributedString();
    user.setValue(username);
    usernameTokenType.setUsername(user);
    String usernameToken = null;
    // Add a password
    PasswordString pass = new PasswordString();
    pass.setValue(password);
    pass.setType(WSConstants.PASSWORD_TEXT);
    JAXBElement<PasswordString> passwordType = new JAXBElement<>(QNameConstants.PASSWORD, PasswordString.class, pass);
    usernameTokenType.getAny().add(passwordType);
    // Marshall the received JAXB object into a DOM Element
    List<String> ctxPath = new ArrayList<>(2);
    ctxPath.add(ObjectFactory.class.getPackage().getName());
    ctxPath.add(org.apache.cxf.ws.security.sts.provider.model.wstrust14.ObjectFactory.class.getPackage().getName());
    ParserConfigurator configurator = parser.configureParser(ctxPath, WssBasicAuthenticationHandler.class.getClassLoader());
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    JAXBElement<UsernameTokenType> tokenType = new JAXBElement<>(QNameConstants.USERNAME_TOKEN, UsernameTokenType.class, usernameTokenType);
    try {
        parser.marshal(configurator, tokenType, os);
        usernameToken = os.toString("UTF-8");
    } catch (ParserException | UnsupportedEncodingException ex) {
        LOGGER.info("Unable to parse username token.", ex);
    }
    BaseAuthenticationToken baseAuthenticationToken = new BaseAuthenticationToken(null, "", usernameToken);
    baseAuthenticationToken.setUseWssSts(true);
    return baseAuthenticationToken;
}
Also used : ParserException(org.codice.ddf.parser.ParserException) UsernameTokenType(org.apache.cxf.ws.security.sts.provider.model.secext.UsernameTokenType) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AttributedString(org.apache.cxf.ws.security.sts.provider.model.secext.AttributedString) PasswordString(org.apache.cxf.ws.security.sts.provider.model.secext.PasswordString) JAXBElement(javax.xml.bind.JAXBElement) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PasswordString(org.apache.cxf.ws.security.sts.provider.model.secext.PasswordString) ParserConfigurator(org.codice.ddf.parser.ParserConfigurator) AttributedString(org.apache.cxf.ws.security.sts.provider.model.secext.AttributedString) BaseAuthenticationToken(org.codice.ddf.security.handler.api.BaseAuthenticationToken)

Example 2 with AttributedString

use of org.apache.cxf.ws.security.sts.provider.model.secext.AttributedString in project ddf by codice.

the class UPBSTValidator method getUsernameTokenType.

public UsernameTokenType getUsernameTokenType(UPAuthenticationToken token) {
    UsernameTokenType usernameTokenType = new UsernameTokenType();
    AttributedString user = new AttributedString();
    user.setValue(token.getUsername());
    usernameTokenType.setUsername(user);
    // Add a password
    PasswordString password = new PasswordString();
    password.setValue(token.getPassword());
    password.setType(WSConstants.PASSWORD_TEXT);
    JAXBElement<PasswordString> passwordType = new JAXBElement<PasswordString>(QNameConstants.PASSWORD, PasswordString.class, password);
    usernameTokenType.getAny().add(passwordType);
    return usernameTokenType;
}
Also used : PasswordString(org.apache.cxf.ws.security.sts.provider.model.secext.PasswordString) AttributedString(org.apache.cxf.ws.security.sts.provider.model.secext.AttributedString) UsernameTokenType(org.apache.cxf.ws.security.sts.provider.model.secext.UsernameTokenType) JAXBElement(javax.xml.bind.JAXBElement)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)2 AttributedString (org.apache.cxf.ws.security.sts.provider.model.secext.AttributedString)2 PasswordString (org.apache.cxf.ws.security.sts.provider.model.secext.PasswordString)2 UsernameTokenType (org.apache.cxf.ws.security.sts.provider.model.secext.UsernameTokenType)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 ParserConfigurator (org.codice.ddf.parser.ParserConfigurator)1 ParserException (org.codice.ddf.parser.ParserException)1 BaseAuthenticationToken (org.codice.ddf.security.handler.api.BaseAuthenticationToken)1