Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.credentialsstorage
Class CredentialsStorageServiceImpl

java.lang.Object
  extended by net.java.sip.communicator.impl.credentialsstorage.CredentialsStorageServiceImpl
All Implemented Interfaces:
CredentialsStorageService

public class CredentialsStorageServiceImpl
extends Object
implements CredentialsStorageService

Implements CredentialsStorageService to load and store user credentials from/to the ConfigurationService.

Author:
Dmitri Melnikov

Field Summary
static String ACCOUNT_ENCRYPTED_PASSWORD
          The name of a property which represents an encrypted password.
static String ACCOUNT_UNENCRYPTED_PASSWORD
          The name of a property which represents an unencrypted password.
 
Constructor Summary
CredentialsStorageServiceImpl()
           
 
Method Summary
 boolean changeMasterPassword(String oldPassword, String newPassword)
          Changes the master password from the old to the new one.
 boolean isStoredEncrypted(String accountPrefix)
          Check if encrypted account password is saved in the configuration.
 boolean isUsingMasterPassword()
          Checks if master password is used to encrypt saved account passwords.
 String loadPassword(String accountPrefix)
          Loads the password for the specified account.
 boolean removePassword(String accountPrefix)
          Removes the password for the account that starts with the given prefix by setting its value in the configuration to null.
(package private)  void start(org.osgi.framework.BundleContext bc)
          Initializes the credentials service by fetching the configuration service reference from the bundle context.
(package private)  void stop()
          Forget the encryption/decryption key when stopping the service.
 boolean storePassword(String accountPrefix, String password)
          Stores the password for the specified account.
 boolean verifyMasterPassword(String master)
          Verifies the correctness of the master password.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACCOUNT_ENCRYPTED_PASSWORD

public static final String ACCOUNT_ENCRYPTED_PASSWORD
The name of a property which represents an encrypted password.

See Also:
Constant Field Values

ACCOUNT_UNENCRYPTED_PASSWORD

public static final String ACCOUNT_UNENCRYPTED_PASSWORD
The name of a property which represents an unencrypted password.

See Also:
Constant Field Values
Constructor Detail

CredentialsStorageServiceImpl

public CredentialsStorageServiceImpl()
Method Detail

start

void start(org.osgi.framework.BundleContext bc)
Initializes the credentials service by fetching the configuration service reference from the bundle context. Encrypts and moves all passwords to new properties.

Parameters:
bc - bundle context

stop

void stop()
Forget the encryption/decryption key when stopping the service.


storePassword

public boolean storePassword(String accountPrefix,
                             String password)
Stores the password for the specified account. When password is null the property is cleared. Many threads can call this method at the same time, and the first thread may present the user with the master password prompt and create a Crypto instance based on the input (createCrypto method). This instance will be used later by all other threads.

Specified by:
storePassword in interface CredentialsStorageService
Parameters:
accountPrefix - account prefix
password - the password to store
Returns:
true if the specified password was successfully stored; otherwise, false
See Also:
storePassword(String, String)

loadPassword

public String loadPassword(String accountPrefix)
Loads the password for the specified account. If the password is stored encrypted, decrypts it with the master password. Many threads can call this method at the same time, and the first thread may present the user with the master password prompt and create a Crypto instance based on the input (createCrypto method). This instance will be used later by all other threads.

Specified by:
loadPassword in interface CredentialsStorageService
Parameters:
accountPrefix - account prefix
Returns:
the loaded password for the accountPrefix
See Also:
createCrypto()

removePassword

public boolean removePassword(String accountPrefix)
Removes the password for the account that starts with the given prefix by setting its value in the configuration to null.

Specified by:
removePassword in interface CredentialsStorageService
Parameters:
accountPrefix - account prefix
Returns:
true if the password for the specified accountPrefix was successfully removed; otherwise, false

isUsingMasterPassword

public boolean isUsingMasterPassword()
Checks if master password is used to encrypt saved account passwords.

Specified by:
isUsingMasterPassword in interface CredentialsStorageService
Returns:
true if used, false if not

verifyMasterPassword

public boolean verifyMasterPassword(String master)
Verifies the correctness of the master password. Since we do not store the MP itself, if MASTER_PROP_VALUE is equal to the decrypted MASTER_PROP's value, then the MP is considered correct.

Specified by:
verifyMasterPassword in interface CredentialsStorageService
Parameters:
master - master password
Returns:
true if the password is correct; false, otherwise

changeMasterPassword

public boolean changeMasterPassword(String oldPassword,
                                    String newPassword)
Changes the master password from the old to the new one. Decrypts all encrypted password properties from the configuration with the oldPassword and encrypts them again with newPassword.

Specified by:
changeMasterPassword in interface CredentialsStorageService
Parameters:
oldPassword - old master password
newPassword - new master password
Returns:
true if master password was changed successfully; false, otherwise

isStoredEncrypted

public boolean isStoredEncrypted(String accountPrefix)
Check if encrypted account password is saved in the configuration.

Specified by:
isStoredEncrypted in interface CredentialsStorageService
Parameters:
accountPrefix - account prefix
Returns:
true if saved, false if not

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.