org.jets3t.service.security
Class ProviderCredentials

java.lang.Object
  extended by org.jets3t.service.security.ProviderCredentials
Direct Known Subclasses:
AWSCredentials, GSCredentials

public abstract class ProviderCredentials
extends java.lang.Object

Abstract class to contain the credentials of a user.


Field Summary
protected  java.lang.String accessKey
           
protected static int CREDENTIALS_STORAGE_VERSION
           
protected  java.lang.String friendlyName
           
protected static org.apache.commons.logging.Log log
           
protected  java.lang.String secretKey
           
protected static java.lang.String V2_KEYS_DELIMITER
           
protected static java.lang.String V3_KEYS_DELIMITER
           
 
Constructor Summary
ProviderCredentials(java.lang.String accessKey, java.lang.String secretKey)
          Construct credentials.
ProviderCredentials(java.lang.String accessKey, java.lang.String secretKey, java.lang.String friendlyName)
          Construct credentials, and associate them with a human-friendly name.
 
Method Summary
 java.lang.String getAccessKey()
           
protected  java.lang.String getDataToEncrypt()
           
 java.lang.String getFriendlyName()
           
 java.lang.String getLogString()
           
 java.lang.String getSecretKey()
           
protected abstract  java.lang.String getTypeName()
           
protected abstract  java.lang.String getVersionPrefix()
           
 boolean hasFriendlyName()
           
static ProviderCredentials load(java.lang.String password, java.io.BufferedInputStream inputStream)
          Loads encrypted credentials from a data input stream.
static ProviderCredentials load(java.lang.String password, java.io.File file)
          Loads encrypted credentials from a file.
 void save(java.lang.String password, java.io.File file)
          Encrypts ProviderCredentials with the given password and saves the encrypted data to a file using the default algorithm EncryptionUtil.DEFAULT_ALGORITHM.
 void save(java.lang.String password, java.io.File file, java.lang.String algorithm)
          Encrypts ProviderCredentials with the given password and saves the encrypted data to a file.
 void save(java.lang.String password, java.io.OutputStream outputStream)
          Encrypts ProviderCredentials with the given password and writes the encrypted data to an output stream using the default algorithm EncryptionUtil.DEFAULT_ALGORITHM.
 void save(java.lang.String password, java.io.OutputStream outputStream, java.lang.String algorithm)
          Encrypts ProviderCredentials with the given password and writes the encrypted data to an output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.apache.commons.logging.Log log

CREDENTIALS_STORAGE_VERSION

protected static final int CREDENTIALS_STORAGE_VERSION
See Also:
Constant Field Values

V2_KEYS_DELIMITER

protected static final java.lang.String V2_KEYS_DELIMITER
See Also:
Constant Field Values

V3_KEYS_DELIMITER

protected static final java.lang.String V3_KEYS_DELIMITER
See Also:
Constant Field Values

accessKey

protected java.lang.String accessKey

secretKey

protected java.lang.String secretKey

friendlyName

protected java.lang.String friendlyName
Constructor Detail

ProviderCredentials

public ProviderCredentials(java.lang.String accessKey,
                           java.lang.String secretKey)
Construct credentials.

Parameters:
accessKey - Access key for a storage account.
secretKey - Secret key for a storage account.

ProviderCredentials

public ProviderCredentials(java.lang.String accessKey,
                           java.lang.String secretKey,
                           java.lang.String friendlyName)
Construct credentials, and associate them with a human-friendly name.

Parameters:
accessKey - Access key for a storage account.
secretKey - Secret key for a storage account.
friendlyName - a name identifying the owner of the credentials, such as 'James'.
Method Detail

getAccessKey

public java.lang.String getAccessKey()
Returns:
the Access Key.

getSecretKey

public java.lang.String getSecretKey()
Returns:
the Secret Key.

getFriendlyName

public java.lang.String getFriendlyName()
Returns:
the friendly name associated with a storage account, if available.

hasFriendlyName

public boolean hasFriendlyName()
Returns:
true if there is a non-null and non-empty friendly name associated with this account.

getLogString

public java.lang.String getLogString()
Returns:
a string summarizing these credentials

getDataToEncrypt

protected java.lang.String getDataToEncrypt()
Returns:
the string of data that needs to be encrypted (for serialization)

getTypeName

protected abstract java.lang.String getTypeName()
Returns:
string representing this credential type's name (for serialization)

getVersionPrefix

protected abstract java.lang.String getVersionPrefix()

save

public void save(java.lang.String password,
                 java.io.File file,
                 java.lang.String algorithm)
          throws java.security.InvalidKeyException,
                 java.security.NoSuchAlgorithmException,
                 javax.crypto.NoSuchPaddingException,
                 java.security.spec.InvalidKeySpecException,
                 java.lang.IllegalStateException,
                 javax.crypto.IllegalBlockSizeException,
                 javax.crypto.BadPaddingException,
                 java.security.InvalidAlgorithmParameterException,
                 java.io.IOException
Encrypts ProviderCredentials with the given password and saves the encrypted data to a file.

Parameters:
password - the password used to encrypt the credentials.
file - the file to write the encrypted credentials data to.
algorithm - the algorithm used to encrypt the output stream.
Throws:
java.security.InvalidKeyException
java.security.NoSuchAlgorithmException
javax.crypto.NoSuchPaddingException
java.security.spec.InvalidKeySpecException
java.lang.IllegalStateException
javax.crypto.IllegalBlockSizeException
javax.crypto.BadPaddingException
java.security.InvalidAlgorithmParameterException
java.io.IOException

save

public void save(java.lang.String password,
                 java.io.File file)
          throws java.security.InvalidKeyException,
                 java.security.NoSuchAlgorithmException,
                 javax.crypto.NoSuchPaddingException,
                 java.security.spec.InvalidKeySpecException,
                 java.lang.IllegalStateException,
                 javax.crypto.IllegalBlockSizeException,
                 javax.crypto.BadPaddingException,
                 java.security.InvalidAlgorithmParameterException,
                 java.io.IOException
Encrypts ProviderCredentials with the given password and saves the encrypted data to a file using the default algorithm EncryptionUtil.DEFAULT_ALGORITHM.

Parameters:
password - the password used to encrypt the credentials.
file - the file to write the encrypted credentials data to.
Throws:
java.security.InvalidKeyException
java.security.NoSuchAlgorithmException
javax.crypto.NoSuchPaddingException
java.security.spec.InvalidKeySpecException
java.lang.IllegalStateException
javax.crypto.IllegalBlockSizeException
javax.crypto.BadPaddingException
java.security.InvalidAlgorithmParameterException
java.io.IOException

save

public void save(java.lang.String password,
                 java.io.OutputStream outputStream,
                 java.lang.String algorithm)
          throws java.security.InvalidKeyException,
                 java.security.NoSuchAlgorithmException,
                 javax.crypto.NoSuchPaddingException,
                 java.security.spec.InvalidKeySpecException,
                 java.lang.IllegalStateException,
                 javax.crypto.IllegalBlockSizeException,
                 javax.crypto.BadPaddingException,
                 java.security.InvalidAlgorithmParameterException,
                 java.io.IOException
Encrypts ProviderCredentials with the given password and writes the encrypted data to an output stream.

Parameters:
password - the password used to encrypt the credentials.
outputStream - the output stream to write the encrypted credentials data to, this stream must be closed by the caller.
algorithm - the algorithm used to encrypt the output stream.
Throws:
java.security.InvalidKeyException
java.security.NoSuchAlgorithmException
javax.crypto.NoSuchPaddingException
java.security.spec.InvalidKeySpecException
java.lang.IllegalStateException
javax.crypto.IllegalBlockSizeException
javax.crypto.BadPaddingException
java.security.InvalidAlgorithmParameterException
java.io.IOException

save

public void save(java.lang.String password,
                 java.io.OutputStream outputStream)
          throws java.security.InvalidKeyException,
                 java.security.NoSuchAlgorithmException,
                 javax.crypto.NoSuchPaddingException,
                 java.security.spec.InvalidKeySpecException,
                 java.lang.IllegalStateException,
                 javax.crypto.IllegalBlockSizeException,
                 javax.crypto.BadPaddingException,
                 java.security.InvalidAlgorithmParameterException,
                 java.io.IOException
Encrypts ProviderCredentials with the given password and writes the encrypted data to an output stream using the default algorithm EncryptionUtil.DEFAULT_ALGORITHM.

Parameters:
password - the password used to encrypt the credentials.
outputStream - the output stream to write the encrypted credentials data to, this stream must be closed by the caller.
Throws:
java.security.InvalidKeyException
java.security.NoSuchAlgorithmException
javax.crypto.NoSuchPaddingException
java.security.spec.InvalidKeySpecException
java.lang.IllegalStateException
javax.crypto.IllegalBlockSizeException
javax.crypto.BadPaddingException
java.security.InvalidAlgorithmParameterException
java.io.IOException

load

public static ProviderCredentials load(java.lang.String password,
                                       java.io.File file)
                                throws ServiceException
Loads encrypted credentials from a file.

Parameters:
password - the password used to decrypt the credentials. If null, the credentials are not decrypted and only the version and friendly-name information is loaded.
file - a file containing an encrypted data encoding of an ProviderCredentials object.
Returns:
the decrypted credentials in an object.
Throws:
ServiceException

load

public static ProviderCredentials load(java.lang.String password,
                                       java.io.BufferedInputStream inputStream)
                                throws ServiceException
Loads encrypted credentials from a data input stream.

Parameters:
password - the password used to decrypt the credentials. If null, the credentials are not decrypted and only the version and friendly-name information is loaded.
inputStream - an input stream containing an encrypted data encoding of an ProviderCredentials object.
Returns:
the decrypted credentials in an object.
Throws:
ServiceException