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;
}
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;
}
Aggregations