1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.wss4j.policy.model;
20
21 import org.apache.neethi.Assertion;
22 import org.apache.neethi.Policy;
23 import org.apache.wss4j.policy.SPConstants;
24
25 import javax.xml.namespace.QName;
26 import java.util.Iterator;
27 import java.util.List;
28
29 public class KeyValueToken extends AbstractToken {
30
31 private boolean rsaKeyValue;
32
33 public KeyValueToken(SPConstants.SPVersion version, SPConstants.IncludeTokenType includeTokenType,
34 Policy nestedPolicy) {
35 super(version, includeTokenType, null, null, null, nestedPolicy);
36 setIncludeTokenType(includeTokenType);
37
38 parseNestedPolicy(nestedPolicy, this);
39 }
40
41 @Override
42 public QName getName() {
43 return getVersion().getSPConstants().getKeyValueToken();
44 }
45
46 @Override
47 public boolean equals(Object object) {
48 if (object == this) {
49 return true;
50 }
51 if (!(object instanceof KeyValueToken)) {
52 return false;
53 }
54
55 KeyValueToken that = (KeyValueToken)object;
56 if (rsaKeyValue != that.rsaKeyValue) {
57 return false;
58 }
59
60 return super.equals(object);
61 }
62
63 @Override
64 public int hashCode() {
65 int result = 17;
66 result = 31 * result + Boolean.hashCode(rsaKeyValue);
67
68 return 31 * result + super.hashCode();
69 }
70
71 @Override
72 protected AbstractSecurityAssertion cloneAssertion(Policy nestedPolicy) {
73 return new KeyValueToken(getVersion(), getIncludeTokenType(), nestedPolicy);
74 }
75
76 protected void parseNestedPolicy(Policy nestedPolicy, KeyValueToken keyValueToken) {
77 Iterator<List<Assertion>> alternatives = nestedPolicy.getAlternatives();
78
79
80
81 if (alternatives.hasNext()) {
82 List<Assertion> assertions = alternatives.next();
83 for (Assertion assertion : assertions) {
84 String assertionName = assertion.getName().getLocalPart();
85 String assertionNamespace = assertion.getName().getNamespaceURI();
86
87 QName rsaKeyValue = getVersion().getSPConstants().getRsaKeyValue();
88 if (rsaKeyValue.getLocalPart().equals(assertionName)
89 && rsaKeyValue.getNamespaceURI().equals(assertionNamespace)) {
90 if (keyValueToken.isRsaKeyValue()) {
91 throw new IllegalArgumentException(SPConstants.ERR_INVALID_POLICY);
92 }
93 keyValueToken.setRsaKeyValue(true);
94 continue;
95 }
96 }
97 }
98 }
99
100 public boolean isRsaKeyValue() {
101 return rsaKeyValue;
102 }
103
104 protected void setRsaKeyValue(boolean rsaKeyValue) {
105 this.rsaKeyValue = rsaKeyValue;
106 }
107 }