Class IdentityDatabase
java.lang.Object
java.security.Identity
java.security.IdentityScope
com.sun.ts.lib.util.sec.security.provider.IdentityDatabase
- All Implemented Interfaces:
Serializable
,Principal
An implementation of IdentityScope as a persistent identity database.
- Author:
- Benjamin Renaud
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionIdentityDatabase
(File file) Construct a new, empty database with a specified source file.IdentityDatabase
(String name) Construct a new, empty database. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addIdentity
(Identity identity) Adds an identity to the database.static IdentityDatabase
Initialize an IdentityDatabase from file.static IdentityDatabase
Initialize an identity database from a stream.getIdentity
(String name) getIdentity
(PublicKey key) Get an identity by key.void
removeIdentity
(Identity identity) Removes an identity to the database.void
save()
Saves the database to the default source file.void
save
(OutputStream os) Save the database in its current state to an output stream.int
size()
toString()
Methods inherited from class java.security.IdentityScope
getIdentity, getSystemScope, setSystemScope
Methods inherited from class java.security.Identity
addCertificate, certificates, equals, getInfo, getName, getPublicKey, getScope, hashCode, identityEquals, removeCertificate, setInfo, setPublicKey, toString
-
Constructor Details
-
IdentityDatabase
Construct a new, empty database with a specified source file.- Parameters:
file
- the source file.- Throws:
InvalidParameterException
-
IdentityDatabase
Construct a new, empty database.- Throws:
InvalidParameterException
-
-
Method Details
-
fromStream
Initialize an identity database from a stream. The stream should contain data to initialized a serialized IdentityDatabase object.- Parameters:
is
- the input stream from which to restore the database.- Throws:
IOException
- if a stream IO exception occurs
-
fromFile
Initialize an IdentityDatabase from file.- Parameters:
f
- the filename where the identity database is stored.- Throws:
IOException
- a file-related exception occurs (e.g. the directory of the file passed does not exists, etc.
-
size
public int size()- Specified by:
size
in classIdentityScope
- Returns:
- the number of identities in the database.
-
getIdentity
- Specified by:
getIdentity
in classIdentityScope
- Parameters:
name
- the name of the identity to be retrieved.- Returns:
- the identity named name, or null if there are no identities named name in the database.
-
getIdentity
Get an identity by key.- Specified by:
getIdentity
in classIdentityScope
- Parameters:
name
- the key of the identity to be retrieved.- Returns:
- the identity with a given key, or null if there are no identities with that key in the database.
-
addIdentity
Adds an identity to the database.- Specified by:
addIdentity
in classIdentityScope
- Parameters:
identity
- the identity to be added.- Throws:
KeyManagementException
- if a name or key clash occurs, or if another exception occurs.
-
removeIdentity
Removes an identity to the database.- Specified by:
removeIdentity
in classIdentityScope
- Throws:
KeyManagementException
-
identities
- Specified by:
identities
in classIdentityScope
- Returns:
- an enumeration of all identities in the database.
-
save
Save the database in its current state to an output stream.- Parameters:
os
- the output stream to which the database should be serialized.- Throws:
IOException
- if an IO exception is raised by stream operations.
-
save
Saves the database to the default source file.- Throws:
KeyManagementException
- when there is no default source file specified for this database.IOException
-
toString
- Specified by:
toString
in interfacePrincipal
- Overrides:
toString
in classIdentityScope
-