APIdia Launch Partner
Top Description Inners Fields Constructors Methods
java.security

public final Class Security

extends Object
Class Inheritance
Imports
java.io.FileNotFoundException, .IOException, .InputStream, java.net.MalformedURLException, .URI, .URL, java.nio.file.Files, .InvalidPathException, .Path, java.util.ArrayList, .Arrays, .Collections, .Enumeration, .HashSet, .Hashtable, .LinkedList, .List, .Locale, .Map, .Properties, .Set, java.util.concurrent.ConcurrentHashMap, jdk.internal.access.JavaSecurityPropertiesAccess, .SharedSecrets, jdk.internal.event.EventHelper, .SecurityPropertyModificationEvent, jdk.internal.util.StaticProperty, sun.security.jca.GetInstance, .ProviderList, .Providers, sun.security.util.Debug, .PropertyExpander

This class centralizes all security properties and common security methods. One of its primary uses is to manage providers.

The default values of security properties are read from an implementation-specific location, which is typically the properties file conf/security/java.security in the Java installation directory.

Implementation Note

If the properties file fails to load, the JDK implementation will throw an unspecified error when initializing the Security class.

Author
Benjamin Renaud
Since
1.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private static Properties
private static final Properties
private static final Debug
private static final Map<String, Class<?>>

Constructor Summary

AccessConstructor and Description
private
Security()

Don't let anyone instantiate this.

Method Summary

Modifier and TypeMethod and Description
public static int

Returns:

the preference position in which the provider was added, or -1 if the provider was not added because it is already installed.
addProvider
(Provider
the provider to be added.
provider
)

Adds a provider to the next position available.

public static String

Returns:

the value of the specified property.
getAlgorithmProperty
(String
the algorithm name.
algName
,
String
the name of the property to get.
propName
)
Deprecated This method used to return the value of a proprietary property in the master file of the "SUN" Cryptographic Service Provider in order to determine how to parse algorithm-specific parameters.

Gets a specified property for an algorithm.

public static Set<String>

Returns:

a Set of String objects containing the names of all available algorithms or types for the specified Java cryptographic service or an empty set if no provider supports the specified service.
getAlgorithms
(String
the name of the Java cryptographic service (e.g., Signature, MessageDigest, Cipher, Mac, KeyStore).

Note

this parameter is case-insensitive.

serviceName
)

Returns a Set of String objects containing the names of all available algorithms or types for the specified Java cryptographic service (e.g., Signature, MessageDigest, Cipher, Mac, KeyStore).

pack-priv static Object[]
getImpl(String algorithm, String type, String provider)

pack-priv static Object[]
getImpl(String algorithm, String type, String provider, Object params)

pack-priv static Object[]
getImpl(String algorithm, String type, Provider provider)

pack-priv static Object[]
getImpl(String algorithm, String type, Provider provider, Object params)

public static String

Returns:

the value of the security property, or null if there is no property with that key.
getProperty
(String
the key of the property being retrieved.
key
)

Gets a security property value.

public static Provider

Returns:

the provider of the specified name.
getProvider
(String
the name of the provider to get.
name
)

Returns the provider installed with the specified name, if any.

private static Security.ProviderProperty
getProviderProperty(String key)

Looks up providers, and returns the property (and its associated provider) mapping the key, if any.

private static String
getProviderProperty(String key, Provider provider)

Returns the property (if any) mapping the key for the given provider.

public static Provider[]

Returns:

an array of all the installed providers.
getProviders
()

Returns an array containing all the installed providers.

public static Provider[]

Returns:

all the installed providers that satisfy the selection criterion, or null if no such providers have been installed.
getProviders
(String
the criterion for selecting providers. The filter is case-insensitive.
filter
)

Returns an array containing all installed providers that satisfy the specified selection criterion, or null if no such providers have been installed.

public static Provider[]

Returns:

all the installed providers that satisfy the selection criteria, or null if no such providers have been installed.
getProviders
(Map<String, String>
the criteria for selecting providers. The filter is case-insensitive.
filter
)

Returns an array containing all installed providers that satisfy the specified selection criteria, or null if no such providers have been installed.

private static Class<?>
getSpiClass(String type)

Return the Class object for the given engine type (e.g. "MessageDigest").

private static void
public static synchronized int

Returns:

the actual preference position in which the provider was added, or -1 if the provider was not added because it is already installed.
insertProviderAt
(Provider
the provider to be added.
provider
,
int
the preference position that the caller would like for this provider.
position
)

Adds a new provider, at a specified position.

private static URL
newURL(String spec)

public static synchronized void
removeProvider(String
the name of the provider to remove.
name
)

Removes the provider with the specified name.

public static void
setProperty(String
the name of the property to be set.
key
,
String
the value of the property to be set.
datum
)

Sets a security property value.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

initialSecurityPropertiesback to summary
private static Properties initialSecurityProperties
propsback to summary
private static final Properties props
sdebugback to summary
private static final Debug sdebug
spiMapback to summary
private static final Map<String, Class<?>> spiMap

Constructor Detail

Securityback to summary
private Security()

Don't let anyone instantiate this.

Method Detail

addProviderback to summary
public static int addProvider(Provider provider)

Adds a provider to the next position available.

Parameters
provider:Provider

the provider to be added.

Returns:int

the preference position in which the provider was added, or -1 if the provider was not added because it is already installed.

Exceptions
NullPointerException:
if provider is null
See Also
getProvider, removeProvider
getAlgorithmPropertyback to summary
public static String getAlgorithmProperty(String algName, String propName)

Deprecated

This method used to return the value of a proprietary property in the master file of the "SUN" Cryptographic Service Provider in order to determine how to parse algorithm-specific parameters. Use the new provider-based and algorithm-independent AlgorithmParameters and KeyFactory engine classes (introduced in the J2SE version 1.2 platform) instead.

Gets a specified property for an algorithm. The algorithm name should be a standard name. See the Java Security Standard Algorithm Names Specification for information about standard algorithm names. One possible use is by specialized algorithm parsers, which may map classes to algorithms which they understand (much like Key parsers do).

Parameters
algName:String

the algorithm name.

propName:String

the name of the property to get.

Returns:String

the value of the specified property.

Annotations
@Deprecated
External Specification
Java Security Standard Algorithm Names
getAlgorithmsback to summary
public static Set<String> getAlgorithms(String serviceName)

Returns a Set of String objects containing the names of all available algorithms or types for the specified Java cryptographic service (e.g., Signature, MessageDigest, Cipher, Mac, KeyStore). Returns an empty set if there is no provider that supports the specified service or if serviceName is null. For a complete list of Java cryptographic services, please see the Java Cryptography Architecture (JCA) Reference Guide.

Note

the returned set is immutable.

Parameters
serviceName:String

the name of the Java cryptographic service (e.g., Signature, MessageDigest, Cipher, Mac, KeyStore).

Note

this parameter is case-insensitive.

Returns:Set<String>

a Set of String objects containing the names of all available algorithms or types for the specified Java cryptographic service or an empty set if no provider supports the specified service.

Since
1.4
getImplback to summary
pack-priv static Object[] getImpl(String algorithm, String type, String provider) throws NoSuchAlgorithmException, NoSuchProviderException
getImplback to summary
pack-priv static Object[] getImpl(String algorithm, String type, String provider, Object params) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException
getImplback to summary
pack-priv static Object[] getImpl(String algorithm, String type, Provider provider) throws NoSuchAlgorithmException
getImplback to summary
pack-priv static Object[] getImpl(String algorithm, String type, Provider provider, Object params) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException
getPropertyback to summary
public static String getProperty(String key)

Gets a security property value.

Parameters
key:String

the key of the property being retrieved.

Returns:String

the value of the security property, or null if there is no property with that key.

Exceptions
NullPointerException:
if key is null
IllegalArgumentException:
if key is reserved and cannot be used as a Security property name. Reserved keys are: "include".
See Also
setProperty
getProviderback to summary
public static Provider getProvider(String name)

Returns the provider installed with the specified name, if any. Returns null if no provider with the specified name is installed or if name is null.

Parameters
name:String

the name of the provider to get.

Returns:Provider

the provider of the specified name.

See Also
removeProvider, addProvider
getProviderPropertyback to summary
private static Security.ProviderProperty getProviderProperty(String key)

Looks up providers, and returns the property (and its associated provider) mapping the key, if any. The order in which the providers are looked up is the provider-preference order, as specified in the security properties file.

getProviderPropertyback to summary
private static String getProviderProperty(String key, Provider provider)

Returns the property (if any) mapping the key for the given provider.

getProvidersback to summary
public static Provider[] getProviders()

Returns an array containing all the installed providers. The order of the providers in the array is their preference order.

Returns:Provider[]

an array of all the installed providers.

getProvidersback to summary
public static Provider[] getProviders(String filter)

Returns an array containing all installed providers that satisfy the specified selection criterion, or null if no such providers have been installed. The returned providers are ordered according to their preference order.

A cryptographic service is always associated with a particular algorithm or type. For example, a digital signature service is always associated with a particular algorithm (e.g., DSA), and a CertificateFactory service is always associated with a particular certificate type (e.g., X.509).

The selection criterion must be specified in one of the following two formats:

  • <crypto_service>.<algorithm_or_type>

    The cryptographic service name must not contain any dots.

    A provider satisfies the specified selection criterion iff the provider implements the specified algorithm or type for the specified cryptographic service.

    For example, "CertificateFactory.X.509" would be satisfied by any provider that supplied a CertificateFactory implementation for X.509 certificates.

  • <crypto_service>.<algorithm_or_type> <attribute_name>:<attribute_value>

    The cryptographic service name must not contain any dots. There must be one or more space characters between the <algorithm_or_type> and the <attribute_name>.

    A provider satisfies this selection criterion iff the provider implements the specified algorithm or type for the specified cryptographic service and its implementation meets the constraint expressed by the specified attribute name/value pair.

    For example, "Signature.SHA1withDSA KeySize:1024" would be satisfied by any provider that implemented the SHA1withDSA signature algorithm with a keysize of 1024 (or larger).

See the Java Security Standard Algorithm Names Specification for information about standard cryptographic service names, standard algorithm names and standard attribute names.

Parameters
filter:String

the criterion for selecting providers. The filter is case-insensitive.

Returns:Provider[]

all the installed providers that satisfy the selection criterion, or null if no such providers have been installed.

Exceptions
InvalidParameterException:
if the filter is not in the required format
NullPointerException:
if filter is null
Since
1.3
External Specification
Java Security Standard Algorithm Names
See Also
getProviders(java.util.Map)
getProvidersback to summary
public static Provider[] getProviders(Map<String, String> filter)

Returns an array containing all installed providers that satisfy the specified selection criteria, or null if no such providers have been installed. The returned providers are ordered according to their preference order.

The selection criteria are represented by a map. Each map entry represents a selection criterion. A provider is selected iff it satisfies all selection criteria. The key for any entry in such a map must be in one of the following two formats:

  • <crypto_service>.<algorithm_or_type>

    The cryptographic service name must not contain any dots.

    The value associated with the key must be an empty string.

    A provider satisfies this selection criterion iff the provider implements the specified algorithm or type for the specified cryptographic service.

  • <crypto_service>. <algorithm_or_type> <attribute_name>

    The cryptographic service name must not contain any dots. There must be one or more space characters between the <algorithm_or_type> and the <attribute_name>.

    The value associated with the key must be a non-empty string. A provider satisfies this selection criterion iff the provider implements the specified algorithm or type for the specified cryptographic service and its implementation meets the constraint expressed by the specified attribute name/value pair.

See the Java Security Standard Algorithm Names Specification for information about standard cryptographic service names, standard algorithm names and standard attribute names.

Parameters
filter:Map<String, String>

the criteria for selecting providers. The filter is case-insensitive.

Returns:Provider[]

all the installed providers that satisfy the selection criteria, or null if no such providers have been installed.

Exceptions
InvalidParameterException:
if the filter is not in the required format
NullPointerException:
if filter is null
Since
1.3
External Specification
Java Security Standard Algorithm Names
See Also
getProviders(java.lang.String)
getSpiClassback to summary
private static Class<?> getSpiClass(String type)

Return the Class object for the given engine type (e.g. "MessageDigest"). Works for Spis in the java.security package only.

initializeback to summary
private static void initialize()
insertProviderAtback to summary
public static synchronized int insertProviderAt(Provider provider, int position)

Adds a new provider, at a specified position. The position is the preference order in which providers are searched for requested algorithms. The position is 1-based, that is, 1 is most preferred, followed by 2, and so on. If the position is less than 1 or greater than n, where n is the number of installed providers, the provider (if not already installed) is inserted at the end of the list, or at the n + 1 position.

If the given provider is installed at the requested position, the provider that used to be at that position, and all providers with a position greater than position, are shifted up one position (towards the end of the list of installed providers).

A provider cannot be added if it is already installed.

Parameters
provider:Provider

the provider to be added.

position:int

the preference position that the caller would like for this provider.

Returns:int

the actual preference position in which the provider was added, or -1 if the provider was not added because it is already installed.

Exceptions
NullPointerException:
if provider is null
See Also
getProvider, removeProvider
newURLback to summary
private static URL newURL(String spec) throws MalformedURLException
Annotations
@SuppressWarnings:deprecation
removeProviderback to summary
public static synchronized void removeProvider(String name)

Removes the provider with the specified name.

When the specified provider is removed, all providers located at a position greater than where the specified provider was are shifted down one position (towards the head of the list of installed providers).

This method returns silently if the provider is not installed or if name is null.

Parameters
name:String

the name of the provider to remove.

See Also
getProvider, addProvider
setPropertyback to summary
public static void setProperty(String key, String datum)

Sets a security property value.

Parameters
key:String

the name of the property to be set.

datum:String

the value of the property to be set.

Exceptions
NullPointerException:
if key or datum is null
IllegalArgumentException:
if key is reserved and cannot be used as a Security property name. Reserved keys are: "include".
See Also
getProperty
java.security back to summary

private Class Security.Criteria

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final String
private final String
private final String
private final String

Constructor Summary

AccessConstructor and Description
pack-priv
Criteria(String key, String value)

Method Summary

Modifier and TypeMethod and Description
private boolean
private boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

algNameback to summary
private final String algName
attrNameback to summary
private final String attrName
attrValueback to summary
private final String attrValue
serviceNameback to summary
private final String serviceName

Constructor Detail

Criteriaback to summary
pack-priv Criteria(String key, String value) throws InvalidParameterException

Method Detail

isCompositeValueback to summary
private boolean isCompositeValue()
isCriterionSatisfiedback to summary
private boolean isCriterionSatisfied(Provider prov)
java.security back to summary

private Class Security.ProviderProperty

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv String
pack-priv Provider

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

classNameback to summary
pack-priv String className
providerback to summary
pack-priv Provider provider

Constructor Detail

ProviderPropertyback to summary
private ProviderProperty()
java.security back to summary

private final Class Security.SecPropLoader

extends Object
Class Inheritance

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum

Field Summary

Modifier and TypeField and Description
private static final List<Path>
private static Path
private static final String
private static final String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static void
pack-priv static void
private static void
debugLoad(boolean start, Object source)

pack-priv static boolean
pack-priv static void
private static void
private static Exception
private static Exception
private static void
private static void
private static void
pack-priv static void
loadInclude(String propFile)

private static void
private static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

activePathsback to summary
private static final List<Path> activePaths
currentPathback to summary
private static Path currentPath
EXTRA_SYS_PROPback to summary
private static final String EXTRA_SYS_PROP
OVERRIDE_SEC_PROPback to summary
private static final String OVERRIDE_SEC_PROP

Constructor Detail

SecPropLoaderback to summary
private SecPropLoader()

Method Detail

checkCyclicIncludeback to summary
private static void checkCyclicInclude(Path path)
checkReservedKeyback to summary
pack-priv static void checkReservedKey(String key) throws IllegalArgumentException
debugLoadback to summary
private static void debugLoad(boolean start, Object source)
isIncludeback to summary
pack-priv static boolean isInclude(String key)
loadAllback to summary
pack-priv static void loadAll()
loadExtraback to summary
private static void loadExtra()
loadExtraFromFileUrlback to summary
private static Exception loadExtraFromFileUrl(URI uri, Security.SecPropLoader.LoadingMode mode) throws Exception
loadExtraFromPathback to summary
private static Exception loadExtraFromPath(String propFile, Security.SecPropLoader.LoadingMode mode) throws Exception
loadExtraHelperback to summary
private static void loadExtraHelper(String propFile, Security.SecPropLoader.LoadingMode mode) throws Exception
loadFromPathback to summary
private static void loadFromPath(Path path, Security.SecPropLoader.LoadingMode mode) throws IOException
loadFromUrlback to summary
private static void loadFromUrl(URL url, Security.SecPropLoader.LoadingMode mode) throws IOException
loadIncludeback to summary
pack-priv static void loadInclude(String propFile)
loadMasterback to summary
private static void loadMaster()
resetback to summary
private static void reset(Security.SecPropLoader.LoadingMode mode)
java.security back to summary

private final Enum Security.SecPropLoader.LoadingMode

extends Enum<Security.SecPropLoader.LoadingMode>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final Security.SecPropLoader.LoadingMode
public static final Security.SecPropLoader.LoadingMode

Constructor Summary

AccessConstructor and Description
private

Field Detail

APPENDback to summary
public static final Security.SecPropLoader.LoadingMode APPEND
OVERRIDEback to summary
public static final Security.SecPropLoader.LoadingMode OVERRIDE

Constructor Detail

LoadingModeback to summary
private LoadingMode()

Method Detail

valueOfback to summary
public static Security.SecPropLoader.LoadingMode valueOf(String name)
valuesback to summary
public static Security.SecPropLoader.LoadingMode[] values()