src/java.xml.crypto/share/classes/com/sun/org/apache/xml/internal/security/Init.java
author jlaskey
Thu, 21 Jun 2018 08:58:59 -0300
changeset 50695 36ca515343e0
parent 50614 3810c9a2efa1
child 59240 b3116877866f
permissions -rw-r--r--
8203637: Fix Sources Reviewed-by: hannesw, sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 */
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
     5
/**
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
     7
 * or more contributor license agreements. See the NOTICE file
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
     8
 * distributed with this work for additional information
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
     9
 * regarding copyright ownership. The ASF licenses this file
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    10
 * to you under the Apache License, Version 2.0 (the
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    11
 * "License"); you may not use this file except in compliance
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    12
 * with the License. You may obtain a copy of the License at
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    14
 * http://www.apache.org/licenses/LICENSE-2.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    16
 * Unless required by applicable law or agreed to in writing,
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    17
 * software distributed under the License is distributed on an
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    18
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    19
 * KIND, either express or implied. See the License for the
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    20
 * specific language governing permissions and limitations
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    21
 * under the License.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
package com.sun.org.apache.xml.internal.security;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.security.PrivilegedAction;
27081
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
    28
import java.security.PrivilegedActionException;
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
    29
import java.security.PrivilegedExceptionAction;
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    30
import java.util.ArrayList;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    31
import java.util.List;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    32
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.xml.parsers.DocumentBuilder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.xml.internal.security.algorithms.JCEMapper;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.xml.internal.security.algorithms.SignatureAlgorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer;
27081
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
    38
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import com.sun.org.apache.xml.internal.security.transforms.Transform;
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    41
import com.sun.org.apache.xml.internal.security.utils.ElementProxy;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import com.sun.org.apache.xml.internal.security.utils.I18n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import org.w3c.dom.Attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import org.w3c.dom.Document;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import org.w3c.dom.Element;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import org.w3c.dom.Node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * This class does the configuration of the library. This includes creating
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * the mapping of Canonicalization and Transform algorithms. Initialization is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * done by calling {@link Init#init} which should be done in any static block
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * of the files of this library. We ensure that this call is only executed once.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 */
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    57
public class Init {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    59
    /** The namespace for CONF file **/
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    60
    public static final String CONF_NS = "http://www.xmlsecurity.org/NS/#configuration";
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    61
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    62
    private static final com.sun.org.slf4j.internal.Logger LOG =
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    63
        com.sun.org.slf4j.internal.LoggerFactory.getLogger(Init.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    65
    /** Field alreadyInitialized */
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    66
    private static boolean alreadyInitialized = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    68
    /**
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    69
     * Method isInitialized
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    70
     * @return true if the library is already initialized.
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    71
     */
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    72
    public static final synchronized boolean isInitialized() {
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    73
        return Init.alreadyInitialized;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    74
    }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    75
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    76
    /**
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    77
     * Method init
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    78
     *
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    79
     */
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    80
    public static synchronized void init() {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    81
        if (alreadyInitialized) {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    82
            return;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    83
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    85
        InputStream is =
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    86
            AccessController.doPrivileged(
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    87
                (PrivilegedAction<InputStream>)
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    88
                    () -> {
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    89
                        String cfile =
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    90
                            System.getProperty("com.sun.org.apache.xml.internal.security.resource.config");
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    91
                        if (cfile == null) {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    92
                            return null;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    93
                        }
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    94
                        return Init.class.getResourceAsStream(cfile);
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    95
                    }
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    96
                );
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    97
        if (is == null) {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    98
            dynamicInit();
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
    99
        } else {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   100
            fileInit(is);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   101
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   103
        alreadyInitialized = true;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   104
    }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   105
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   106
    /**
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   107
     * Dynamically initialise the library by registering the default algorithms/implementations
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   108
     */
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   109
    private static void dynamicInit() {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   110
        //
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   111
        // Load the Resource Bundle - the default is the English resource bundle.
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   112
        // To load another resource bundle, call I18n.init(...) before calling this
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   113
        // method.
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   114
        //
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   115
        I18n.init("en", "US");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   117
        LOG.debug("Registering default algorithms");
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   118
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   119
        try {
27081
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   120
            AccessController.doPrivileged(new PrivilegedExceptionAction<Void>(){
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   121
                @Override public Void run() throws XMLSecurityException {
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   122
                    //
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   123
                    // Bind the default prefixes
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   124
                    //
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   125
                    ElementProxy.registerDefaultPrefixes();
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   126
27081
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   127
                    //
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   128
                    // Set the default Transforms
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   129
                    //
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   130
                    Transform.registerDefaultAlgorithms();
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   131
27081
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   132
                    //
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   133
                    // Set the default signature algorithms
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   134
                    //
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   135
                    SignatureAlgorithm.registerDefaultAlgorithms();
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   136
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   137
                    //
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   138
                    // Set the default JCE algorithms
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   139
                    //
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   140
                    JCEMapper.registerDefaultAlgorithms();
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   141
27081
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   142
                    //
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   143
                    // Set the default c14n algorithms
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   144
                    //
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   145
                    Canonicalizer.registerDefaultAlgorithms();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
27081
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   147
                    //
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   148
                    // Register the default resolvers
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   149
                    //
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   150
                    ResourceResolver.registerDefaultResolvers();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
27081
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   152
                    //
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   153
                    // Register the default key resolvers
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   154
                    //
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   155
                    KeyResolver.registerDefaultResolvers();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
27081
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   157
                    return null;
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   158
                }
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   159
            });
27081
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   160
        } catch (PrivilegedActionException ex) {
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   161
            XMLSecurityException xse = (XMLSecurityException)ex.getException();
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   162
            LOG.error(xse.getMessage(), xse);
27081
1ceee8d3844d 8038913: Bolster XML support
mullan
parents: 25859
diff changeset
   163
            xse.printStackTrace();
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   164
        }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   165
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   167
    /**
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   168
     * Initialise the library from a configuration file
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   169
     */
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   170
    private static void fileInit(InputStream is) {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   171
        try {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            /* read library configuration file */
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   173
            DocumentBuilder db = XMLUtils.createDocumentBuilder(false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            Document doc = db.parse(is);
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   175
            Node config = doc.getFirstChild();
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   176
            for (; config != null; config = config.getNextSibling()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                if ("Configuration".equals(config.getLocalName())) {
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   178
                    break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            }
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   181
            if (config == null) {
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   182
                LOG.error("Error in reading configuration file - Configuration element not found");
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   183
                return;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   184
            }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   185
            for (Node el = config.getFirstChild(); el != null; el = el.getNextSibling()) {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   186
                if (Node.ELEMENT_NODE != el.getNodeType()) {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   187
                    continue;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   188
                }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   189
                String tag = el.getLocalName();
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   190
                if ("ResourceBundles".equals(tag)) {
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   191
                    Element resource = (Element)el;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   192
                    /* configure internationalization */
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   193
                    Attr langAttr = resource.getAttributeNodeNS(null, "defaultLanguageCode");
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   194
                    Attr countryAttr = resource.getAttributeNodeNS(null, "defaultCountryCode");
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   195
                    String languageCode =
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   196
                        (langAttr == null) ? null : langAttr.getNodeValue();
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   197
                    String countryCode =
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   198
                        (countryAttr == null) ? null : countryAttr.getNodeValue();
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   199
                    I18n.init(languageCode, countryCode);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                }
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   201
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   202
                if ("CanonicalizationMethods".equals(tag)) {
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   203
                    Element[] list =
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   204
                        XMLUtils.selectNodes(el.getFirstChild(), CONF_NS, "CanonicalizationMethod");
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   205
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   206
                    for (Element element : list) {
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   207
                        String uri = element.getAttributeNS(null, "URI");
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   208
                        String javaClass =
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   209
                            element.getAttributeNS(null, "JAVACLASS");
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   210
                        try {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   211
                            Canonicalizer.register(uri, javaClass);
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   212
                            LOG.debug("Canonicalizer.register({}, {})", uri, javaClass);
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   213
                        } catch (ClassNotFoundException e) {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   214
                            Object exArgs[] = { uri, javaClass };
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   215
                            LOG.error(I18n.translate("algorithm.classDoesNotExist", exArgs));
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   216
                        }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   217
                    }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   218
                }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   219
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   220
                if ("TransformAlgorithms".equals(tag)) {
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   221
                    Element[] tranElem =
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   222
                        XMLUtils.selectNodes(el.getFirstChild(), CONF_NS, "TransformAlgorithm");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   224
                    for (Element element : tranElem) {
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   225
                        String uri = element.getAttributeNS(null, "URI");
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   226
                        String javaClass =
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   227
                            element.getAttributeNS(null, "JAVACLASS");
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   228
                        try {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   229
                            Transform.register(uri, javaClass);
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   230
                            LOG.debug("Transform.register({}, {})", uri, javaClass);
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   231
                        } catch (ClassNotFoundException e) {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   232
                            Object exArgs[] = { uri, javaClass };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   234
                            LOG.error(I18n.translate("algorithm.classDoesNotExist", exArgs));
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   235
                        } catch (NoClassDefFoundError ex) {
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   236
                            LOG.warn("Not able to found dependencies for algorithm, I'll keep working.");
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   237
                        }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   238
                    }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   239
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   241
                if ("JCEAlgorithmMappings".equals(tag)) {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   242
                    Node algorithmsNode = ((Element)el).getElementsByTagName("Algorithms").item(0);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   243
                    if (algorithmsNode != null) {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   244
                        Element[] algorithms =
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   245
                            XMLUtils.selectNodes(algorithmsNode.getFirstChild(), CONF_NS, "Algorithm");
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   246
                        for (Element element : algorithms) {
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   247
                            String id = element.getAttributeNS(null, "URI");
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   248
                            JCEMapper.register(id, new JCEMapper.Algorithm(element));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                        }
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   250
                    }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   251
                }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   252
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   253
                if ("SignatureAlgorithms".equals(tag)) {
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   254
                    Element[] sigElems =
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   255
                        XMLUtils.selectNodes(el.getFirstChild(), CONF_NS, "SignatureAlgorithm");
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   256
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   257
                    for (Element sigElem : sigElems) {
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   258
                        String uri = sigElem.getAttributeNS(null, "URI");
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   259
                        String javaClass =
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   260
                            sigElem.getAttributeNS(null, "JAVACLASS");
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   261
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   262
                        /** $todo$ handle registering */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   264
                        try {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   265
                            SignatureAlgorithm.register(uri, javaClass);
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   266
                            LOG.debug("SignatureAlgorithm.register({}, {})", uri, javaClass);
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   267
                        } catch (ClassNotFoundException e) {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   268
                            Object exArgs[] = { uri, javaClass };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   270
                            LOG.error(I18n.translate("algorithm.classDoesNotExist", exArgs));
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   271
                        }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   272
                    }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   273
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   275
                if ("ResourceResolvers".equals(tag)) {
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   276
                    Element[] resolverElem =
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   277
                        XMLUtils.selectNodes(el.getFirstChild(), CONF_NS, "Resolver");
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   278
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   279
                    for (Element element : resolverElem) {
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   280
                        String javaClass =
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   281
                            element.getAttributeNS(null, "JAVACLASS");
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   282
                        String description =
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   283
                            element.getAttributeNS(null, "DESCRIPTION");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   285
                        if (description != null && description.length() > 0) {
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   286
                            LOG.debug("Register Resolver: {}: {}", javaClass, description);
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   287
                        } else {
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   288
                            LOG.debug("Register Resolver: {}: For unknown purposes", javaClass);
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   289
                        }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   290
                        try {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   291
                            ResourceResolver.register(javaClass);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   292
                        } catch (Throwable e) {
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   293
                            LOG.warn(
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   294
                                 "Cannot register:" + javaClass
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   295
                                 + " perhaps some needed jars are not installed",
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   296
                                 e
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   297
                             );
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   298
                        }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   299
                    }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   300
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   302
                if ("KeyResolver".equals(tag)){
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   303
                    Element[] resolverElem =
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   304
                        XMLUtils.selectNodes(el.getFirstChild(), CONF_NS, "Resolver");
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   305
                    List<String> classNames = new ArrayList<>(resolverElem.length);
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   306
                    for (Element element : resolverElem) {
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   307
                        String javaClass =
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   308
                            element.getAttributeNS(null, "JAVACLASS");
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   309
                        String description =
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   310
                            element.getAttributeNS(null, "DESCRIPTION");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   312
                        if (description != null && description.length() > 0) {
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   313
                            LOG.debug("Register Resolver: {}: {}", javaClass, description);
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   314
                        } else {
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   315
                            LOG.debug("Register Resolver: {}: For unknown purposes", javaClass);
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   316
                        }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   317
                        classNames.add(javaClass);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   318
                    }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   319
                    KeyResolver.registerClassNames(classNames);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   320
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   323
                if ("PrefixMappings".equals(tag)){
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   324
                    LOG.debug("Now I try to bind prefixes:");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   326
                    Element[] nl =
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   327
                        XMLUtils.selectNodes(el.getFirstChild(), CONF_NS, "PrefixMapping");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   329
                    for (Element element : nl) {
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   330
                        String namespace = element.getAttributeNS(null, "namespace");
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   331
                        String prefix = element.getAttributeNS(null, "prefix");
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   332
                        LOG.debug("Now I try to bind {} to {}", prefix, namespace);
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   333
                        ElementProxy.setDefaultPrefix(namespace, prefix);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   334
                    }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   335
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            }
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   337
        } catch (Exception e) {
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   338
            LOG.error("Bad: ", e);
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   339
        }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   340
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
}
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 13791
diff changeset
   343