SimpleCredentials implements the Credentials
* interface and represents simple user ID/password credentials.
*
* @author Markus Nix
* @package phpcr
*/
final class SimpleCredentials implements Credentials
{
/**
* @var String
* @access private
*/
private $userId;
/**
* @var string
* @access private
*/
private $password;
/**
* @var array
* @access private
*/
private $attributes;
/**
* Create a new SimpleCredentials
object, given a user ID
* and password.
*
* Note that the given user password is cloned before it is stored
* in the new SimpleCredentials
object. This should
* avoid the risk of having unnecessary references to password data
* lying around in memory.
*
*
* @param userId the user ID
* @param password the user's password
*/
public function __construct( $userId, $password ) {
$this->userId = $userId;
$this->password = $password;
}
/**
* Returns the user password.
*
* Note that this method returns a reference to the password.
* It is the caller's responsibility to zero out the password information
* after it is no longer needed.
*
* @return the password
*/
public function getPassword() {
return $this->password;
}
/**
* Returns the user ID.
*
* @return String the user ID.
*/
public function getUserId() {
return userId;
}
/**
* Stores an attribute in this credentials instance.
*
* @param name a String
specifying the name of the attribute
* @param value the Object
to be stored
*/
public function setAttribute( $name = null, $value = null ) {
// name cannot be null
if ( !isset( $name ) ) {
throw new IllegalArgumentException("name cannot be null");
}
// null value is the same as removeAttribute()
if ( !isset( $value ) ) {
$this->removeAttribute( $name );
return;
}
$this->attributes[$name] = $value;
}
/**
* Returns the value of the named attribute as an Object
,
* or null
if no attribute of the given name exists.
*
* @param name a String
specifying the name of the attribute
* @return an Object
containing the value of the attribute,
* or null
if the attribute does not exist
*/
public function getAttribute( $name ) {
return $this->attributes[$name];
}
/**
* Removes an attribute from this credentials instance.
*
* @param name a String
specifying the name of the attribute
* to remove
*/
public function removeAttribute( $name ) {
unset( $this->attributes[$name] );
}
/**
* Returns the names of the attributes available to this
* credentials instance. This method returns an empty array
* if the credentials instance has no attributes available to it.
*
* Level 1 and 2
*
*
* @return a string array containing the names of the stored attributes
*/
public function getAttributeNames() {
return array_keys( $this->attributes );
}
}
?>