public final class DOFCredentials extends java.lang.Object implements DOFAuthenticator.CredentialStorage, java.io.Serializable, org.opendof.core.internal.protocol.Marshallable
Modifier and Type | Class and Description |
---|---|
static class |
DOFCredentials.Key
This class represents authentication using a preshared 256-bit key.
|
static class |
DOFCredentials.Password
Password credentials are used to authenticate with a password.
|
Modifier and Type | Field and Description |
---|---|
static short |
KEY
The 256-bit key credentials type.
|
static short |
NONE
Reserved value representing no credentials.
|
static short |
PASSWORD
The SRP6 Password credentials type.
|
Modifier and Type | Method and Description |
---|---|
static DOFCredentials |
create(byte[] data)
Create DOFCredentials from a buffer that was obtained through
marshal(org.opendof.core.oal.DOFMarshalContext, java.lang.Object, org.opendof.core.oal.DOFPacket) . |
static DOFCredentials |
create(DOFCredentials initialCredentials,
DOFObjectID.Domain targetDomain)
Construct a DOFCredentials with a target domain.
|
static DOFCredentials |
create(java.io.File file)
Create a DOFCredentials by reading from a
File . |
static DOFCredentials |
create(java.io.InputStream stream)
Create a DOFCredentials by reading from an
InputStream . |
static DOFCredentials |
create(java.lang.String filename)
Create a DOFCredentials by reading from a file specified by filename.
|
static DOFCredentials |
create(java.net.URL url)
Create a DOFCredentials by reading from a
java.net.URL . |
boolean |
equals(java.lang.Object obj) |
byte[] |
getBytes()
Get a byte array of a DOFCredentials that can be used to recreate it at a later time.
|
DOFObjectID.Domain |
getDomainID()
Gets the security domain that the credential is valid in.
|
DOFObjectID.Authentication |
getIdentity()
Gets the identity of the authorized user.
|
byte[] |
getPrivateStorage()
Create a byte array that can be stored and used later.
|
int |
getRemoteDomainID()
Get the remote domain identifier of the credentials if there is one.
|
byte[] |
getStorageKey()
Gets the Storage Key.
|
short |
getType()
Retrieve the type of credentials represented by the given DOFCredentials.
|
int |
hashCode() |
boolean |
isResolved()
Return true if the credential is resolved, meaning that it is ready to use in authentication.
|
void |
marshal(DOFMarshalContext context,
java.lang.Object state,
DOFPacket packet)
Write an object to a serialized form to the specified buffer, according
to the context specified and with the given state.
|
void |
setPrivateStorage(DOFObjectID.Domain domainID,
DOFObjectID.Authentication identity,
byte[] storage)
Sets the storage domainID, identity and the credential storage data.
|
java.lang.String |
toString() |
void |
write(java.io.File file)
Write the DOFCredentials to a
java.io.File . |
void |
write(java.io.OutputStream stream)
Write the DOFCredentials to a
java.io.OutputStream . |
void |
write(java.lang.String filename)
Write the DOFCredentials to a named file.
|
public static final short NONE
public static final short KEY
public static final short PASSWORD
public static DOFCredentials create(DOFCredentials initialCredentials, DOFObjectID.Domain targetDomain)
initialCredentials
- The initial credentials. This must not be null.targetDomain
- The target domain. This must not be null or broadcast.public static DOFCredentials create(byte[] data) throws DOFMarshalException
marshal(org.opendof.core.oal.DOFMarshalContext, java.lang.Object, org.opendof.core.oal.DOFPacket)
.data
- The byte array representing the credential, including all of its data, suitable for storage.marshal(org.opendof.core.oal.DOFMarshalContext, java.lang.Object, org.opendof.core.oal.DOFPacket)
.DOFMarshalException
- Upon unmarshal error.public static DOFCredentials create(java.net.URL url) throws java.io.IOException, DOFException
java.net.URL
.url
- The URL from which to read the DOFCredentials. This must not be null.java.lang.IllegalArgumentException
- If url is null.DOFException
- The file is empty or too large.java.io.FileNotFoundException
- The file could not be found.java.io.IOException
- The file could not be read.java.lang.SecurityException
- If a security manager exists and its checkWrite method denies write access to the file.public static DOFCredentials create(java.lang.String filename) throws java.io.IOException, DOFException
filename
- The filename from which to read the DOFCredentials. This must not be null.java.lang.IllegalArgumentException
- If filename is null.DOFException
- The file is empty or too large.java.io.FileNotFoundException
- The file could not be found.java.io.IOException
- The file could not be read.java.lang.SecurityException
- If a security manager exists and its checkWrite method denies write access to the file.public static DOFCredentials create(java.io.File file) throws java.io.FileNotFoundException, java.io.IOException, DOFException
File
.
To obtain more meaningful information about exceptions that arise, the caller may benefit by making his own more comprehensive File tests,
such as checking file permissions, testing for empty file, etc.file
- The File
from which to read the DOFCredentials. Must not be null.java.lang.IllegalArgumentException
- If file is null.DOFException
- The file is empty or too large.java.io.FileNotFoundException
- The file could not be found.java.io.IOException
- The file could not be read.java.lang.SecurityException
- If a security manager exists and its checkWrite method denies write access to the file.public static DOFCredentials create(java.io.InputStream stream) throws java.io.IOException, DOFException
InputStream
.
NOTE: It is the caller's responsibility to try-finally close stream
passed in.stream
- An input stream such as from file, url or classpath. Must not be null.stream
. Never returns null.java.lang.IllegalArgumentException
- If stream is null.DOFException
- The stream is empty or too large.java.io.IOException
- If the stream could not be read.public void marshal(DOFMarshalContext context, java.lang.Object state, DOFPacket packet) throws DOFMarshalException
org.opendof.core.internal.protocol.Marshallable
marshal
in interface org.opendof.core.internal.protocol.Marshallable
context
- The context of the marshaling to be performed.state
- The state in which the marshalling is done. This may affect the result.packet
- The buffer which will receive the marshaled data. Must not be null.DOFMarshalException
- If there are errors in the data or the buffer.public void write(java.lang.String filename) throws java.io.FileNotFoundException, java.io.IOException, DOFException
File.createNewFile()
and call write(java.io.OutputStream)
.
The written credential file is a form of a credential which could be used by anyone gaining
access to the file to access systems as if they were the owner. Care should be taken to
only create these files in secure settings.filename
- The filename to which to write the DOFCredentials. Must not be null.java.lang.IllegalArgumentException
- if filename is null.java.io.FileNotFoundException
- The file could not be opened for write.java.io.IOException
- The file could not be written.java.lang.SecurityException
- If a security manager exists and its checkWrite method denies write access to the file.DOFException
public void write(java.io.File file) throws java.io.FileNotFoundException, java.io.IOException, DOFException
java.io.File
.
If the file already exists, it will be overwritten. If you don't want that, then check if it exists before calling this method.
There is a race condition if you check for the file's existence and then call this method. Another thread may have created the file.
If that is a problem, then create the file yourself with File.createNewFile()
and call write(java.io.OutputStream)
.
The written credential file is a form of a credential which could be used by anyone gaining
access to the file to access systems as if they were the owner. Care should be taken to
only create these files in secure settings.file
- The file to which to write the DOFCredentials. Must not be null.java.lang.IllegalArgumentException
- If file is null.java.io.FileNotFoundException
- The file could not be opened for write.java.io.IOException
- The file could not be written.java.lang.SecurityException
- If a security manager exists and its checkWrite method denies write access to the file.DOFException
public void write(java.io.OutputStream stream) throws java.io.IOException
java.io.OutputStream
.
The written credential is a form of a credential which could be used by anyone gaining
access to the results of the stream to access systems as if they were the owner. Care should be taken to
only create these streams in secure settings.
The caller is responsible for closing the stream.stream
- The stream to which to write the DOFCredentials. Must not be null.java.lang.IllegalArgumentException
- If stream is null.java.io.IOException
- The file could not be written.public byte[] getBytes()
public byte[] getPrivateStorage()
public DOFObjectID.Domain getDomainID()
public DOFObjectID.Authentication getIdentity()
getIdentity
in interface DOFAuthenticator.CredentialStorage
public short getType()
getType
in interface DOFAuthenticator.CredentialStorage
public byte[] getStorageKey()
getStorageKey
in interface DOFAuthenticator.CredentialStorage
public void setPrivateStorage(DOFObjectID.Domain domainID, DOFObjectID.Authentication identity, byte[] storage) throws DOFSecurityException
setPrivateStorage
in interface DOFAuthenticator.CredentialStorage
domainID
- The domain of the credential, or null if it is already known to the credentialidentity
- The public identity of the credential, or null if it is already known to the credential
and should not be changed.storage
- The private credential data.DOFSecurityException
- Thrown if the data is invalid for the credential.public boolean isResolved()
public int getRemoteDomainID()
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object