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.WSSecurityEngineResult;
25  import org.apache.ws.security.WSSecurityException;
26  import org.apache.ws.security.handler.RequestData;
27  import org.apache.ws.security.message.token.SignatureConfirmation;
28  import org.w3c.dom.Element;
29  
30  import java.util.List;
31  
32  public class SignatureConfirmationProcessor implements Processor {
33      private static org.apache.commons.logging.Log log = 
34          org.apache.commons.logging.LogFactory.getLog(SignatureConfirmationProcessor.class);
35      
36      public List<WSSecurityEngineResult> handleToken(
37          Element elem, 
38          RequestData data,
39          WSDocInfo wsDocInfo 
40      ) throws WSSecurityException {
41          if (log.isDebugEnabled()) {
42              log.debug("Found SignatureConfirmation list element");
43          }
44          //
45          // Decode SignatureConfirmation, just store in result
46          //
47          SignatureConfirmation sigConf = new SignatureConfirmation(elem);
48          String id = sigConf.getID();
49          // A wsu:Id is required as per the BSP spec
50          if (data.getWssConfig().isWsiBSPCompliant() && (id == null || "".equals(id))) {
51              throw new WSSecurityException(
52                  WSSecurityException.INVALID_SECURITY, 
53                  "requiredElementNoID", 
54                  new Object[] {elem.getLocalName()}
55              );
56          }
57          
58          WSSecurityEngineResult result = 
59              new WSSecurityEngineResult(WSConstants.SC, sigConf);
60          result.put(WSSecurityEngineResult.TAG_ID, id);
61          wsDocInfo.addResult(result);
62          wsDocInfo.addTokenElement(elem);
63          return java.util.Collections.singletonList(result);
64      }
65      
66  }