1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.wss4j.policy.builders;
20
21 import javax.xml.namespace.QName;
22
23 import org.apache.neethi.Assertion;
24 import org.apache.neethi.AssertionBuilderFactory;
25 import org.apache.neethi.Policy;
26 import org.apache.neethi.builders.AssertionBuilder;
27 import org.apache.wss4j.policy.SP11Constants;
28 import org.apache.wss4j.policy.SP13Constants;
29 import org.apache.wss4j.policy.SPConstants;
30 import org.apache.wss4j.policy.SPUtils;
31 import org.apache.wss4j.policy.model.AlgorithmSuite;
32 import org.w3c.dom.Element;
33
34 public class AlgorithmSuiteBuilder implements AssertionBuilder<Element> {
35
36 @Override
37 public Assertion build(Element element, AssertionBuilderFactory factory) throws IllegalArgumentException {
38
39 final SPConstants.SPVersion spVersion = SPConstants.SPVersion.getSPVersion(element.getNamespaceURI());
40 final Element nestedPolicyElement = SPUtils.getFirstPolicyChildElement(element);
41 if (nestedPolicyElement == null) {
42 throw new IllegalArgumentException("sp:AlgorithmSuite must have an inner wsp:Policy element");
43 }
44 final Policy nestedPolicy = factory.getPolicyEngine().getPolicy(nestedPolicyElement);
45 AlgorithmSuite algorithmSuite = createAlgorithmSuite(
46 spVersion,
47 nestedPolicy
48 );
49 algorithmSuite.setOptional(SPUtils.isOptional(element));
50 algorithmSuite.setIgnorable(SPUtils.isIgnorable(element));
51 return algorithmSuite;
52 }
53
54 @Override
55 public QName[] getKnownElements() {
56 return new QName[]{SP13Constants.ALGORITHM_SUITE, SP11Constants.ALGORITHM_SUITE};
57 }
58
59 protected AlgorithmSuite createAlgorithmSuite(SPConstants.SPVersion version, Policy nestedPolicy) {
60 return new AlgorithmSuite(version, nestedPolicy);
61 }
62 }