1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.wss4j.policy.stax.assertionStates;
20
21 import javax.xml.namespace.QName;
22
23 import org.apache.wss4j.policy.AssertionState;
24 import org.apache.wss4j.policy.SPConstants;
25 import org.apache.wss4j.policy.model.AbstractBinding;
26 import org.apache.wss4j.policy.model.AbstractSecurityAssertion;
27 import org.apache.xml.security.stax.securityEvent.SecurityEvent;
28 import org.apache.xml.security.stax.securityEvent.SecurityEventConstants;
29 import org.apache.wss4j.policy.stax.Assertable;
30 import org.apache.wss4j.policy.stax.DummyPolicyAsserter;
31 import org.apache.wss4j.policy.stax.PolicyAsserter;
32 import org.apache.wss4j.stax.securityEvent.WSSecurityEventConstants;
33
34
35
36
37 public class IncludeTimeStampAssertionState extends AssertionState implements Assertable {
38
39 private PolicyAsserter policyAsserter;
40
41 public IncludeTimeStampAssertionState(AbstractSecurityAssertion assertion,
42 PolicyAsserter policyAsserter,
43 boolean asserted) {
44 super(assertion, asserted);
45 this.policyAsserter = policyAsserter;
46 if (this.policyAsserter == null) {
47 this.policyAsserter = new DummyPolicyAsserter();
48 }
49
50 if (asserted) {
51 String namespace = getAssertion().getName().getNamespaceURI();
52 policyAsserter.assertPolicy(new QName(namespace, SPConstants.INCLUDE_TIMESTAMP));
53 }
54 }
55
56 @Override
57 public SecurityEventConstants.Event[] getSecurityEventType() {
58 return new SecurityEventConstants.Event[]{
59 WSSecurityEventConstants.TIMESTAMP
60 };
61 }
62
63 @Override
64 public boolean assertEvent(SecurityEvent securityEvent) {
65
66 boolean isIncludeTimestamp = ((AbstractBinding) getAssertion()).isIncludeTimestamp();
67
68 String namespace = getAssertion().getName().getNamespaceURI();
69 if (isIncludeTimestamp) {
70 setAsserted(true);
71 policyAsserter.assertPolicy(new QName(namespace, SPConstants.INCLUDE_TIMESTAMP));
72 } else {
73 setAsserted(false);
74 setErrorMessage("Timestamp must not be present");
75 policyAsserter.unassertPolicy(new QName(namespace, SPConstants.INCLUDE_TIMESTAMP),
76 getErrorMessage());
77 }
78 return isAsserted();
79 }
80 }