View Javadoc
1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied. See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.wss4j.dom.processor;
21  
22  import java.util.List;
23  
24  import org.apache.wss4j.common.ext.WSSecurityException;
25  import org.apache.wss4j.dom.WSConstants;
26  import org.apache.wss4j.dom.engine.WSSecurityEngineResult;
27  import org.apache.wss4j.dom.handler.RequestData;
28  import org.apache.wss4j.dom.message.token.Timestamp;
29  import org.apache.wss4j.dom.validate.Credential;
30  import org.apache.wss4j.dom.validate.Validator;
31  import org.w3c.dom.Element;
32  
33  public class TimestampProcessor implements Processor {
34      private static final org.slf4j.Logger LOG =
35          org.slf4j.LoggerFactory.getLogger(TimestampProcessor.class);
36  
37      public List<WSSecurityEngineResult> handleToken(
38          Element elem,
39          RequestData data
40      ) throws WSSecurityException {
41          LOG.debug("Found Timestamp list element");
42          //
43          // Decode Timestamp, add the found time (created/expiry) to result
44          //
45          Timestamp timestamp = new Timestamp(elem, data.getBSPEnforcer());
46          Credential credential = new Credential();
47          credential.setTimestamp(timestamp);
48  
49          WSSecurityEngineResult result =
50              new WSSecurityEngineResult(WSConstants.TS, timestamp);
51          String tokenId = timestamp.getID();
52          if (tokenId.length() != 0) {
53              result.put(WSSecurityEngineResult.TAG_ID, tokenId);
54          }
55  
56          Validator validator = data.getValidator(WSConstants.TIMESTAMP);
57          if (validator != null) {
58              validator.validate(credential, data);
59  
60              result.put(WSSecurityEngineResult.TAG_VALIDATED_TOKEN, Boolean.TRUE);
61          }
62  
63          data.getWsDocInfo().addTokenElement(elem);
64          data.getWsDocInfo().addResult(result);
65          return java.util.Collections.singletonList(result);
66      }
67  
68  }