[jboss-cvs] jbosstest/src/main/org/jboss/test/security/test ...

Anil Saldhana anil.saldhana at jboss.com
Wed Jul 26 17:59:15 EDT 2006


  User: asaldhana
  Date: 06/07/26 17:59:15

  Added:       src/main/org/jboss/test/security/test  Tag: Branch_3_2
                        DynamicLoginConfigServiceUnitTestCase.java
  Log:
  JBAS-3210: allow absolute url for AuthConfig resources
  JBAS-3422: Do not default to conf/login-config.xml
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.4.2.2   +182 -0    jbosstest/src/main/org/jboss/test/security/test/DynamicLoginConfigServiceUnitTestCase.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: DynamicLoginConfigServiceUnitTestCase.java
  ===================================================================
  RCS file: DynamicLoginConfigServiceUnitTestCase.java
  diff -N DynamicLoginConfigServiceUnitTestCase.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ DynamicLoginConfigServiceUnitTestCase.java	26 Jul 2006 21:59:15 -0000	1.4.2.2
  @@ -0,0 +1,182 @@
  +/*
  +* JBoss, Home of Professional Open Source
  +* Copyright 2005, JBoss Inc., and individual contributors as indicated
  +* by the @authors tag. See the copyright.txt in the distribution for a
  +* full listing of individual contributors.
  +*
  +* This is free software; you can redistribute it and/or modify it
  +* under the terms of the GNU Lesser General Public License as
  +* published by the Free Software Foundation; either version 2.1 of
  +* the License, or (at your option) any later version.
  +*
  +* This software is distributed in the hope that it will be useful,
  +* but WITHOUT ANY WARRANTY; without even the implied warranty of
  +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  +* Lesser General Public License for more details.
  +*
  +* You should have received a copy of the GNU Lesser General Public
  +* License along with this software; if not, write to the Free
  +* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  +* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  +*/
  +package org.jboss.test.security.test; 
  +
  +import java.net.URL;
  +
  +import javax.management.Attribute;
  +import javax.management.MBeanServerConnection;
  +import javax.management.ObjectName;
  +
  +import junit.framework.Test;
  +import junit.framework.TestSuite;
  +
  +import org.jboss.test.JBossTestCase;
  +import org.jboss.test.JBossTestSetup; 
  +
  +//$Id: DynamicLoginConfigServiceUnitTestCase.java,v 1.4.2.2 2006/07/26 21:59:15 asaldhana Exp $
  +
  +/**
  + *  Unit tests for the Dynamic Login Config Service
  + *  @author <a href="mailto:Anil.Saldhana at jboss.org">Anil Saldhana</a>
  + *  @since  May 12, 2006
  + *  @version $Revision: 1.4.2.2 $
  + */
  +public class DynamicLoginConfigServiceUnitTestCase extends JBossTestCase
  +{ 
  +   private String login_config = "<policy>\n<application-policy name='test-dyn'>"+
  +                "<authentication>"+
  +                "<login-module code='org.jboss.security.auth.spi.UsersRolesLoginModule'" +
  +                " flag = 'required' /> </authentication></application-policy></policy>";
  +   
  +   public DynamicLoginConfigServiceUnitTestCase(String name)
  +   {
  +      super(name); 
  +   }
  +   
  +   /**
  +    * JBAS-3210: DynamicLoginConfig service fails absolute login-config.xml url
  +    * @throws Exception
  +    */
  +   public void testAbsoluteLoginConfigURL() throws Exception
  +   {
  +      MBeanServerConnection server = getServer(); 
  +      ObjectName oname = new ObjectName("jboss:service=TempFileCreator");  
  +      URL confURL = (URL)server.invoke(oname,"createTempFile",
  +            new Object[]{"test-dyn",login_config},
  +            new String[] {"java.lang.String", "java.lang.String"});
  +      assertNotNull(" config url != null",confURL); 
  +      ObjectName serviceOName = new ObjectName("jboss:service=TestDynamicLoginConfig");
  +      if(server.isRegistered(serviceOName))
  +         server.unregisterMBean(serviceOName);
  +      prepareTestDynamicLoginConfig(server,serviceOName,confURL.toExternalForm());   
  +      server.invoke(serviceOName,"create", new Object[0], new String[0]); 
  +      server.invoke(serviceOName,"start", new Object[0], new String[0]);
  +      
  +      //Restart the service
  +      server.invoke(serviceOName,"stop", new Object[0], new String[0]);
  +      server.invoke(serviceOName,"start", new Object[0], new String[0]);
  +      
  +      //Ensure that the service has been started
  +      String startedStr = (String)server.getAttribute(serviceOName, "StateString");
  +      assertTrue("Test Dynamic Login Config Service started?", startedStr.equalsIgnoreCase("Started"));
  +      
  +      String authConfig = (String)server.getAttribute(serviceOName,"AuthConfig");
  +      assertEquals(confURL + "matches", confURL.toExternalForm(), authConfig); 
  +      server.invoke(serviceOName,"stop", new Object[0], new String[0]);
  +      server.invoke(serviceOName,"destroy", new Object[0], new String[0]);
  +      if(server.isRegistered(serviceOName))
  +         server.unregisterMBean(serviceOName);
  +   } 
  +   
  +   /**
  +    * JBAS-3422: Do not allow Null AuthConfig or login-config.xml
  +    * @throws Exception
  +    */
  +   public void testAuthConf() throws Exception
  +   {
  +      MBeanServerConnection server = getServer(); 
  +      ObjectName serviceOName = new ObjectName("jboss:service=TestDynamicLoginConfig");
  +      if(server.isRegistered(serviceOName))
  +         server.unregisterMBean(serviceOName);
  +      prepareTestDynamicLoginConfig(server, 
  +            new ObjectName("jboss:service=TestDynamicLoginConfig"), null);
  +      try
  +      {
  +         server.invoke(serviceOName,"create", new Object[0], new String[0]); 
  +         server.invoke(serviceOName,"start", new Object[0], new String[0]);
  +         fail("Service should not have started");
  +      }
  +      catch(Throwable t)
  +      {
  +         log.debug("Service has rightly disagreed to start",t); 
  +      }
  +      finally
  +      {
  +         server.invoke(serviceOName,"stop", new Object[0], new String[0]); 
  +      }
  +      server.setAttribute(serviceOName,new Attribute("AuthConfig","login-config.xml"));  
  +      try
  +      { 
  +         server.invoke(serviceOName,"start", new Object[0], new String[0]);
  +         fail("Service should not have started");
  +      }
  +      catch(Throwable t)
  +      {
  +         log.debug("Service has rightly disagreed to start",t); 
  +      }
  +      finally
  +      {
  +         server.invoke(serviceOName,"stop", new Object[0], new String[0]);
  +         server.invoke(serviceOName,"destroy", new Object[0], new String[0]);
  +         if(server.isRegistered(serviceOName))
  +            server.unregisterMBean(serviceOName);
  +      }
  +   }
  +   
  +   private void prepareTestDynamicLoginConfig(MBeanServerConnection server, 
  +         ObjectName serviceOName, String confURL) throws Exception
  +   {
  +      server.createMBean("org.jboss.security.auth.login.DynamicLoginConfig", 
  +            serviceOName); 
  +      if(confURL != null)
  +      {
  +         Attribute attr = new Attribute("AuthConfig", confURL);
  +         server.setAttribute(serviceOName,attr);  
  +      } 
  +      
  +      ObjectName lcs = new ObjectName("jboss.security:service=XMLLoginConfig");
  +      Attribute attrLCS = new Attribute("LoginConfigService", lcs);
  +      server.setAttribute(serviceOName,attrLCS); 
  +   }
  +   
  +   public static Test suite()
  +   throws Exception
  +   {
  +      TestSuite suite = new TestSuite();
  +      suite.addTest(new TestSuite(DynamicLoginConfigServiceUnitTestCase.class));
  +      JBossTestSetup wrapper = new JBossTestSetup(suite)
  +      {
  +         protected void setUp() throws Exception
  +         {
  +            deploymentException = null;
  +            try
  +            {
  +               this.delegate.init();
  +               this.deploy("tempfilecreator.jar");
  +               this.redeploy(getResourceURL("jmx/tempFileCreator-service.xml")); 
  +            }
  +            catch (Exception ex)
  +            {
  +               // Throw this in testServerFound() instead.
  +               deploymentException = ex;
  +            }
  +         }
  +         
  +         protected void tearDown() throws Exception
  +         {
  +            this.undeploy(getResourceURL("jmx/tempFileCreator-service.xml")); 
  +         }
  +      };
  +      return wrapper; 
  +   }
  +}
  
  
  



More information about the jboss-cvs-commits mailing list