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  package org.apache.wss4j.stax.impl.transformer;
20  
21  import org.apache.wss4j.common.ext.WSSecurityException;
22  import org.apache.xml.security.exceptions.XMLSecurityException;
23  import org.apache.xml.security.stax.ext.Transformer;
24  import org.apache.xml.security.stax.impl.transformer.TransformIdentity;
25  import org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_Excl;
26  
27  import java.util.ArrayList;
28  import java.util.HashMap;
29  import java.util.List;
30  import java.util.Map;
31  
32  public class STRTransformer extends TransformIdentity {
33  
34      @Override
35      public void setTransformer(Transformer transformer) throws XMLSecurityException {
36          if (!(transformer instanceof Canonicalizer20010315_Excl)) {
37              throw new WSSecurityException(WSSecurityException.ErrorCode.INVALID_SECURITY);
38          }
39          List<String> inclusiveNamespacesPrefixList = new ArrayList<>();
40          inclusiveNamespacesPrefixList.add("#default");
41          Map<String, Object> transformerProperties = new HashMap<>();
42          transformerProperties.put(
43              Canonicalizer20010315_Excl.INCLUSIVE_NAMESPACES_PREFIX_LIST, inclusiveNamespacesPrefixList);
44          transformerProperties.put(Canonicalizer20010315_Excl.PROPAGATE_DEFAULT_NAMESPACE, Boolean.TRUE);
45          transformer.setProperties(transformerProperties);
46          super.setTransformer(transformer);
47      }
48  
49  }