log.log(
Level.SEVERE,
"WSS0329.usernametoken.expected",
new Object[] {getLocalName()});
throw new SecurityTokenException(
"Expected UsernameToken Element, but Found " + getLocalName());
}
boolean invalidToken = false;
Iterator children = getChildElements();
// Check that the first child element is a Username
Node object = null;
while (children.hasNext() && !(object instanceof SOAPElement)) {
object = (Node)children.next();
}
if ((object != null) && (object.getNodeType() == Node.ELEMENT_NODE)) {
SOAPElement element = (SOAPElement) object;
if ("Username".equals(element.getLocalName()) &&
XMLUtil.inWsseNS(element)) {
username = element.getValue();
} else {
log.log(Level.SEVERE,"WSS0330.usernametoken.firstchild.mustbe.username");
throw new SecurityTokenException("The first child of a UsernameToken Element, should be"
+ " a Username ");
}
} else {
invalidToken = true;
}
while (children.hasNext()) {
object = (Node)children.next();
if (object.getNodeType() == Node.ELEMENT_NODE) {
SOAPElement element = (SOAPElement) object;
if ("Password".equals(element.getLocalName()) &&
XMLUtil.inWsseNS(element)) {
String passwordType = element.getAttribute("Type");
if (isBSP() && passwordType.length() < 1) {
// Type should be specified
log.log(Level.SEVERE,"BSP4201.PasswordType.Username");
throw new XWSSecurityException(" A wsse:UsernameToken/wsse:Password element in a SECURITY_HEADER MUST specify a Type attribute.");
}
if (!"".equals(passwordType))
setPasswordType(passwordType);
if (MessageConstants.PASSWORD_TEXT_NS == this.passwordType)
password = element.getValue();
else
passwordDigest = element.getValue();
}
else if ("Nonce".equals(element.getLocalName()) && XMLUtil.inWsseNS(element)) {
nonce = element.getValue();
String encodingType =
element.getAttribute("EncodingType");
if (!"".equals(encodingType))
setNonceEncodingType(encodingType);
try {
decodedNonce = Base64.decode(nonce);
} catch (Base64DecodingException bde) {
log.log(Level.SEVERE, "WSS0309.couldnot.decode.base64.nonce", bde);
throw new XWSSecurityException(bde);
}
}
else if ("Created".equals(element.getLocalName()) &&
XMLUtil.inWsuNS(element)) {
created = element.getValue();
} else {
invalidToken = true;
}
}
}
if (invalidToken) {
log.log(Level.SEVERE, "WSS0331.invalid.usernametoken");
throw new SecurityTokenException(
"Element passed was not a SOAPElement or"
+ " is not a proper UsernameToken");
}
if (null == username) {
log.log(Level.SEVERE, "WSS0332.usernametoken.null.username");
throw new SecurityTokenException(
"Username token does not contain the username");
}
}