java.security

Class Security

public final class Security extends Object

This class centralizes all security properties and common security methods. One of its primary uses is to manage security providers.
Method Summary
static intaddProvider(Provider provider)
Appends the designated new {@link Provider} to the current list of installed {@link Provider}s.
static StringgetAlgorithmProperty(String algName, String propName)
Returns the value associated to a designated property name for a given algorithm.
static Set<String>getAlgorithms(String serviceName)
For a given service (e.g.
static StringgetProperty(String key)
Returns the value associated with a Security propery.
static ProvidergetProvider(String name)
Returns an already installed {@link Provider} given its name.
static Provider[]getProviders()
Returns the current list of installed {@link Provider}s as an array ordered according to their installation preference order.
static Provider[]getProviders(String filter)
Returns an array of currently installed {@link Provider}s, ordered according to their installation preference order, which satisfy a given selection criterion.
static Provider[]getProviders(Map<String,String> filter)
Returns an array of currently installed {@link Provider}s which satisfy a set of selection criteria.
static intinsertProviderAt(Provider provider, int position)
Inserts a new designated {@link Provider} at a designated (1-based) position in the current list of installed {@link Provider}s,
static voidremoveProvider(String name)
Removes an already installed {@link Provider}, given its name, from the current list of installed {@link Provider}s.
static voidsetProperty(String key, String datum)
Sets or changes a designated Security property to a designated value.

Method Detail

addProvider

public static int addProvider(Provider provider)
Appends the designated new {@link Provider} to the current list of installed {@link Provider}s.

Parameters: provider the new {@link Provider} to append.

Returns: the position (starting from 1) of provider in the current list of {@link Provider}s, or -1 if provider was already there.

Throws: SecurityException if a {@link SecurityManager} is installed and it disallows this operation.

See Also: getProvider removeProvider SecurityPermission

getAlgorithmProperty

public static String getAlgorithmProperty(String algName, String propName)

Deprecated: Use the provider-based and algorithm-independent {@link AlgorithmParameters} and {@link KeyFactory} engine classes instead.

Returns the value associated to a designated property name for a given algorithm.

Parameters: algName the algorithm name. propName the name of the property to return.

Returns: the value of the specified property or null if none found.

getAlgorithms

public static Set<String> getAlgorithms(String serviceName)
For a given service (e.g. Signature, MessageDigest, etc...) this method returns the {@link Set} of all available algorithm names (instances of {@link String}, from all currently installed {@link Provider}s.

Parameters: serviceName the case-insensitive name of a service (e.g. Signature, MessageDigest, etc).

Returns: a {@link Set} of {@link String}s containing the names of all algorithm names provided by all of the currently installed {@link Provider}s.

Since: 1.4

getProperty

public static String getProperty(String key)
Returns the value associated with a Security propery.

Parameters: key the key of the property to fetch.

Returns: the value of the Security property associated with key. Returns null if no such property was found.

Throws: SecurityException if a {@link SecurityManager} is installed and it disallows this operation.

See Also: Security SecurityPermission

getProvider

public static Provider getProvider(String name)
Returns an already installed {@link Provider} given its name.

Parameters: name the name of an already installed {@link Provider}.

Returns: the {@link Provider} known by name. Returns null if the current list of {@link Provider}s does not include one named name.

See Also: removeProvider addProvider

getProviders

public static Provider[] getProviders()
Returns the current list of installed {@link Provider}s as an array ordered according to their installation preference order.

Returns: an array of all the installed providers.

getProviders

public static Provider[] getProviders(String filter)
Returns an array of currently installed {@link Provider}s, ordered according to their installation preference order, which satisfy a given selection criterion.

This implementation recognizes a selection criterion written in one of two following forms:

Parameters: filter the selection criterion for selecting among the installed {@link Provider}s.

Returns: all the installed {@link Provider}s which satisfy the selection criterion. Returns null if no installed {@link Provider}s were found which satisfy the selection criterion. Returns ALL installed {@link Provider}s if filter is null or is an empty string.

Throws: InvalidParameterException if an exception occurs while parsing the filter.

See Also: getProviders

getProviders

public static Provider[] getProviders(Map<String,String> filter)
Returns an array of currently installed {@link Provider}s which satisfy a set of selection criteria.

The selection criteria are defined in a {@link Map} where each element specifies a selection querry. The Keys in this {@link Map} must be in one of the two following forms:

Parameters: filter a {@link Map} of selection querries.

Returns: all currently installed {@link Provider}s which satisfy ALL the selection criteria defined in filter. Returns ALL installed {@link Provider}s if filter is null or empty.

Throws: InvalidParameterException if an exception is encountered while parsing the syntax of the {@link Map}'s keys.

See Also: getProviders

insertProviderAt

public static int insertProviderAt(Provider provider, int position)
Inserts a new designated {@link Provider} at a designated (1-based) position in the current list of installed {@link Provider}s,

Parameters: provider the new {@link Provider} to add. position the position (starting from 1) of where to install provider.

Returns: the actual position, in the list of installed Providers. Returns -1 if provider was laready in the list. The actual position may be different than the desired position.

Throws: SecurityException if a {@link SecurityManager} is installed and it disallows this operation.

See Also: getProvider removeProvider SecurityPermission

removeProvider

public static void removeProvider(String name)
Removes an already installed {@link Provider}, given its name, from the current list of installed {@link Provider}s.

Parameters: name the name of an already installed {@link Provider} to remove.

Throws: SecurityException if a {@link SecurityManager} is installed and it disallows this operation.

See Also: getProvider addProvider

setProperty

public static void setProperty(String key, String datum)
Sets or changes a designated Security property to a designated value.

Parameters: key the name of the property to set. datum the new value of the property.

Throws: SecurityException if a {@link SecurityManager} is installed and it disallows this operation.

See Also: getProperty SecurityPermission