You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by ep...@apache.org on 2003/12/06 00:22:18 UTC

cvs commit: jakarta-turbine-fulcrum/security/nt/src/java/org/apache/fulcrum/security/nt NTUserManagerImpl.java ParseUtils.java

epugh       2003/12/05 15:22:18

  Added:       security/nt/src/test/org/apache/fulcrum/security/nt/dynamic
                        NTBasicModelManagerTest.java NTUserManagerTest.java
                        NTBasicACLTest.java NTDynamicModelManagerTest.java
               security/nt project.xml maven.xml project.properties
               security/nt/src/test DynamicNT.xml Log4j.properties
                        BasicNT.xml
               security/nt/src/java/org/apache/fulcrum/security/authenticator
                        NTAuthenticator.java
               security/nt/src/java/org/apache/fulcrum/security/nt
                        NTUserManagerImpl.java ParseUtils.java
  Log:
  Import various implementors
  
  Revision  Changes    Path
  1.1                  jakarta-turbine-fulcrum/security/nt/src/test/org/apache/fulcrum/security/nt/dynamic/NTBasicModelManagerTest.java
  
  Index: NTBasicModelManagerTest.java
  ===================================================================
  package org.apache.fulcrum.security.nt.dynamic;
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.fulcrum.security.SecurityService;
  import org.apache.fulcrum.security.UserManager;
  import org.apache.fulcrum.security.entity.Group;
  import org.apache.fulcrum.security.entity.User;
  import org.apache.fulcrum.security.model.basic.BasicModelManager;
  import org.apache.fulcrum.security.util.UnknownEntityException;
  import org.apache.fulcrum.testcontainer.BaseUnitTest;
  /**
   * @author Eric Pugh
   * 
   * Test the NT implementation of the user manager. This test traps some exceptions that can be
   * thrown if there is NO nt dll.
   */
  public class NTBasicModelManagerTest extends BaseUnitTest
  {
      private static Log log = LogFactory.getLog(NTBasicModelManagerTest.class);
      private static final String ERROR_MSG = "Not supported by NT User Manager";
      private static final String USERNAME = "Eric Pugh";
      private static final String DOMAIN = "IQUITOS";
      private static final String PASSWORD = "";
  	private static final String GUESTUSER = DOMAIN + "/" + "Guest";
  	private static final String TESTUSER = DOMAIN + "/" + USERNAME;
      private BasicModelManager modelManager;
  	private SecurityService securityService;
  	private UserManager userManager;
  	private User user;
  
      public static void main(String[] args)
      {
          junit.textui.TestRunner.run(NTBasicModelManagerTest.class);
      }
      public void setUp() throws Exception
      {
          this.setRoleFileName(null);
          this.setConfigurationFileName("src/test/BasicNT.xml");
          securityService = (SecurityService) lookup(SecurityService.ROLE);
          userManager = securityService.getUserManager();
          modelManager = (BasicModelManager) securityService.getModelManager();
      }
      public void tearDown()
      {
          user = null;
          userManager = null;
          securityService = null;
      }
      /**
       * Constructor for MemoryPermissionManagerTest.
       * 
       * @param arg0
       */
      public NTBasicModelManagerTest(String arg0)
      {
          super(arg0);
      }
      public void testRevokeAll() throws Exception
      {
          try
          {
              user = userManager.getUserInstance("domain/BOB");
              user.setPassword("rob");
              modelManager.revokeAll(user);
              fail("Should throw runtime exception");
          }
          catch (UnknownEntityException re)
          {
              assertTrue(re.getMessage().indexOf("Unknown user") > -1);
          }
      }
  
      public void testGrantUserGroup() throws Exception
      {
          user = userManager.getUserInstance("domain/BOB");
          user.setPassword("rob");
          Group group = securityService.getGroupManager().getGroupInstance();
          group.setName("TEST_GROUP");
          securityService.getGroupManager().addGroup(group);
          try
          {
              modelManager.grant(user, group);
              fail("Should throw runtime exception");
          }
          catch (UnknownEntityException re)
          {
              assertTrue(re.getMessage().indexOf("Unknown user") > -1);
          }
      }
      public void testRevokeUserGroup() throws Exception
      {
          try
          {
              user = userManager.getUserInstance("domain/BOB");
              user.setPassword("rob");
              Group group = securityService.getGroupManager().getGroupInstance();
              group.setName("TEST_REVOKE");
              securityService.getGroupManager().addGroup(group);
              modelManager.revoke(user, group);
              fail("Should throw runtime exception");
          }
          catch (UnknownEntityException re)
          {
              assertTrue(re.getMessage().indexOf("Unknown user") > -1);
          }
      }
    
  }
  
  
  
  1.1                  jakarta-turbine-fulcrum/security/nt/src/test/org/apache/fulcrum/security/nt/dynamic/NTUserManagerTest.java
  
  Index: NTUserManagerTest.java
  ===================================================================
  package org.apache.fulcrum.security.nt.dynamic;
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.fulcrum.security.SecurityService;
  import org.apache.fulcrum.security.acl.AccessControlList;
  import org.apache.fulcrum.security.model.dynamic.entity.DynamicUser;
  import org.apache.fulcrum.security.model.test.AbstractUserManagerTest;
  
  import com.tagish.auth.win32.NTSystem;
  /**
   * @author Eric Pugh
   * 
   * Test the NT implementation of the user manager. This test traps some exceptions that can be
   * thrown if there is NO nt dll.
   */
  public class NTUserManagerTest extends AbstractUserManagerTest
  {
      private static Log log = LogFactory.getLog(NTUserManagerTest.class);
      private static final String ERROR_MSG = "Not supported by NT User Manager";
      private static final String USERNAME = "Eric Pugh";
      private static final String DOMAIN = "IQUITOS";
      private static final String PASSWORD = "";
  	private static final String GUESTUSER = DOMAIN + "/" + "Guest";
  	private static final String TESTUSER = DOMAIN + "/" + USERNAME;
      //private DynamicModelManager modelManager;
      public static void main(String[] args)
      {
          junit.textui.TestRunner.run(NTUserManagerTest.class);
      }
      public void setUp() throws Exception
      {
          this.setRoleFileName(null);
          this.setConfigurationFileName("src/test/DynamicNT.xml");
          securityService = (SecurityService) lookup(SecurityService.ROLE);
          userManager = securityService.getUserManager();
          //modelManager = (DynamicModelManager) securityService.getModelManager();
      }
      public void tearDown()
      {
          user = null;
          userManager = null;
          securityService = null;
      }
      /**
       * Constructor for MemoryPermissionManagerTest.
       * 
       * @param arg0
       */
      public NTUserManagerTest(String arg0)
      {
          super(arg0);
      }
      public void testCheckExists() throws Exception
      {
          try
          {
  			user = userManager.getUser(GUESTUSER, "");
              user.setPassword("");
              assertTrue(userManager.checkExists(user));
          }
          catch (UnsatisfiedLinkError ule)
          {
              log.info("Unit test not being run due to missing NT DLL");
          }
      }
      public void testCheckExistsFails() throws Exception
      {
          try
          {
              user = new DynamicUser();
              user.setName("MCD\\Ronald Mcdonaled");
              ((DynamicUser) user).setPassword("");
              assertFalse(userManager.checkExists(user));
          }
          catch (NoClassDefFoundError ule)
          {
              log.info("Unit test not being run due to missing NT DLL");
          }
      }
      /**
       * tests getting an NT username
       */
      public void testNTGetName() throws Exception
      {
          try
          {
              NTSystem ntSystem = new NTSystem();
              assertTrue(
                  "Name is eric:" + ntSystem.getName(),
                  USERNAME.equals(ntSystem.getName()));
          }
          catch (NoClassDefFoundError ule)
          {
              log.info("Unit test not being run due to missing NT DLL");
          }
      }
      /**
       * tests getting an NT Domain
       */
      public void testGetDomain() throws Exception
      {
          try
          {
              NTSystem ntSystem = new NTSystem();
              assertTrue(
                  "Domain is:" + ntSystem.getDomain(),
                  DOMAIN.equals(ntSystem.getDomain()));
          }
          catch (NoClassDefFoundError ule)
          {
              log.info("Unit test not being run due to missing NT DLL");
          }
      }
      /**
       * tests logging on a different user
       */
      public void testLoginAsUser() throws Exception
      {
          try
          {
              NTSystem ntSystem = new NTSystem();
              char password[] = "editor!".toCharArray();
              ntSystem.logon(USERNAME, password, DOMAIN);
              String groups[] = ntSystem.getGroupNames(false);
              for (int i = 0; i < groups.length; i++)
              {
                  System.out.println("Groups :" + groups[i]);
              }
              ntSystem.logoff();
              assertTrue(
                  "User is:" + ntSystem.getName(),
                  USERNAME.equals(ntSystem.getName()));
              assertTrue(
                  "Domain is:" + ntSystem.getName(),
                  "IQUITOS".equals(ntSystem.getDomain()));
              assertTrue(
                  "Primary Group is:" + ntSystem.getPrimaryGroupName(),
                  "None".equals(ntSystem.getPrimaryGroupName()));
          }
          catch (NoClassDefFoundError ule)
          {
              log.info("Unit test not being run due to missing NT DLL");
          }
      }
      /*
       * Class to test for User retrieve(String, String)
       */
      public void testRetrieveStringString() throws Exception
      {
          try
          {
              user = userManager.getUser(GUESTUSER, PASSWORD);
              assertNotNull(user);
              assertTrue(((DynamicUser) user).getGroups().size() > 0);
          }
          catch (NoClassDefFoundError ule)
          {
              log.info("Unit test not being run due to missing NT DLL");
          }
      }
      public void testAuthenticate() throws Exception
      {
          try
          {
              user = userManager.getUserInstance(GUESTUSER);
              userManager.authenticate(user, PASSWORD);
          }
          catch (NoClassDefFoundError ule)
          {
              log.info("Unit test not being run due to missing NT DLL");
          }
      }
      public void testGetACL() throws Exception
      {
          try
          {
              user = userManager.getUserInstance(GUESTUSER);
              userManager.authenticate(user, PASSWORD);
              AccessControlList acl = userManager.getACL(user);
              assertNotNull(acl);
          }
          catch (NoClassDefFoundError ule)
          {
              log.info("Unit test not being run due to missing NT DLL");
          }
      }
      /** ******* ALL BELOW HERE THROW RUNTIME EXCEPTIONS ******** */
      /*
       * Class to test for User retrieve(String)
       */
      public void testRetrieveString() throws Exception
      {
          try
          {
              user = userManager.getUser("QuietMike");
              fail("Should throw runtime exception");
          }
          catch (RuntimeException re)
          {
              assertTrue(re.getMessage().equals(ERROR_MSG));
          }
      }
      public void testChangePassword() throws Exception
      {
  		user = userManager.getUser(GUESTUSER, "");
  		user.setPassword("");
          try
          {
              userManager.changePassword(user, "", "newPassword");
              fail("Should throw runtime exception");
          }
          catch (RuntimeException re)
          {
              assertTrue(re.getMessage().equals(ERROR_MSG));
          }
      }
      public void testForcePassword() throws Exception
      {
  		user = userManager.getUser(GUESTUSER, "");
  		user.setPassword("");
          try
          {
              userManager.forcePassword(user, "JC_SUBSET");
              fail("Should throw runtime exception");
          }
          catch (RuntimeException re)
          {
              assertTrue(re.getMessage().equals(ERROR_MSG));
          }
      }
     
      public void testSaveUser() throws Exception
      {
          try
          {
              userManager.saveUser(user);
              fail("Should throw runtime exception");
          }
          catch (RuntimeException re)
          {
              assertTrue(re.getMessage().equals(ERROR_MSG));
          }
      }
     
      public void testRemoveUser() throws Exception
      {
          try
          {
              userManager.removeUser(user);
              fail("Should throw runtime exception");
          }
          catch (RuntimeException re)
          {
              assertTrue(re.getMessage().equals(ERROR_MSG));
          }
      }
      public void testAddUser() throws Exception
      {
          try
          {
              user = userManager.getUserInstance("Joe1");
              userManager.addUser(user, "mc");
          }
          catch (RuntimeException re)
          {
              assertTrue(re.getMessage().equals(ERROR_MSG));
          }
      }
      public void testRetrieveingUsersByGroup() throws Exception
      {
          try
          {
              user = userManager.getUserInstance("Joe1");
              userManager.addUser(user, "mc");
          }
          catch (RuntimeException re)
          {
              assertTrue(re.getMessage().equals(ERROR_MSG));
          }
      }
  }
  
  
  
  1.1                  jakarta-turbine-fulcrum/security/nt/src/test/org/apache/fulcrum/security/nt/dynamic/NTBasicACLTest.java
  
  Index: NTBasicACLTest.java
  ===================================================================
  package org.apache.fulcrum.security.nt.dynamic;
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.fulcrum.security.SecurityService;
  import org.apache.fulcrum.security.UserManager;
  import org.apache.fulcrum.security.acl.AccessControlList;
  import org.apache.fulcrum.security.entity.User;
  import org.apache.fulcrum.security.model.basic.BasicAccessControlList;
  import org.apache.fulcrum.security.model.basic.BasicModelManager;
  import org.apache.fulcrum.security.util.UnknownEntityException;
  import org.apache.fulcrum.testcontainer.BaseUnitTest;
  /**
   * @author Eric Pugh
   * 
   * Test the NT implementation of the user manager. This test traps some exceptions that can be
   * thrown if there is NO nt dll.
   */
  public class NTBasicACLTest extends BaseUnitTest
  {
      private static Log log = LogFactory.getLog(NTBasicACLTest.class);
      private static final String ERROR_MSG = "Not supported by NT User Manager";
      private static final String USERNAME = "Eric Pugh";
      private static final String DOMAIN = "IQUITOS";
      private static final String PASSWORD = "";
  	private static final String GUESTUSER = DOMAIN + "/" + "Guest";
  	private static final String TESTUSER = DOMAIN + "/" + USERNAME;
      private BasicModelManager modelManager;
  	private SecurityService securityService;
  	private UserManager userManager;
  	private User user;
  
      public static void main(String[] args)
      {
          junit.textui.TestRunner.run(NTBasicACLTest.class);
      }
      public void setUp() throws Exception
      {
          this.setRoleFileName(null);
          this.setConfigurationFileName("src/test/BasicNT.xml");
          securityService = (SecurityService) lookup(SecurityService.ROLE);
          userManager = securityService.getUserManager();
          modelManager = (BasicModelManager) securityService.getModelManager();
      }
      public void tearDown()
      {
          user = null;
          userManager = null;
          securityService = null;
      }
      /**
       * Constructor for MemoryPermissionManagerTest.
       * 
       * @param arg0
       */
      public NTBasicACLTest(String arg0)
      {
          super(arg0);
      }
      public void testLoadingUpGroupsForBasicModelACL() throws Exception
      {
          try
          {
  			user = userManager.getUser(GUESTUSER, "");
              user.setPassword("");
              AccessControlList acl = userManager.getACL(user);
              assertTrue(acl instanceof BasicAccessControlList);
              BasicAccessControlList bacl = (BasicAccessControlList)acl;
              assertEquals(4,bacl.getGroups().size());
  			assertTrue(bacl.hasGroup("Guests"));
  			assertTrue(bacl.hasGroup("gUEsts"));
              
          }
          catch (UnknownEntityException re)
          {
              assertTrue(re.getMessage().indexOf("Unknown user") > -1);
          }
      }
  
     
    
  }
  
  
  
  1.1                  jakarta-turbine-fulcrum/security/nt/src/test/org/apache/fulcrum/security/nt/dynamic/NTDynamicModelManagerTest.java
  
  Index: NTDynamicModelManagerTest.java
  ===================================================================
  package org.apache.fulcrum.security.nt.dynamic;
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.fulcrum.security.SecurityService;
  import org.apache.fulcrum.security.UserManager;
  import org.apache.fulcrum.security.entity.Group;
  import org.apache.fulcrum.security.entity.User;
  import org.apache.fulcrum.security.model.dynamic.DynamicModelManager;
  import org.apache.fulcrum.security.util.UnknownEntityException;
  import org.apache.fulcrum.testcontainer.BaseUnitTest;
  /**
   * @author Eric Pugh
   * 
   * Test the NT implementation of the user manager. This test traps some exceptions that can be
   * thrown if there is NO nt dll.
   */
  public class NTDynamicModelManagerTest extends BaseUnitTest
  {
      private static Log log = LogFactory.getLog(NTDynamicModelManagerTest.class);
      private static final String ERROR_MSG = "Not supported by NT User Manager";
      private static final String USERNAME = "Eric Pugh";
      private static final String DOMAIN = "IQUITOS";
      private static final String PASSWORD = "";
  	private static final String GUESTUSER = DOMAIN + "/" + "Guest";
  	private static final String TESTUSER = DOMAIN + "/" + USERNAME;
      private DynamicModelManager modelManager;
  	private SecurityService securityService;
  	private UserManager userManager;
  	private User user;
  
      public static void main(String[] args)
      {
          junit.textui.TestRunner.run(NTDynamicModelManagerTest.class);
      }
      public void setUp() throws Exception
      {
          this.setRoleFileName(null);
          this.setConfigurationFileName("src/test/DynamicNT.xml");
          securityService = (SecurityService) lookup(SecurityService.ROLE);
          userManager = securityService.getUserManager();
          modelManager = (DynamicModelManager) securityService.getModelManager();
      }
      public void tearDown()
      {
          user = null;
          userManager = null;
          securityService = null;
      }
      /**
       * Constructor for MemoryPermissionManagerTest.
       * 
       * @param arg0
       */
      public NTDynamicModelManagerTest(String arg0)
      {
          super(arg0);
      }
      public void testRevokeAll() throws Exception
      {
          try
          {
              user = userManager.getUserInstance("domain/BOB");
              user.setPassword("rob");
              modelManager.revokeAll(user);
              fail("Should throw runtime exception");
          }
          catch (UnknownEntityException re)
          {
              assertTrue(re.getMessage().indexOf("Unknown user") > -1);
          }
      }
  
      public void testGrantUserGroup() throws Exception
      {
          user = userManager.getUserInstance("domain/BOB");
          user.setPassword("rob");
          Group group = securityService.getGroupManager().getGroupInstance();
          group.setName("TEST_GROUP");
          securityService.getGroupManager().addGroup(group);
          try
          {
              modelManager.grant(user, group);
              fail("Should throw runtime exception");
          }
          catch (UnknownEntityException re)
          {
              assertTrue(re.getMessage().indexOf("Unknown user") > -1);
          }
      }
      public void testRevokeUserGroup() throws Exception
      {
          try
          {
              user = userManager.getUserInstance("domain/BOB");
              user.setPassword("rob");
              Group group = securityService.getGroupManager().getGroupInstance();
              group.setName("TEST_REVOKE");
              securityService.getGroupManager().addGroup(group);
              modelManager.revoke(user, group);
              fail("Should throw runtime exception");
          }
          catch (UnknownEntityException re)
          {
              assertTrue(re.getMessage().indexOf("Unknown user") > -1);
          }
      }
    
  }
  
  
  
  1.1                  jakarta-turbine-fulcrum/security/nt/project.xml
  
  Index: project.xml
  ===================================================================
  <?xml version="1.0"?>
  <project>
    <extend>${basedir}/../../project.xml</extend>
    <id>fulcrum-security-nt</id>
    <name>Fulcrum Security NT Impl</name>
    <currentVersion>1.0-alpha-4</currentVersion>
    <package>org.apache.fulcrum.security</package>
  
    <dependencies>
      <dependency>
        <groupId>fulcrum</groupId>   
        <artifactId>fulcrum-security-api</artifactId>
        <version>1.0-alpha-4</version>
      </dependency>  
      <dependency>
        <groupId>fulcrum</groupId>   
        <artifactId>fulcrum-security-spi</artifactId>
        <version>1.0-alpha-4</version>
      </dependency>     
      <dependency>
        <groupId>fulcrum</groupId>   
        <artifactId>fulcrum-crypto</artifactId>
        <version>1.0-alpha-3</version>
      </dependency>
      
      <dependency>
        <groupId>fulcrum</groupId>    
        <artifactId>fulcrum-factory</artifactId>
        <version>1.0-alpha-1</version>
      </dependency>
  
      <dependency>
        <groupId>avalon-framework</groupId>
        <artifactId>avalon-framework-api</artifactId>
        <version>4.1.5</version>
      </dependency> 
      
      <dependency>
        <id>commons-logging</id>
        <version>1.0.3</version>
      </dependency>      
      <dependency>
        <id>commons-lang</id>
        <version>2.0</version>
      </dependency>  
      <dependency>
        <id>cryptix</id>
        <version>3.2.0</version>
        <url>http://www.cryptix.org/</url>
      </dependency>    
  
       <dependency>
        <id>tagishauth</id>
        <version>1.0.2</version>
        <url>http://free.tagish.net/jaas/index.jsp</url>
      </dependency>   
      
      <!-- testing -->
      <dependency>
        <groupId>fulcrum</groupId>    
        <artifactId>fulcrum-security-memory</artifactId>
        <version>1.0-alpha-4</version>
      </dependency>      
      <dependency>
        <groupId>fulcrum</groupId>    
        <artifactId>fulcrum-testcontainer</artifactId>
        <version>1.0-alpha-1</version>
      </dependency>        
      <!--dependency>
        <groupId>merlin</groupId>
        <artifactId>merlin-unit</artifactId>
        <version>3.2.3-dev</version>
      </dependency-->
  
    </dependencies>
  
  
  </project>
  
  
  
  
  1.1                  jakarta-turbine-fulcrum/security/nt/maven.xml
  
  Index: maven.xml
  ===================================================================
  <project default="jar:jar" xmlns:maven="jelly:maven" xmlns:j="jelly:core" xmlns:util="jelly:util">
  
    <preGoal name="java:compile">
      <attainGoal name="avalon:meta"/>
    </preGoal>
  
  </project>
  
  
  1.1                  jakarta-turbine-fulcrum/security/nt/project.properties
  
  Index: project.properties
  ===================================================================
  maven.multiproject.type=jar
  maven.junit.usefile=true
  maven.junit.fork=true
  
  
  
  1.1                  jakarta-turbine-fulcrum/security/nt/src/test/DynamicNT.xml
  
  Index: DynamicNT.xml
  ===================================================================
  <my-system>
    <component
      role="org.apache.fulcrum.security.SecurityService"
      class="org.apache.fulcrum.security.BaseSecurityService">   
    </component>  
  
    <component
      role="org.apache.fulcrum.security.UserManager"
      class="org.apache.fulcrum.security.nt.NTUserManagerImpl">   
      <className>org.apache.fulcrum.security.model.dynamic.entity.DynamicUser</className>         
    </component>   
   <component
      role="org.apache.fulcrum.security.GroupManager"
      class="org.apache.fulcrum.security.memory.MemoryGroupManagerImpl">   
      <className>org.apache.fulcrum.security.model.dynamic.entity.DynamicGroup</className>
    </component>     
  
    <component
      role="org.apache.fulcrum.security.RoleManager"
      class="org.apache.fulcrum.security.memory.MemoryRoleManagerImpl">   
      <className>org.apache.fulcrum.security.model.dynamic.entity.DynamicRole</className>
    </component>     
  
    <component
      role="org.apache.fulcrum.security.PermissionManager"
      class="org.apache.fulcrum.security.memory.MemoryPermissionManagerImpl">   
      <className>org.apache.fulcrum.security.model.dynamic.entity.DynamicPermission</className>    
    </component>     
  
    <component
      role="org.apache.fulcrum.security.ModelManager"
      class="org.apache.fulcrum.security.memory.dynamic.MemoryModelManagerImpl">   
    </component> 
    
    <component
      role="org.apache.fulcrum.security.authenticator.Authenticator"
      class="org.apache.fulcrum.security.authenticator.TextMatchAuthenticator">   
    </component> 
    
    <component
      role="org.apache.fulcrum.security.model.ACLFactory"
      class="org.apache.fulcrum.security.model.dynamic.DynamicACLFactory">   
    </component>    
  
  </my-system>
  
  
  1.1                  jakarta-turbine-fulcrum/security/nt/src/test/Log4j.properties
  
  Index: Log4j.properties
  ===================================================================
  # ------------------------------------------------------------------------
  #
  # Logging Configuration
  #
  # Mix of Turbine logging configuration and Hibernate configuration
  #
  # ------------------------------------------------------------------------
  
  #
  # If we don't know the logging facility, put it into the
  # turbine.log
  #
  log4j.rootLogger = INFO, turbine
  
  #
  # Turbine goes into Turbine Log
  #
  log4j.category.org.apache.turbine = INFO, turbine
  log4j.additivity.org.apache.turbine = false
  
  #
  # Avalon Logfile
  #
  log4j.category.avalon = INFO, avalon
  log4j.additivity.avalon = false
  
  ########################################################################
  #
  # Logfile definitions
  #
  ########################################################################
  
  #
  # turbine.log
  #
  log4j.appender.turbine = org.apache.log4j.FileAppender
  log4j.appender.turbine.file = turbine.log
  log4j.appender.turbine.layout = org.apache.log4j.PatternLayout
  log4j.appender.turbine.layout.conversionPattern = %d [%t] %-5p %c - %m%n
  log4j.appender.turbine.append = false
  
  #
  # torque.log
  # 
  log4j.appender.torque = org.apache.log4j.FileAppender
  log4j.appender.torque.file = target/torque.log
  log4j.appender.torque.layout = org.apache.log4j.PatternLayout
  log4j.appender.torque.layout.conversionPattern = %d [%t] %-5p %c - %m%n
  log4j.appender.torque.append = false
  
  #
  # Avalon gets configured to write its output onto the avalon
  # category.
  #
  log4j.appender.avalon = org.apache.log4j.FileAppender
  log4j.appender.avalon.file = target/avalon.log
  log4j.appender.avalon.layout = org.apache.log4j.PatternLayout
  log4j.appender.avalon.layout.conversionPattern = %d [%t] %-5p %c - %m%n
  log4j.appender.avalon.append = false
  
  
  # BEGIN HIBERNATE SECTION
  ### direct log messages to stdout ###
  log4j.appender.stdout=org.apache.log4j.ConsoleAppender
  log4j.appender.stdout.Target=System.out
  log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
  log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
  
  ### direct messages to file hibernate.log ###
  #log4j.appender.file=org.apache.log4j.FileAppender
  #log4j.appender.file.File=hibernate.log
  #log4j.appender.file.layout=org.apache.log4j.PatternLayout
  #log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
  
  ### set log levels - for more verbose logging change 'info' to 'debug' ##
  
  log4j.rootLogger=warn, stdout
  
  log4j.logger.net.sf.hibernate=warn
  
  ### enable the following line if you want to track down connection ###
  ### leakages when using DriverManagerConnectionProvider ###
  #log4j.logger.net.sf.hibernate.connection.DriverManagerConnectionProvider=trace
  
  ### log JDBC bind parameters ###
  log4j.logger.net.sf.hibernate.type=info
  
  ### log prepared statement cache activity ###
  log4j.logger.net.sf.hibernate.ps.PreparedStatementCache=info
  
  
  
  
  1.1                  jakarta-turbine-fulcrum/security/nt/src/test/BasicNT.xml
  
  Index: BasicNT.xml
  ===================================================================
  <my-system>
    <component
      role="org.apache.fulcrum.security.SecurityService"
      class="org.apache.fulcrum.security.BaseSecurityService">   
    </component>  
  
    <component
      role="org.apache.fulcrum.security.UserManager"
      class="org.apache.fulcrum.security.nt.NTUserManagerImpl">   
      <className>org.apache.fulcrum.security.model.basic.entity.BasicUser</className>         
    </component>   
    <component
      role="org.apache.fulcrum.security.GroupManager"
      class="org.apache.fulcrum.security.memory.MemoryGroupManagerImpl">   
      <className>org.apache.fulcrum.security.model.basic.entity.BasicGroup</className>
    </component>     
  
    <component
      role="org.apache.fulcrum.security.ModelManager"
      class="org.apache.fulcrum.security.memory.basic.MemoryModelManagerImpl">   
    </component> 
    
    <component
      role="org.apache.fulcrum.security.authenticator.Authenticator"
      class="org.apache.fulcrum.security.authenticator.TextMatchAuthenticator">   
    </component> 
  
    <component
      role="org.apache.fulcrum.security.model.ACLFactory"
      class="org.apache.fulcrum.security.model.basic.BasicACLFactory">   
    </component>   
    
  </my-system>
  
  
  1.1                  jakarta-turbine-fulcrum/security/nt/src/java/org/apache/fulcrum/security/authenticator/NTAuthenticator.java
  
  Index: NTAuthenticator.java
  ===================================================================
  package org.apache.fulcrum.security.authenticator;
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  import javax.security.auth.login.LoginException;
  
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.fulcrum.security.entity.User;
  import org.apache.fulcrum.security.nt.ParseUtils;
  import org.apache.fulcrum.security.util.DataBackendException;
  
  import com.tagish.auth.win32.NTSystem;
  /**
   * This class authenticates a user against NT.  Requires some
   * extra libraries.  
   *
   * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
   * @version $Id: NTAuthenticator.java,v 1.1 2003/12/05 23:22:18 epugh Exp $
   */
  public class NTAuthenticator extends AbstractLogEnabled implements Authenticator
  {
      /** Logging */
      private static Log log = LogFactory.getLog(NTAuthenticator.class);
      /**
       * Authenticate an username with the specified password. If authentication
       * is successful the method returns true. If it fails, it returns false
       * If there are any problems, an exception is thrown.
       * 
       *
       * @param usernameAndDomain an string in the format [domain]/[username].
       * @param password the user supplied password.
       * @exception UnknownEntityException if the user's account does not
       *            exist in the database.
       * @exception DataBackendException if there is a problem accessing the
       *            storage.
       */
      public boolean authenticate(User user, String password)
          throws  DataBackendException
      {
          // check NT...
          boolean authenticated = false;
          NTSystem ntSystem = new NTSystem();
          char passwordArray[] = password.toCharArray();
          try
          {
              String username = ParseUtils.parseForUsername(user.getName());
              String domain = ParseUtils.parseForDomain(user.getName());
              ntSystem.logon(username, passwordArray, domain);
              if (ntSystem.getName().equalsIgnoreCase(username))
              {
                  authenticated = true;
              }
              ntSystem.logoff();
          }
          catch (LoginException le)
          {
              ntSystem.logoff();
              throw new DataBackendException(le.getMessage(), le);
          }
          return authenticated;
      }
  
  }
  
  
  
  1.1                  jakarta-turbine-fulcrum/security/nt/src/java/org/apache/fulcrum/security/nt/NTUserManagerImpl.java
  
  Index: NTUserManagerImpl.java
  ===================================================================
  package org.apache.fulcrum.security.nt;
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  import javax.security.auth.login.LoginException;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.fulcrum.security.entity.Group;
  import org.apache.fulcrum.security.entity.User;
  import org.apache.fulcrum.security.model.basic.entity.BasicUser;
  import org.apache.fulcrum.security.model.dynamic.entity.DynamicUser;
  import org.apache.fulcrum.security.spi.AbstractUserManager;
  import org.apache.fulcrum.security.util.DataBackendException;
  import org.apache.fulcrum.security.util.EntityExistsException;
  import org.apache.fulcrum.security.util.PasswordMismatchException;
  import org.apache.fulcrum.security.util.UnknownEntityException;
  
  import com.tagish.auth.win32.NTSystem;
  /**
   * This implementation attempts to manager users against NT.
   * 
   * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
   * @version $Id: NTUserManagerImpl.java,v 1.1 2003/12/05 23:22:18 epugh Exp $
   */
  public class NTUserManagerImpl extends AbstractUserManager
  {
      /** Logging */
      private static Log log = LogFactory.getLog(NTUserManagerImpl.class);
  
      protected User persistNewUser(User user) throws DataBackendException
      {
          throw new RuntimeException("This method is not supported.");
      }
  
      /**
       * Retrieve a user from persistent storage using username as the key, and
       * authenticate the user. The implementation may chose to authenticate to
       * the server as the user whose data is being retrieved.
       * 
       * @param userName the name of the user.
       * @param password the user supplied password.
       * @return an User object.
       * @exception PasswordMismatchException if the supplied password was
       *                incorrect.
       * @exception UnknownEntityException if the user's account does not exist
       *                in the database.
       * @exception DataBackendException if there is a problem accessing the
       *                storage.
       */
      public User getUser(String userName, String password)
          throws PasswordMismatchException, UnknownEntityException, DataBackendException
      {
          User user = getUserInstance(userName);
          authenticate(user, password);
          return user;
      }
  
      /**
       * Check whether a specified user's account exists.
       * 
       * The login name is used for looking up the account.
       * 
       * @param user The user to be checked.
       * @return true if the specified account exists
       * @throws DataBackendException if there was an error accessing the data
       *             backend.
       */
      public boolean checkExists(User user) throws DataBackendException
      {
          boolean exists = false;
          try
          {
              authenticate(user, user.getPassword());
              exists = true;
          }
          catch (PasswordMismatchException pme)
          {
              exists = false;
          }
          catch (UnknownEntityException uee)
          {
              exists = false;
          }
          return exists;
      }
      /**
       * Check whether a specified user's account exists.
       * 
       * The login name is used for looking up the account.
       * 
       * @param userName The name of the user to be checked.
       * @return true if the specified account exists
       * @throws DataBackendException if there was an error accessing the data
       *             backend.
       */
      public boolean checkExists(String userName) throws DataBackendException
      {
          throw new RuntimeException("This method is not supported.");
      }
  
      /**
       * Retrieve a user from persistent storage using username as the key. Not
       * supported currently.
       * 
       * @param userName the name of the user.
       * @return an User object.
       * @exception UnknownEntityException if the user's account does not exist
       *                in the database.
       * @exception DataBackendException if there is a problem accessing the
       *                storage.
       */
      public User getUser(String userName)
          throws UnknownEntityException, DataBackendException
      {
          throw new RuntimeException("Not supported by NT User Manager");
      }
  
      /**
       * Authenticate an User with the specified password. If authentication is
       * successful the method returns nothing. If there are any problems,
       * exception was thrown.  Additionally, if the User object is of type BasicUser
       * or DynamicUser, then it will populate all the group information as well!
       * 
       * @param user an User object to authenticate.
       * @param password the user supplied password.
       * @exception PasswordMismatchException if the supplied password was
       *                incorrect.
       * @exception UnknownEntityException if the user's account does not exist
       *                in the database.
       * @exception DataBackendException if there is a problem accessing the
       *                storage.
       */
      public void authenticate(User user, String password)
          throws PasswordMismatchException, UnknownEntityException, DataBackendException
      {
          NTSystem ntSystem = new NTSystem();
          char passwordArray[] = password.toCharArray();
          try
          {
              String username = ParseUtils.parseForUsername(user.getName());
              String domain = ParseUtils.parseForDomain(user.getName());
              ntSystem.logon(username, passwordArray, domain);
              if (!ntSystem.getName().equalsIgnoreCase(username))
              {
                  throw new PasswordMismatchException(
                      "Could not authenticate user "
                          + username
                          + " against domain "
                          + domain);
              }
              String groups[] = ntSystem.getGroupNames(false);
              for (int i = 0; i < groups.length; i++)
              {
                  // Note how it populates groups? This
                  // should maybe delegate a call to the
                  // group manager to look for groups it
                  // knows about instead.
                  Group group = getGroupManager().getGroupInstance();
                  group.setName(groups[i]);
                  group.setId(groups[i]);
                  if (user instanceof DynamicUser)
                  {
                      ((DynamicUser) user).addGroup(group);
                  }
                  else if (user instanceof BasicUser)
                  {
                      ((BasicUser) user).addGroup(group);
                  }
              }
              ntSystem.logoff();
          }
          catch (LoginException le)
          {
              ntSystem.logoff();
              throw new DataBackendException(le.getMessage(), le);
          }
      }
  
      /**
       * Removes an user account from the system. Not supported currently.
       * 
       * @param user the object describing the account to be removed.
       * @throws DataBackendException if there was an error accessing the data
       *             backend.
       * @throws UnknownEntityException if the user account is not present.
       */
      public void removeUser(User user)
          throws DataBackendException, UnknownEntityException
      {
          throw new RuntimeException("Not supported by NT User Manager");
      }
      /**
       * Creates new user account with specified attributes. Not supported
       * currently.
       * 
       * @param user the object describing account to be created.
       * @param password The password to use for the account.
       * 
       * @throws DataBackendException if there was an error accessing the data
       *             backend.
       * @throws EntityExistsException if the user account already exists.
       */
      public User addUser(User user, String password)
          throws DataBackendException, EntityExistsException
      {
          throw new RuntimeException("Not supported by NT User Manager");
      }
      /**
       * Stores User attributes. The User is required to exist in the system. Not
       * supported currently.
       * 
       * @param role The User to be stored.
       * @throws DataBackendException if there was an error accessing the data
       *             backend.
       * @throws UnknownEntityException if the role does not exist.
       */
      public void saveUser(User user)
          throws DataBackendException, UnknownEntityException
      {
          throw new RuntimeException("Not supported by NT User Manager");
      }
  
  }
  
  
  
  1.1                  jakarta-turbine-fulcrum/security/nt/src/java/org/apache/fulcrum/security/nt/ParseUtils.java
  
  Index: ParseUtils.java
  ===================================================================
  package org.apache.fulcrum.security.nt;
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import javax.security.auth.login.LoginException;
  
  /**
   * Utility class for parsing username and domain out of a single string.
   *
   * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
   * @version $Id: ParseUtils.java,v 1.1 2003/12/05 23:22:18 epugh Exp $
   */
  public class ParseUtils
  {
      public static String parseForUsername(String usernameAndDomain) throws LoginException
      {
          // fix up angles in case user puts in wrong one!
          usernameAndDomain = usernameAndDomain.replace('/', '\\');
          // parse the domain and username values out of the username
          int separator = usernameAndDomain.indexOf("\\");
          if (separator == -1)
          {
              throw new LoginException("Error: no separator (\\) found in the username pased in to distingush between domain and username");
          }
          return usernameAndDomain.substring(separator + 1);
      }
      public static String parseForDomain(String usernameAndDomain) throws LoginException
      {
          // fix up angles in case user puts in wrong one!
          usernameAndDomain = usernameAndDomain.replace('/', '\\');
          // parse the domain and username values out of the username
          int separator = usernameAndDomain.indexOf("\\");
          if (separator == -1)
          {
              throw new LoginException("Error: no separator (\\) found in the username pased in to distingush between domain and username");
          }
          return usernameAndDomain.substring(0, separator);
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org