jdk/src/share/classes/com/sun/org/apache/xml/internal/security/utils/resolver/ResourceResolverSpi.java
author mullan
Mon, 22 Apr 2013 11:23:33 +0100
changeset 18240 cda839ac048f
parent 10694 cf59e2badd14
child 18780 f47b920867e7
permissions -rw-r--r--
6741606: Integrate Apache Santuario Reviewed-by: vinnie, hawtin
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
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * Copyright  1999-2004 The Apache Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *  Licensed under the Apache License, Version 2.0 (the "License");
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *  you may not use this file except in compliance with the License.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *  You may obtain a copy of the License at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *      http://www.apache.org/licenses/LICENSE-2.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *  Unless required by applicable law or agreed to in writing, software
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *  distributed under the License is distributed on an "AS IS" BASIS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *  See the License for the specific language governing permissions and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *  limitations under the License.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
package com.sun.org.apache.xml.internal.security.utils.resolver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    24
import java.util.HashMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import org.w3c.dom.Attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * During reference validation, we have to retrieve resources from somewhere.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    34
 * @author $Author: mullan $
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
public abstract class ResourceResolverSpi {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
   /** {@link java.util.logging} logging facility */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    static java.util.logging.Logger log =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        java.util.logging.Logger.getLogger(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
                    ResourceResolverSpi.class.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
   /** Field _properties */
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
    44
   protected java.util.Map<String,String> _properties = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    46
   protected boolean secureValidation;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    47
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    * This is the workhorse method used to resolve resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    * @param uri
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    * @param BaseURI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    * @return the resource wrapped arround a XMLSignatureInput
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    * @throws ResourceResolverException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
   public abstract XMLSignatureInput engineResolve(Attr uri, String BaseURI)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
      throws ResourceResolverException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    * Method engineSetProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    * @param key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    * @param value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
   public void engineSetProperty(String key, String value) {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    67
          if (_properties==null) {
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
    68
                  _properties=new HashMap<String,String>();
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    69
          }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
      this._properties.put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    * Method engineGetProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    * @param key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    * @return the value of the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
   public String engineGetProperty(String key) {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    80
          if (_properties==null) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    81
                        return null;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    82
          }
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
    83
      return this._properties.get(key);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    * @param properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    */
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
    90
   public void engineAddProperies(Map<String,String> properties) {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    91
          if (properties!=null) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    92
                  if (_properties==null) {
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
    93
                          _properties=new HashMap<String,String>();
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    94
                  }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    95
                  this._properties.putAll(properties);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    96
          }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
   }
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    98
   /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    99
    * Tells if the implementation does can be reused by several threads safely.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   100
    * It normally means that the implemantation does not have any member, or there is
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   101
    * member change betwen engineCanResolve & engineResolve invocations. Or it mantians all
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   102
    * member info in ThreadLocal methods.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   103
    */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   104
   public boolean engineIsThreadSafe() {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   105
           return false;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   106
   }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    * This method helps the {@link ResourceResolver} to decide whether a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    * {@link ResourceResolverSpi} is able to perform the requested action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    * @param uri
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    * @param BaseURI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    * @return true if the engine can resolve the uri
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
   public abstract boolean engineCanResolve(Attr uri, String BaseURI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    * Method engineGetPropertyKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    * @return the property keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
   public String[] engineGetPropertyKeys() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
      return new String[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    * Method understandsProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    * @param propertyToTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    * @return true if understands the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
   public boolean understandsProperty(String propertyToTest) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
      String[] understood = this.engineGetPropertyKeys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
      if (understood != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
         for (int i = 0; i < understood.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            if (understood[i].equals(propertyToTest)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
               return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
      return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    * Fixes a platform dependent filename to standard URI form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    * @param str The string to fix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    * @return Returns the fixed URI string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
   public static String fixURI(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
      // handle platform dependent strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
      str = str.replace(java.io.File.separatorChar, '/');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
      if (str.length() >= 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
         // str =~ /^\W:\/([^/])/ # to speak perl ;-))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
         char ch0 = Character.toUpperCase(str.charAt(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
         char ch1 = str.charAt(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
         char ch2 = str.charAt(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
         char ch3 = str.charAt(3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
         boolean isDosFilename = ((('A' <= ch0) && (ch0 <= 'Z'))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                                  && (ch1 == ':') && (ch2 == '/')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                                  && (ch3 != '/'));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
         if (isDosFilename) {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   172
            if (log.isLoggable(java.util.logging.Level.FINE))
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   173
                log.log(java.util.logging.Level.FINE, "Found DOS filename: " + str);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
      // Windows fix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
      if (str.length() >= 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
         char ch1 = str.charAt(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
         if (ch1 == ':') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            char ch0 = Character.toUpperCase(str.charAt(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            if (('A' <= ch0) && (ch0 <= 'Z')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
               str = "/" + str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
      // done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
      return str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
}