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

AuthRealmConfigBeanHelper

public final class AuthRealmConfigBeanHelper extends StdConfigBeanHelper

Fields Summary
private AuthRealmSupport
mSupport
private static final String
TEMPLATE_PREFIX
private static final String
USER_NAMES_ATTR
private static final String
GROUP_NAMES_ATTR
private static final Set
SUPPORTED_OPERATIONS
Constructors Summary
public AuthRealmConfigBeanHelper(com.sun.enterprise.config.ConfigContext configContext, com.sun.enterprise.config.ConfigBean configBean)

        super( configContext, configBean );
        
        mSupport    = createSupport();
    
Methods Summary
protected java.util.Set_getAttributeNames()

    
         
    
    
        final Set<String>   attrNames = super._getAttributeNames();
        
        if ( isStdFileRealm() )
        {
            attrNames.add( GROUP_NAMES_ATTR );
            attrNames.add( USER_NAMES_ATTR );
        }
        
        return attrNames;
    
private voidcheckRealmType()

        if ( ! isStdFileRealm() )
        {
            throw new IllegalArgumentException(
                "AuthRealm type " + getClassname() +" not supported." );
        }
    
private AuthRealmSupportcreateSupport()

	
         
   
   
        AuthRealmSupport    support = null;
        
        if ( isStdFileRealm() )
        {
            String    file    = null;
            try
            {
                file    = getFile();
            }
            catch( Exception e )
            {
                // some realms are malformed
            }
            
            if ( file != null && file.indexOf( TEMPLATE_PREFIX ) < 0 )
            {
                support    = new AuthRealmSupport( this );
            }
            else if ( file != null )
            {
                // can't support it
            }
        }
        
        return support;
   
public java.lang.ObjectgetAttribute(java.lang.String attrName)

        Object  result  = null;
        
        if ( GROUP_NAMES_ATTR.equals( attrName ) )
        {
            checkRealmType();
            result  = mSupport.getGroupNames();
            //sdebug( "GroupNames: " + StringUtil.toString( (String[])result ) );
        }
        else if ( USER_NAMES_ATTR.equals( attrName ) )
        {
            checkRealmType();
            result  = mSupport.getUserNames();
            //sdebug( "UserNames: " + StringUtil.toString( (String[])result ) );
        }
        else
        {
            result  = super.getAttribute( attrName );
	    }
	    return result;
    
protected java.lang.ClassgetAttributeClass(java.lang.String attrName)

        Class  result  = null;
        
        if ( isStdFileRealm() &&
            (   GROUP_NAMES_ATTR.equals( attrName ) ||
                USER_NAMES_ATTR.equals( attrName ) ) )
        {
            result  = String[].class;
        }
        else
        {
            result  = super.getAttributeClass( attrName );
	    }
	    return result;
    
public java.lang.StringgetClassname()

        try
        {
            return (String)getAttribute( "Classname" );
        }
        catch( AttributeNotFoundException e )
        {
            e.printStackTrace();
            throw new RuntimeException( e );
        }
    
public java.lang.StringgetFile()

        return getPropertyValue( "file" );
    
public java.lang.ObjecthandleInvoke(java.lang.String operationName, java.lang.Object[] args, java.lang.String[] types)

    
         
    
    	 		
    		
    		 
    
        Object  result  = null;
        
        if(args == null)
        {
            unsupportedOperation( operationName, args, types );
        }

        final int   numArgs = args.length;
        
        if ( isStdFileRealm() &&
            SUPPORTED_OPERATIONS.contains( operationName ) && numArgs >= 1 )
        {
            final String    user    = (String)args[ 0 ];
                
            if (  operationName.equals( "getUserGroupNames" ) && numArgs == 1)
            {
                result  = mSupport.getUserGroupNames( user );
            }
            else if (  operationName.equals( "addUser" ) && numArgs == 3)
            {
                final String    password    = (String)args[ 1 ];
                final String[]    groupList    = (String[])args[ 2 ];
                mSupport.addUser( user, password, groupList );
            }
            else if (  operationName.equals( "updateUser" ) && numArgs == 3)
            {
                final String      password    = (String)args[ 1 ];
                final String[]    groupList    = (String[])args[ 2 ];
                mSupport.updateUser( user, password, groupList );
            }
            else if (  operationName.equals( "removeUser" ) && numArgs == 1)
            {
                mSupport.removeUser( user  );
            }
            else
            {
                unsupportedOperation( operationName, args, types );
            }
        }
        else
        {
            unsupportedOperation( operationName, args, types );
        }
        //sdebug( "handleInvoke: " + operationName + "(): " + result );
        
        return result;
    
private booleanisStdFileRealm()

        return AuthRealmConfig.DEFAULT_REALM_CLASSNAME.equals( getClassname() );