FileDocCategorySizeDatePackage
ClientSecurityContext.javaAPI DocGlassfish v2 API6937Fri May 04 22:35:22 BST 2007com.sun.enterprise.security

ClientSecurityContext

public final class ClientSecurityContext extends AbstractSecurityContext
This class represents the security context on the client side. For usage of the IIOP_CLIENT_PER_THREAD_FLAG flag, see UsernamePasswordStore. When set to false, the volatile field sharedCsc is used to store the context.
see
UsernamePasswordStore
author
Harpreet Singh

Fields Summary
private static final Logger
_logger
public static final String
IIOP_CLIENT_PER_THREAD_FLAG
private static final boolean
isPerThreadAuth
private static ThreadLocal
localCsc
private static volatile ClientSecurityContext
sharedCsc
Constructors Summary
public ClientSecurityContext(String userName, Subject s)
This creates a new ClientSecurityContext object.

param
The name of the user.
param
The Credentials of the user.


                           
       
				   

	this.initiator = new PrincipalImpl(userName);
	this.subject = s ;
    
Methods Summary
private static com.sun.enterprise.security.ClientSecurityContextgenerateDefaultSecurityContext()

	final String PRINCIPAL_NAME = "auth.default.principal.name";
	final String PRINCIPAL_PASS = "auth.default.principal.password";
	
	ServerConfiguration config = ServerConfiguration.getConfiguration();
	String username = config.getProperty(PRINCIPAL_NAME, "guest");
	String password = config.getProperty(PRINCIPAL_PASS, "guest123");
	
        synchronized (ClientSecurityContext.class) {
            // login & all that stuff..
            try {
                final Subject subject = new Subject();
                final PasswordCredential pc = new PasswordCredential(username,
                        password, "default");
                AppservAccessController.doPrivileged(new PrivilegedAction() {
                    public java.lang.Object run() {
                        subject.getPrivateCredentials().add(pc);
                        return null;
                    }
                });
                // we do not need to generate any credential as authorization
                // decisions are not being done on the appclient side.
                ClientSecurityContext defaultCSC =
                    new ClientSecurityContext(username, subject);
                setCurrent(defaultCSC);
                return defaultCSC;
            } catch(Exception e) {
                _logger.log(Level.SEVERE,
                            "java_security.gen_security_context", e);
                return null;
            }
        }
    
public java.security.PrincipalgetCallerPrincipal()
This method returns the caller principal. This information may be redundant since the same information can be inferred by inspecting the Credentials of the caller.

return
The caller Principal.

	return initiator;
    
public static com.sun.enterprise.security.ClientSecurityContextgetCurrent()
This method gets the SecurityContext stored here. If using a per-thread authentication model, it gets the context from Thread Local Store (TLS) of the current thread. If not using a per-thread authentication model, it gets the singleton context.

return
The current Security Context stored here. It returns null if SecurityContext could not be found.

        if (isPerThreadAuth) {
            return (ClientSecurityContext) localCsc.get();
        } else {
            return sharedCsc;
        }
    
public javax.security.auth.SubjectgetSubject()

	return subject;
    
public static com.sun.enterprise.security.ClientSecurityContextinit()
Initialize the SecurityContext & handle the unauthenticated principal case

	ClientSecurityContext sc = getCurrent();
	if (sc == null) { // there is no current security context
            // create a default one if
	    sc = generateDefaultSecurityContext();
        }
	return sc;
    
public static voidsetCurrent(com.sun.enterprise.security.ClientSecurityContext sc)
This method sets the SecurityContext to be stored here.

param
The Security Context that should be stored.

        if (isPerThreadAuth) {
            localCsc.set(sc);
        } else {
            sharedCsc = sc;
        }
    
public java.lang.StringtoString()

	return "ClientSecurityContext[ " + "Initiator: " + initiator +
	    "Subject " + subject + " ]";