src/java.xml/share/classes/com/sun/org/apache/xerces/internal/utils/XMLSecurityPropertyManager.java
author joehw
Wed, 04 Oct 2017 10:54:18 -0700
changeset 47312 d4f959806fe9
parent 47216 71c04702a3d5
permissions -rw-r--r--
8187593: Cleanup: removing SecuritySupport files Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18890
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
     1
/*
47312
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
     2
 * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
18890
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
     4
 *
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    10
 *
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    15
 * accompanied this code).
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    16
 *
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    20
 *
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    23
 * questions.
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    24
 */
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    25
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    26
package com.sun.org.apache.xerces.internal.utils;
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    27
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    28
import com.sun.org.apache.xerces.internal.impl.Constants;
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    29
import javax.xml.XMLConstants;
47312
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
    30
import jdk.xml.internal.SecuritySupport;
18890
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    31
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    32
/**
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    33
 * This class manages security related properties
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    34
 *
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    35
 */
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    36
public final class XMLSecurityPropertyManager {
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    37
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    38
    /**
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    39
     * States of the settings of a property, in the order: default value, value
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    40
     * set by FEATURE_SECURE_PROCESSING, jaxp.properties file, jaxp system
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    41
     * properties, and jaxp api properties
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    42
     */
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    43
    public static enum State {
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    44
        //this order reflects the overriding order
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    45
        DEFAULT, FSP, JAXPDOTPROPERTIES, SYSTEMPROPERTY, APIPROPERTY
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    46
    }
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    47
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    48
    /**
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    49
     * Limits managed by the security manager
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    50
     */
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    51
    public static enum Property {
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    52
        ACCESS_EXTERNAL_DTD(XMLConstants.ACCESS_EXTERNAL_DTD,
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    53
                Constants.EXTERNAL_ACCESS_DEFAULT),
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    54
        ACCESS_EXTERNAL_SCHEMA(XMLConstants.ACCESS_EXTERNAL_SCHEMA,
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    55
                Constants.EXTERNAL_ACCESS_DEFAULT);
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    56
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    57
        final String name;
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    58
        final String defaultValue;
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    59
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    60
        Property(String name, String value) {
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    61
            this.name = name;
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    62
            this.defaultValue = value;
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    63
        }
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    64
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    65
        public boolean equalsName(String propertyName) {
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    66
            return (propertyName == null) ? false : name.equals(propertyName);
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    67
        }
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    68
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    69
        String defaultValue() {
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    70
            return defaultValue;
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    71
        }
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    72
    }
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    73
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    74
    /**
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    75
     * Values of the properties as defined in enum Properties
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    76
     */
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    77
    private final String[] values;
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    78
    /**
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    79
     * States of the settings for each property in Properties above
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    80
     */
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    81
    private State[] states = {State.DEFAULT, State.DEFAULT};
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    82
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    83
    /**
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    84
     * Default constructor. Establishes default values
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    85
     */
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    86
    public XMLSecurityPropertyManager() {
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    87
        values = new String[Property.values().length];
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    88
        for (Property property : Property.values()) {
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    89
            values[property.ordinal()] = property.defaultValue();
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    90
        }
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    91
        //read system properties or jaxp.properties
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    92
        readSystemProperties();
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    93
    }
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
    94
20968
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
    95
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
    96
    /**
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
    97
     * Set limit by property name and state
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
    98
     * @param propertyName property name
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
    99
     * @param state the state of the property
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   100
     * @param value the value of the property
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   101
     * @return true if the property is managed by the security property manager;
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   102
     *         false if otherwise.
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   103
     */
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   104
    public boolean setValue(String propertyName, State state, Object value) {
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   105
        int index = getIndex(propertyName);
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   106
        if (index > -1) {
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   107
            setValue(index, state, (String)value);
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   108
            return true;
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   109
        }
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   110
        return false;
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   111
    }
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   112
18890
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   113
    /**
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   114
     * Set the value for a specific property.
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   115
     *
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   116
     * @param property the property
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   117
     * @param state the state of the property
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   118
     * @param value the value of the property
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   119
     */
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   120
    public void setValue(Property property, State state, String value) {
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   121
        //only update if it shall override
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   122
        if (state.compareTo(states[property.ordinal()]) >= 0) {
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   123
            values[property.ordinal()] = value;
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   124
            states[property.ordinal()] = state;
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   125
        }
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   126
    }
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   127
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   128
    /**
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   129
     * Set the value of a property by its index
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   130
     * @param index the index of the property
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   131
     * @param state the state of the property
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   132
     * @param value the value of the property
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   133
     */
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   134
    public void setValue(int index, State state, String value) {
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   135
        //only update if it shall override
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   136
        if (state.compareTo(states[index]) >= 0) {
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   137
            values[index] = value;
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   138
            states[index] = state;
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   139
        }
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   140
    }
20968
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   141
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   142
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   143
    /**
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   144
     * Return the value of the specified property
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   145
     *
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   146
     * @param propertyName the property name
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   147
     * @return the value of the property as a string
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   148
     */
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   149
    public String getValue(String propertyName) {
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   150
        int index = getIndex(propertyName);
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   151
        if (index > -1) {
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   152
            return getValueByIndex(index);
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   153
        }
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   154
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   155
        return null;
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   156
    }
dde41f8b7b96 8014530: Better digital signature processing
joehw
parents: 18890
diff changeset
   157
18890
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   158
    /**
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   159
     * Return the value of the specified property
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   160
     *
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   161
     * @param property the property
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   162
     * @return the value of the property
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   163
     */
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   164
    public String getValue(Property property) {
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   165
        return values[property.ordinal()];
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   166
    }
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   167
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   168
    /**
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   169
     * Return the value of a property by its ordinal
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   170
     * @param index the index of a property
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   171
     * @return value of a property
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   172
     */
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   173
    public String getValueByIndex(int index) {
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   174
        return values[index];
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   175
    }
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   176
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   177
    /**
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   178
     * Get the index by property name
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   179
     * @param propertyName property name
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   180
     * @return the index of the property if found; return -1 if not
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   181
     */
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   182
    public int getIndex(String propertyName){
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   183
        for (Property property : Property.values()) {
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   184
            if (property.equalsName(propertyName)) {
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   185
                //internally, ordinal is used as index
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   186
                return property.ordinal();
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   187
            }
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   188
        }
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   189
        return -1;
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   190
    }
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   191
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   192
    /**
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   193
     * Read from system properties, or those in jaxp.properties
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   194
     */
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   195
    private void readSystemProperties() {
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   196
        getSystemProperty(Property.ACCESS_EXTERNAL_DTD,
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   197
                Constants.SP_ACCESS_EXTERNAL_DTD);
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   198
        getSystemProperty(Property.ACCESS_EXTERNAL_SCHEMA,
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   199
                Constants.SP_ACCESS_EXTERNAL_SCHEMA);
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   200
    }
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   201
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   202
    /**
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   203
     * Read from system properties, or those in jaxp.properties
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   204
     *
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   205
     * @param property the property
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   206
     * @param systemProperty the name of the system property
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   207
     */
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   208
    private void getSystemProperty(Property property, String systemProperty) {
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   209
        try {
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   210
            String value = SecuritySupport.getSystemProperty(systemProperty);
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   211
            if (value != null) {
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   212
                values[property.ordinal()] = value;
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   213
                states[property.ordinal()] = State.SYSTEMPROPERTY;
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   214
                return;
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   215
            }
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   216
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   217
            value = SecuritySupport.readJAXPProperty(systemProperty);
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   218
            if (value != null) {
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   219
                values[property.ordinal()] = value;
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   220
                states[property.ordinal()] = State.JAXPDOTPROPERTIES;
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   221
            }
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   222
        } catch (NumberFormatException e) {
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   223
            //invalid setting ignored
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   224
        }
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   225
    }
25bdeca3173b 8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
diff changeset
   226
}