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.ws.security.processor;
21  
22  import org.apache.ws.security.WSConstants;
23  import org.apache.ws.security.WSDocInfo;
24  import org.apache.ws.security.WSSConfig;
25  import org.apache.ws.security.WSSecurityEngine;
26  import org.apache.ws.security.WSSecurityEngineResult;
27  import org.apache.ws.security.WSSecurityException;
28  import org.apache.ws.security.handler.RequestData;
29  import org.apache.ws.security.message.token.Timestamp;
30  import org.apache.ws.security.validate.Credential;
31  import org.apache.ws.security.validate.Validator;
32  import org.w3c.dom.Element;
33  
34  import java.util.List;
35  
36  public class TimestampProcessor implements Processor {
37      private static org.apache.commons.logging.Log log = 
38          org.apache.commons.logging.LogFactory.getLog(TimestampProcessor.class);
39  
40      public List<WSSecurityEngineResult> handleToken(
41          Element elem, 
42          RequestData data,
43          WSDocInfo wsDocInfo
44      ) throws WSSecurityException {
45          if (log.isDebugEnabled()) {
46              log.debug("Found Timestamp list element");
47          }
48          //
49          // Decode Timestamp, add the found time (created/expiry) to result
50          //
51          WSSConfig config = data.getWssConfig();
52          Timestamp timestamp = new Timestamp(elem, config.isWsiBSPCompliant());
53          Credential credential = new Credential();
54          credential.setTimestamp(timestamp);
55          
56          WSSecurityEngineResult result = 
57              new WSSecurityEngineResult(WSConstants.TS, timestamp);
58          result.put(WSSecurityEngineResult.TAG_ID, timestamp.getID());
59          
60          Validator validator = data.getValidator(WSSecurityEngine.TIMESTAMP);
61          if (validator != null) {
62              validator.validate(credential, data);
63              
64              result.put(WSSecurityEngineResult.TAG_VALIDATED_TOKEN, Boolean.TRUE);
65          }
66          
67          wsDocInfo.addTokenElement(elem);
68          wsDocInfo.addResult(result);
69          return java.util.Collections.singletonList(result);
70      }
71  
72  }