FileDocCategorySizeDatePackage
AuthRealmMBeanX.javaAPI DocGlassfish v2 API6978Fri May 04 22:23:40 BST 2007com.sun.enterprise.management.offline

AuthRealmMBeanX

public final class AuthRealmMBeanX extends Object
CAUTION: this code was COPIED from com.sun.enterprise.admin.mbeans.AuthRealmMBean. This class initially was a subclass of AuthRealmMBean, but it is impossible to instantiate the superclass, due to its hooks into MBeanRegistry, which throws an Exception when running "offline".
see
com.sun.enterprise.admin.mbeans.AuthRealmMBean

Fields Summary
private final String
mFile
Constructors Summary
public AuthRealmMBeanX(String file)

        mFile = file;
    
Methods Summary
public voidaddUser(java.lang.String userName, java.lang.String password, java.lang.String[] groupList)
Adds new user to file realm. User cannot exist already.

        final FileRealm realm = getRealmKeyFile();
        try
        {
            realm.addUser(userName, password, groupList);
            saveInstanceRealmKeyFile(realm);
        }
        catch(Exception e)
        {
            throw new MBeanConfigException( e.getMessage() );
        }
    
public java.lang.String[]getGroupNames()
Returns names of all the groups from the instance realm keyfile

        final FileRealm realm = getRealmKeyFile();
        try
        {
            return toStringArray(realm.getGroupNames());
        }
        catch(BadRealmException bre)
        {
            throw new MBeanConfigException(bre.getMessage());
        }
    
private com.sun.enterprise.security.auth.realm.file.FileRealmgetRealmKeyFile()

        try
        {
            return new FileRealm( mFile );
        }
        catch(Exception e)
        {
            throw new MBeanConfigException( e.getMessage() );
        }
    
public java.lang.String[]getUserGroupNames(java.lang.String userName)
Returns the name of all the groups that this user belongs to from the instance realm keyfile

        if( userName == null )
        {
            throw new IllegalArgumentException( "" + null );
        }

        final FileRealm realm = getRealmKeyFile();
        try
        {
            return toStringArray(realm.getGroupNames(userName));
        }
        catch(NoSuchUserException nse)
        {
            throw new MBeanConfigException(nse.getMessage());
        }
    
public java.lang.String[]getUserNames()

        final FileRealm realm = getRealmKeyFile();
        try
        {
            return toStringArray(realm.getUserNames());
        }
        catch(BadRealmException bre)
        {
            throw new MBeanConfigException(bre.getMessage());
        }
    
public voidremoveUser(java.lang.String userName)
Remove user from file realm. User must exist.

        final FileRealm realm = getRealmKeyFile();
        try
        {
            realm.removeUser(userName);
            saveInstanceRealmKeyFile(realm);
        }
        catch(NoSuchUserException nse)
        {
            throw new MBeanConfigException(nse.getMessage());
        }
    
private voidsaveInstanceRealmKeyFile(com.sun.enterprise.security.auth.realm.file.FileRealm realm)

        try
        {
            realm.writeKeyFile( mFile );
        }
        catch(IOException e)
        {
            throw new MBeanConfigException( e.getMessage() );
        }
 
private static java.lang.String[]toStringArray(java.util.Enumeration e)

        final List<String>  list = new ArrayList<String>();
        
        while( e.hasMoreElements() )
        {
            list.add( "" + e.nextElement() );
         }
        return CollectionUtil.toStringArray( list );
    
public voidupdateUser(java.lang.String userName, java.lang.String password, java.lang.String[] groupList)
Update data for an existing user. User must exist. This is equivalent to calling removeUser() followed by addUser().

        final FileRealm realm = getRealmKeyFile();
        try
        {
            realm.updateUser(userName, userName, password, groupList);
            saveInstanceRealmKeyFile( realm );
        }
        catch( Exception e )
        {
            throw new MBeanConfigException( e .getMessage() );
        }