FileDocCategorySizeDatePackage
AuthRealmConfigTest.javaAPI DocGlassfish v2 API9638Fri May 04 22:23:54 BST 2007com.sun.enterprise.management.config

AuthRealmConfigTest

public final class AuthRealmConfigTest extends ConfigMgrTestBase

Fields Summary
private static boolean
WARNED_TESTABLE
private static final String
TEMPLATE_PREFIX
Constructors Summary
public AuthRealmConfigTest()

	    if ( checkNotOffline( "ensureDefaultInstance" ) )
	    {
	        ensureDefaultInstance( getConfigConfig().getSecurityServiceConfig() );
	    }
	
Methods Summary
public static com.sun.appserv.management.config.AuthRealmConfigcreateInstance(com.sun.appserv.management.config.SecurityServiceConfig securityServiceConfig, java.lang.String name, java.lang.String classname, java.lang.String keyFile)

	    final Map<String,String>  options  = new HashMap<String,String>();
	    
	    options.put( KEY_FILE_PROPERTY_KEY, keyFile );
	    options.put( JAAS_CONTEXT_PROPERTY_KEY, "dummy-jaas-context-value" );
	    
	    return securityServiceConfig.createAuthRealmConfig( name, classname, options);
	
protected final com.sun.appserv.management.config.AMXConfigcreateProgeny(java.lang.String name, java.util.Map options)

	    if ( name.indexOf( "Illegal" ) >= 0 )
	    {
	        // MBean doesn't detect illegal parameters; anything is allowed
	        // for the realm.
	        throw new IllegalArgumentException();
	    }
	    
	    return createInstance( getConfigConfig().getSecurityServiceConfig(),
	        name, DEFAULT_REALM_CLASSNAME, name + "-keyfile" );
	
public static com.sun.appserv.management.config.AuthRealmConfigensureDefaultInstance(com.sun.appserv.management.config.SecurityServiceConfig securityServiceConfig)

	    AuthRealmConfig   result  =
	        securityServiceConfig.getAuthRealmConfigMap().get( getDefaultInstanceName() );
	    
	    if ( result == null )
	    {
	        result  = createInstance( securityServiceConfig,
	            getDefaultInstanceName(),
	            DEFAULT_REALM_CLASSNAME,
	            KEY_FILE_PREFIX + "default-instance-test" );
	    }
	    
	    return result;
	
public static java.lang.StringgetDefaultInstanceName()

        return getDefaultInstanceName( "AuthRealmConfig" );
    
protected com.sun.appserv.management.base.ContainergetProgenyContainer()

		return getConfigConfig().getSecurityServiceConfig();
	
protected java.lang.StringgetProgenyJ2EEType()

		return XTypes.AUTH_REALM_CONFIG;
	
private synchronized java.util.MapgetTestableAuthRealms()

	
	      
	
	
        final Map<String,AuthRealmConfig>   m =
            getConfigConfig().getSecurityServiceConfig().getAuthRealmConfigMap();
        
        final Map<String,AuthRealmConfig>   std = new HashMap<String,AuthRealmConfig>();
        final List<String>  warnings    = new ArrayList<String>();
        for( final String name : m.keySet() )
        {
            final AuthRealmConfig   c = m.get( name );
            
            if ( AuthRealmConfig.DEFAULT_REALM_CLASSNAME.equals( c.getClassname() ) )
            {
                try
                {
                    final String    file    = c.getPropertyValue( "file" );
                    if ( file == null )
                    {
                        warnings.add( "Realm " + name +
                            " does not have a 'file' property (test skipped)" );
                    }
                    else if ( file.indexOf( TEMPLATE_PREFIX ) >= 0 )
                    {
                        warnings.add( "Realm " + name +
                            " uses a ${...} name, not yet supported (test skipped)" );
                    }
                    else
                    {
                        std.put( c.getName(), c );
                    }
                }
                catch( Exception e )
                {
                }
            }
        }
        
        if ( ! WARNED_TESTABLE )
        {
            WARNED_TESTABLE = true;
            warning( NEWLINE + CollectionUtil.toString( warnings, NEWLINE ) + NEWLINE +
            "Realms which WILL be tested: {" + CollectionUtil.toString( m.keySet() ) + "}");
        }
        
        return std;
	
protected voidremoveProgeny(java.lang.String name)

		getConfigConfig().getSecurityServiceConfig().removeAuthRealmConfig( name );
	
public synchronized voidtestAddRemoveUpdateUser()

        final Map<String,AuthRealmConfig>   arcMap = getTestableAuthRealms();
        
        final String    USER    = "test";
        
        final Set<AuthRealmConfig>  failures    = new HashSet<AuthRealmConfig>();
        
        for( final AuthRealmConfig ar : arcMap.values() )
        {
            //printVerbose( "TESTING: " + ar.getName() );
            
            try
            {
                ar.getUserNames();
                
                if ( userExists( ar, USER ) )
                {
                    ar.removeUser( USER );
                }
                
                ar.addUser( USER, "foo-pwd", null );
                assert( userExists( ar, USER ) );
                ar.updateUser( USER, "foo-pwd2", null );
                assert( userExists( ar, USER ) );
                ar.removeUser( USER );
                assert( ! userExists( ar, USER ) );
                //printVerbose( "SUCCESS testing: " + ar.getName() );
            }
            catch( Exception e )
            {
                trace( "" );
                trace( "" );
                trace( "FAILURE FOR: " + ar.getName() );
                //e.printStackTrace();
                failures.add( ar );
            }
        }
        
        if ( failures.size() != 0 )
        {
            final Set<String>  names   = Util.getNames( failures );
            
            warning( "testAddRemoveUpdateUser failed on the following realms: " +
                CollectionUtil.toString( names ) );
            assert( false );
        }
        
    
public synchronized voidtestGetGroupNames()

        final Map<String,AuthRealmConfig>   arcMap = getTestableAuthRealms();
        
        for( final AuthRealmConfig ar : arcMap.values() )
        {
            ar.getGroupNames();
        }
    
public synchronized voidtestGetUserGroupNames()

        final Map<String,AuthRealmConfig>   arcMap = getTestableAuthRealms();
        
        for( final AuthRealmConfig ar : arcMap.values() )
        {
            final String[]  users   = ar.getUserNames();
            for( final String user : users )
            {
                ar.getUserGroupNames( user );
            }
        }
    
public synchronized voidtestGetters()

        final Map<String,AuthRealmConfig>   arcMap = getTestableAuthRealms();
        
        for( final AuthRealmConfig ar : arcMap.values() )
        {
            ar.getName();
            final String    classname   = ar.getClassname();
            if ( classname != null )
            {
                ar.setClassname( classname );
            }
        }
    
private booleanuserExists(com.sun.appserv.management.config.AuthRealmConfig config, java.lang.String user)

        return GSetUtil.newStringSet( (String[])config.getUserNames() ).contains( user );