com.sun.sgs.impl.auth
Class NamePasswordAuthenticator

java.lang.Object
  extended by com.sun.sgs.impl.auth.NamePasswordAuthenticator
All Implemented Interfaces:
IdentityAuthenticator

public class NamePasswordAuthenticator
extends Object
implements IdentityAuthenticator

This simple implementation provides authentication based on a name and a password. It is intended only for development use.

The names and cooresponding passwords are provided through a file, which is read on startup and then never re-read. The file is named using the property PASSWORD_FILE_PROPERTY. The file is of a simple form that consists of one entry per line, where each entry has a name, some whitespace, a SHA-256 hashed password that is encoded via encodeBytes, and finally a newline.


Field Summary
static String DEFAULT_FILE_NAME
          The default name for the password file, relative to the app root.
static String PASSWORD_FILE_PROPERTY
          The property used to define the password file location.
 
Constructor Summary
NamePasswordAuthenticator(Properties properties)
          Creates an instance of NamePasswordAuthenticator.
 
Method Summary
 Identity authenticateIdentity(IdentityCredentials credentials)
          Authenticates the given credentials.
static byte[] decodeBytes(byte[] bytes)
          Decodes an array of bytes that has been encoded by a call to encodeBytes.
static byte[] encodeBytes(byte[] bytes)
          Encodes an array of bytes in a form suitable for including in a text file.
 String[] getSupportedCredentialTypes()
          Returns the identifiers for this IdentityAuthenticator's supported credential types.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PASSWORD_FILE_PROPERTY

public static final String PASSWORD_FILE_PROPERTY
The property used to define the password file location.

See Also:
Constant Field Values

DEFAULT_FILE_NAME

public static final String DEFAULT_FILE_NAME
The default name for the password file, relative to the app root.

See Also:
Constant Field Values
Constructor Detail

NamePasswordAuthenticator

public NamePasswordAuthenticator(Properties properties)
                          throws IOException,
                                 NoSuchAlgorithmException
Creates an instance of NamePasswordAuthenticator.

Parameters:
properties - the application's configuration properties
Throws:
FileNotFoundException - if the password file cannot be found
IOException - if any error occurs reading the password file
NoSuchAlgorithmException - if SHA-256 is not supported
Method Detail

decodeBytes

public static byte[] decodeBytes(byte[] bytes)
Decodes an array of bytes that has been encoded by a call to encodeBytes. This results in the original binary representation. This is used to decode a hashed password from the password file.

Parameters:
bytes - an encoded array of bytes as provided by a call to encodePassword
Returns:
the original binary representation

encodeBytes

public static byte[] encodeBytes(byte[] bytes)
Encodes an array of bytes in a form suitable for including in a text file. In this case, a very simple base-16 encoding is used. The original binary representation can be resolved by calling decodeBytes. This is used to turn a hashed password into a form suitable for the password file.

Parameters:
bytes - an array of bytes
Returns:
an encoding of the bytes in a form suitable for use in text

getSupportedCredentialTypes

public String[] getSupportedCredentialTypes()
Returns the identifiers for this IdentityAuthenticator's supported credential types. This may contain any number of identifiers, which are matched against the identifier of IdentityCredentials to determine if this IdentityAuthenticator can consume those credentials.

Specified by:
getSupportedCredentialTypes in interface IdentityAuthenticator
Returns:
the identifiers for the supported credential types

authenticateIdentity

public Identity authenticateIdentity(IdentityCredentials credentials)
                              throws AccountNotFoundException,
                                     CredentialException
Authenticates the given credentials. The returned Identity is valid, but has not yet been notified as logged in.

The provided IdentityCredentials must be an instance of NamePasswordCredentials.

Specified by:
authenticateIdentity in interface IdentityAuthenticator
Parameters:
credentials - the IdentityCredentials to authenticate
Returns:
an authenticated Identity
Throws:
AccountNotFoundException - if the identity is unknown
CredentialException - if the credentials are invalid

RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved