public class SecurityContextTokenBuilder implements AssertionBuilder {
public Assertion build(OMElement element, AssertionBuilderFactory factory)
throws IllegalArgumentException {
SecurityContextToken contextToken = new SecurityContextToken();
OMAttribute attribute = element.getAttribute(Constants.INCLUDE_TOKEN);
if (attribute == null) {
throw new IllegalArgumentException(
"SecurityContextToken doesn't contain any sp:IncludeToken attribute");
}
String inclusionValue = attribute.getAttributeValue().trim();
if (inclusionValue.endsWith(Constants.INCLUDE_NEVER)) {
contextToken.setInclusion(Constants.INCLUDE_NEVER);
} else if (inclusionValue.endsWith(Constants.INCLUDE_ONCE)) {
contextToken.setInclusion(Constants.INCLUDE_ONCE);
} else if (inclusionValue
.endsWith(Constants.INCLUDE_ALWAYS_TO_RECIPIENT)) {
contextToken.setInclusion(Constants.INCLUDE_ALWAYS_TO_RECIPIENT);
} else if (inclusionValue.endsWith(Constants.INCLUDE_ALWAYS)) {
contextToken.setInclusion(Constants.INCLUDE_ALWAYS);
}
element = element.getFirstChildWithName(Constants.POLICY);
if (element != null) {
if (element.getFirstChildWithName(Constants.REQUIRE_DERIVED_KEYS) != null) {
contextToken.setDerivedKeys(true);
}
if (element
.getFirstChildWithName(Constants.REQUIRE_EXTERNAL_URI_REFERNCE) != null) {
contextToken.setRequireExternalUriRef(true);
}
if (element
.getFirstChildWithName(Constants.SC10_SECURITY_CONTEXT_TOKEN) != null) {
contextToken.setSc10SecurityContextToken(true);
}
}
return contextToken;
}