/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* List of Providers. Used to represent the provider preferences.
*
* The system starts out with a ProviderList that only has the classNames
* of the Providers. Providers are loaded on demand only when needed.
*
* For compatibility reasons, Providers that could not be loaded are ignored
* and internally presented as the instance EMPTY_PROVIDER. However, those
* objects cannot be presented to applications. Call the convert() method
* to force all Providers to be loaded and to obtain a ProviderList with
* invalid entries removed. All this is handled by the Security class.
*
* Note that all indices used by this class are 0-based per general Java
* convention. These must be converted to the 1-based indices used by the
* Security class externally when needed.
*
* Instances of this class are immutable. This eliminates the need for
* cloning and synchronization in consumers. The add() and remove() style
* methods are static in order to avoid confusion about the immutability.
*
* @author Andreas Sterbenz
* @since 1.5
*/
public final class ProviderList {
// constant for an ProviderList with no elements
// dummy provider object to use during initialization
// used to avoid explicit null checks in various places
// override getService() to return null slightly faster
return null;
}
};
// construct a ProviderList from the security properties
// (static provider configuration in the java.security file)
// doPrivileged() because of Security.getProperty()
return AccessController.doPrivileged(
new PrivilegedAction<ProviderList>() {
public ProviderList run() {
return new ProviderList();
}
});
}
}
int position) {
return providerList;
}
position = n;
}
}
// make sure provider exists
return providerList;
}
// copy all except matching to new list
int j = 0;
}
}
return new ProviderList(configs, true);
}
// Create a new ProviderList from the specified Providers.
// This method is for use by SunJSSE.
}
return new ProviderList(configs, true);
}
// configuration of the providers
// flag indicating whether all configs have been loaded successfully
private volatile boolean allLoaded;
// List returned by providers()
public int size() {
}
return getProvider(index);
}
};
/**
* Create a new ProviderList from an array of configs
*/
}
/**
* Return a new ProviderList parsed from the java.security Properties.
*/
private ProviderList() {
for (int i = 1; true; i++) {
break;
}
"security.provider." + i);
break;
}
if (k == -1) {
} else {
}
// Get rid of duplicate providers.
}
}
}
}
/**
* Construct a special ProviderList for JAR verification. It consists
* of the providers specified via jarClassNames, which must be on the
* bootclasspath and cannot be in signed JAR files. This is to avoid
* possible recursion and deadlock during verification.
*/
// if the equivalent object is present in this provider list,
// use the old object rather than the new object.
// this ensures that when the provider is loaded in the
// new thread local list, it will also become available
// in this provider list
break;
}
}
}
return new ProviderList(configArray, false);
}
public int size() {
}
/**
* Return the Provider at the specified index. Returns EMPTY_PROVIDER
* if the provider could not be loaded at this time.
*/
return (p != null) ? p : EMPTY_PROVIDER;
}
/**
* Return an unmodifiable List of all Providers in this List. The
* individual Providers are loaded on demand. Elements that could not
* be initialized are replaced with EMPTY_PROVIDER.
*/
return userList;
}
}
// return the Provider with the specified name or null
}
/**
* Return the index at which the provider with the specified name is
* installed or -1 if it is not present in this ProviderList.
*/
Provider p = getProvider(i);
return i;
}
}
return -1;
}
// attempt to load all Providers not already loaded
private int loadAll() {
if (allLoaded) {
}
}
int n = 0;
if (p != null) {
n++;
}
}
allLoaded = true;
}
return n;
}
/**
* Try to load all Providers and return the ProviderList. If one or
* more Providers could not be loaded, a new ProviderList with those
* entries removed is returned. Otherwise, the method returns this.
*/
int n = loadAll();
return this;
}
newConfigs[j++] = config;
}
}
return new ProviderList(newConfigs, true);
}
// return the providers as an array
}
// return a String representation of this ProviderList
}
/**
* Return a Service describing an implementation of the specified
* algorithm from the Provider with the highest precedence that
* supports that algorithm. Return null if no Provider supports this
* algorithm.
*/
Provider p = getProvider(i);
if (s != null) {
return s;
}
}
return null;
}
/**
* Return a List containing all the Services describing implementations
* of the specified algorithms in precedence order. If no implementation
* exists, this method returns an empty List.
*
* The elements of this list are determined lazily on demand.
*
* The List returned is NOT thread safe.
*/
}
/**
* This method exists for compatibility with JCE only. It will be removed
* once JCE has been changed to use the replacement method.
* @deprecated use getServices(List<ServiceId>) instead
*/
}
return getServices(ids);
}
return new ServiceList(ids);
}
/**
* Inner class for a List of Services. Custom List implementation in
* order to delay Provider initialization and lookup.
* Not thread safe.
*/
// type and algorithm for simple lookup
// avoid allocating/traversing the ServiceId list for these lookups
// list of ids for parallel lookup
// if ids is non-null, type and algorithm are null
// first service we have found
// it is stored in a separate variable so that we can avoid
// allocating the services list if we do not need the second service.
// this is the case if we don't failover (failovers are typically rare)
// list of the services we have found so far
// index into config[] of the next provider we need to query
private int providerIndex;
}
}
if (firstService == null) {
firstService = s;
} else {
}
}
}
while (true) {
return firstService;
}
return null;
}
// check all algorithms in this provider before moving on
// simple lookup
if (s != null) {
addService(s);
}
} else {
// parallel lookup
if (s != null) {
addService(s);
}
}
}
}
}
if (s == null) {
throw new IndexOutOfBoundsException();
}
return s;
}
public int size() {
int n;
} else {
}
n++;
}
return n;
}
// override isEmpty() and iterator() to not call size()
// this avoids loading + checking all Providers
public boolean isEmpty() {
}
int index;
public boolean hasNext() {
}
if (s == null) {
throw new NoSuchElementException();
}
index++;
return s;
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
}
}