FileDocCategorySizeDatePackage
SolarisRealm.javaAPI DocGlassfish v2 API7771Thu Jul 26 00:06:02 BST 2007com.sun.enterprise.security.auth.realm.solaris

SolarisRealm

public final class SolarisRealm extends com.sun.enterprise.security.auth.realm.IASRealm
Realm wrapper for supporting Solaris authentication.

The Solaris realm needs the following properties in its configuration:

  • jaas-ctx - JAAS context name used to access LoginModule for authentication.
see
com.sun.enterprise.security.auth.login.SolarisLoginModule

Fields Summary
public static final String
AUTH_TYPE
private HashMap
groupCache
private Vector
emptyVector
Constructors Summary
Methods Summary
public java.lang.String[]authenticate(java.lang.String username, java.lang.String password)
Invoke the native authentication call.

param
username User to authenticate.
param
password Given password.
returns
true of false, indicating authentication status.

        String[] grps = nativeAuthenticate(username, password);
        if(grps != null){
            grps = addAssignGroups(grps);
        }
        setGroupNames(username, grps);
        return grps;
    
public java.lang.StringgetAuthType()
Returns a short (preferably less than fifteen characters) description of the kind of authentication which is supported by this realm.

return
Description of the kind of authentication that is directly supported by this realm.

        return AUTH_TYPE;
    
public java.util.EnumerationgetGroupNames(java.lang.String username)
Returns the name of all the groups that this user belongs to. This is called from web path role verification, though it should not be.

param
username Name of the user in this realm whose group listing is needed.
return
Enumeration of group names (strings).
exception
InvalidOperationException thrown if the realm does not support this operation - e.g. Certificate realm does not support this operation.

        Vector v = (Vector)groupCache.get(username);
        if (v == null) {
            v = loadGroupNames(username);
        }
        
        return v.elements();
    
public synchronized voidinit(java.util.Properties props)
Initialize a realm with some properties. This can be used when instantiating realms from their descriptions. This method may only be called a single time.

param
props Initialization parameters used by this realm.
exception
BadRealmException If the configuration parameters identify a corrupt realm.
exception
NoSuchRealmException If the configuration parameters specify a realm which doesn't exist.



    // Library for native methods
     
        System.loadLibrary("solarisauth");
    
        super.init(props);
        String jaasCtx = props.getProperty(IASRealm.JAAS_CONTEXT_PARAM);
        if (jaasCtx == null) {
            if (_logger.isLoggable(Level.WARNING)) {
                _logger.warning("realmconfig.noctx");
            }
            String msg = sm.getString("solarisrealm.nojaas");
            throw new BadRealmException(msg);
        }

        this.setProperty(IASRealm.JAAS_CONTEXT_PARAM, jaasCtx);

        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("SolarisRealm : "+IASRealm.JAAS_CONTEXT_PARAM+
                       "="+jaasCtx);
        }

        groupCache = new HashMap();
        emptyVector = new Vector();
    
private java.util.VectorloadGroupNames(java.lang.String username)
Loads groups names for the given user by calling native method.

Group info is loaded when user authenticates, however in some cases (such as run-as) the group membership info is needed without an authentication event.

        String[] grps = nativeGetGroups(username);
        if (grps == null) {
            _logger.fine("No groups returned for user: "+username);
        }
        
        grps = addAssignGroups(grps);
        setGroupNames(username, grps);
        return (Vector)groupCache.get(username);
    
private static native java.lang.String[]nativeAuthenticate(java.lang.String user, java.lang.String password)
Native method. Authenticate using PAM.

private static native java.lang.String[]nativeGetGroups(java.lang.String user)
Native method. Retrieve Solaris groups for user.

private voidsetGroupNames(java.lang.String username, java.lang.String[] groups)
Set group membership info for a user.

See bugs 4646133,4646270 on why this is here.

        Vector v = null;
        
        if (groups == null) {
            v = emptyVector;

        } else {
            v = new Vector(groups.length + 1);
            for (int i=0; i<groups.length; i++) {
                v.add(groups[i]);
            }
        }
        
        synchronized (this) {
            groupCache.put(username, v);
        }