FileDocCategorySizeDatePackage
UsernamePasswordStore.javaAPI DocGlassfish v2 API5902Fri May 04 22:35:24 BST 2007com.sun.enterprise.security

UsernamePasswordStore

public final class UsernamePasswordStore extends Object
This class is used to share information between either of the following scenarios 1. Different points of execution of a single thread 2. Different threads that wish to share the username and password information Which of the above two condition is applicable depends upon the system property key "com.sun.appserv.iiopclient.perthreadauth"; When set to true, scenario #1 above applies and the username/password information is not shared between threads. When set to false, scenario #2 above applies and the username/password information stored by one thread is global and visible to all threads.

Fields Summary
private static final Logger
_logger
private static final boolean
isPerThreadAuth
private static ThreadLocal
localUpc
private static UsernamePasswordStore
sharedUpc
private final String
username
private final String
password
Constructors Summary
private UsernamePasswordStore(String username, String password)
This creates a new UsernamePasswordStore object. The constructor is marked as private.

param
username
param
password


                         
         
        this.username = username;
        this.password = password;
    
Methods Summary
private static com.sun.enterprise.security.UsernamePasswordStoreget()
This method returns a UsernamePasswordStore, that is either thread-local or global depending on the system property IIOP_PER_THREAD_CLIENT_FLAG. This method is marked as private.

return
The current UsernamePasswordStore

        if (isPerThreadAuth) {
            return (UsernamePasswordStore) localUpc.get();
        } else {
            synchronized (UsernamePasswordStore.class) {
                return sharedUpc;
            }
        }
    
public static java.lang.StringgetPassword()
Returns the password, that was previously stored.

return
The password set previously or null if not set

        UsernamePasswordStore ups = UsernamePasswordStore.get();
        if( ups != null )
            return ups.password;
        else 
            return null;
    
public static java.lang.StringgetUsername()
Returns the username, that was previously stored.

return
The username set previously or null if not set

        UsernamePasswordStore ups = UsernamePasswordStore.get();
        if( ups != null )
            return ups.username;
        else 
            return null;
    
public static voidreset()
Clears the username and password, that might have been previously stored, either globally or locally to each thread.

        if (isPerThreadAuth) {
            localUpc.set(null);
        } else {
            synchronized (UsernamePasswordStore.class) {
                sharedUpc = null;
            }
        }
    
public static voidresetThreadLocalOnly()
Clears the username and password only is they were stored locally to each thread

        if (isPerThreadAuth) {
            localUpc.set(null);
        }
    
public static voidset(java.lang.String username, java.lang.String password)
This method sets the username and password as thread-local or global variable

param
username
param
password

        if (isPerThreadAuth) {
            localUpc.set(new UsernamePasswordStore(username, password));
        } else {
            synchronized (UsernamePasswordStore.class) {
                sharedUpc = new UsernamePasswordStore(username, password);
            }
        }