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/10/22 15:14:38 UTC
cvs commit: jakarta-turbine-fulcrum/security/src/test/org/apache/fulcrum/security/adapter/osuser OSUserAdapterTest.java
epugh 2003/10/22 06:14:38
Modified: security/src/java/org/apache/fulcrum/security/adapter/osuser
BaseFulcrumProvider.java
FulcrumCredentialsProvider.java
security/src/test/org/apache/fulcrum/security/adapter/osuser
OSUserAdapterTest.java
Log:
Throw Runtime exception for not implemented classes so users dont' think they are working, and
returning negative results!
Revision Changes Path
1.4 +2 -7 jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/adapter/osuser/BaseFulcrumProvider.java
Index: BaseFulcrumProvider.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/adapter/osuser/BaseFulcrumProvider.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- BaseFulcrumProvider.java 21 Oct 2003 10:16:29 -0000 1.3
+++ BaseFulcrumProvider.java 22 Oct 2003 13:14:38 -0000 1.4
@@ -54,12 +54,7 @@
*/
import java.util.Properties;
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
-import org.apache.avalon.framework.component.ComponentManager;
-import org.apache.avalon.framework.component.Composable;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fulcrum.security.SecurityService;
@@ -155,7 +150,7 @@
*
* @return
*/
- SecurityService getSecurityService() throws DataBackendException
+ public SecurityService getSecurityService() throws DataBackendException
{
if (securityService == null)
{
1.3 +114 -123 jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/adapter/osuser/FulcrumCredentialsProvider.java
Index: FulcrumCredentialsProvider.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/adapter/osuser/FulcrumCredentialsProvider.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FulcrumCredentialsProvider.java 21 Oct 2003 10:16:29 -0000 1.2
+++ FulcrumCredentialsProvider.java 22 Oct 2003 13:14:38 -0000 1.3
@@ -1,56 +1,44 @@
package org.apache.fulcrum.security.adapter.osuser;
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
- * reserved.
- *
+/*
+ * ==================================================================== 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.
+ * 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/>.
+ *
+ * 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 java.util.List;
@@ -64,129 +52,132 @@
import com.opensymphony.user.provider.CredentialsProvider;
/**
- * Fulcrum provider for OSUser. Primarily provides support for authenticating
- * a user. This delegates to whatever authenticator is configured in the
+ * Fulcrum provider for OSUser. Primarily provides support for authenticating a
+ * user. This delegates to whatever authenticator is configured in the
* getSecurityService().
*
* @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
- * @version $Id$
+ * @version $Id: FulcrumCredentialsProvider.java,v 1.2 2003/10/21 10:16:29
+ * epugh Exp $
*/
public class FulcrumCredentialsProvider
- extends BaseFulcrumProvider
- implements CredentialsProvider
+ extends BaseFulcrumProvider
+ implements CredentialsProvider
{
- /*
+ /*
* Authenticate a user with their password.
*
* @see com.opensymphony.user.provider.CredentialsProvider#authenticate(java.lang.String,
* java.lang.String)
*/
- public boolean authenticate(String name, String password)
- {
- try
- {
- User user = getSecurityService().getUserManager().getUser(name);
- getSecurityService().getUserManager().authenticate(user, password);
- return true;
- }
- catch (PasswordMismatchException pme)
- {
- return false;
- }
- catch (UnknownEntityException uee)
- {
- return false;
- }
- catch (DataBackendException dbe)
- {
- throw new RuntimeException(dbe);
- }
+ public boolean authenticate(String name, String password)
+ {
+ try
+ {
+ User user = getSecurityService().getUserManager().getUser(name);
+ getSecurityService().getUserManager().authenticate(user, password);
+ return true;
+ }
+ catch (PasswordMismatchException pme)
+ {
+ return false;
+ }
+ catch (UnknownEntityException uee)
+ {
+ return false;
+ }
+ catch (DataBackendException dbe)
+ {
+ throw new RuntimeException(dbe);
+ }
- }
+ }
- /*
+ /*
* Not implemented.
*
* @see com.opensymphony.user.provider.CredentialsProvider#changePassword(java.lang.String,
* java.lang.String)
*/
- public boolean changePassword(String arg0, String arg1)
- {
- return false;
- }
+ public boolean changePassword(String arg0, String arg1)
+ {
+ throw new RuntimeException("Not implemented");
+ }
- /*
+ /*
* Not implemented.
*
* @see com.opensymphony.user.provider.UserProvider#create(java.lang.String)
*/
- public boolean create(String arg0)
- {
- return false;
- }
+ public boolean create(String name)
+ {
+
+ throw new RuntimeException("Not implemented");
+
+ }
- /*
+ /*
* Does nothing.
*
* @see com.opensymphony.user.provider.UserProvider#flushCaches()
*/
- public void flushCaches()
- {
+ public void flushCaches()
+ {
- }
+ }
- /*
+ /*
* Returns whether a user exists or not.
*
* @see com.opensymphony.user.provider.UserProvider#handles(java.lang.String)
*/
- public boolean handles(String name)
- {
- try
- {
- User user = getSecurityService().getUserManager().getUser(name);
- return true;
- }
- catch (UnknownEntityException uee)
- {
- return false;
- }
- catch (DataBackendException dbe)
- {
- throw new RuntimeException(dbe);
- }
- }
+ public boolean handles(String name)
+ {
+ try
+ {
+ User user = getSecurityService().getUserManager().getUser(name);
+ return true;
+ }
+ catch (UnknownEntityException uee)
+ {
+ return false;
+ }
+ catch (DataBackendException dbe)
+ {
+ throw new RuntimeException(dbe);
+ }
+ }
- /*
+ /*
* Not implemented.
*
* @see com.opensymphony.user.provider.UserProvider#list()
*/
- public List list()
- {
- return null;
- }
+ public List list()
+ {
+ return null;
+ }
- /*
+ /*
* Not implemented.
*
* @see com.opensymphony.user.provider.UserProvider#remove(java.lang.String)
*/
- public boolean remove(String arg0)
- {
- return false;
- }
+ public boolean remove(String arg0)
+ {
+ throw new RuntimeException("Not implemented");
+ }
- /*
+ /*
* Not implemented.
*
* @see com.opensymphony.user.provider.UserProvider#store(java.lang.String,
* com.opensymphony.user.Entity.Accessor)
*/
- public boolean store(String arg0, Accessor arg1)
- {
- return false;
- }
+ public boolean store(String arg0, Accessor arg1)
+ {
+ throw new RuntimeException("Not implemented");
+ }
}
1.3 +34 -34 jakarta-turbine-fulcrum/security/src/test/org/apache/fulcrum/security/adapter/osuser/OSUserAdapterTest.java
Index: OSUserAdapterTest.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-fulcrum/security/src/test/org/apache/fulcrum/security/adapter/osuser/OSUserAdapterTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- OSUserAdapterTest.java 21 Oct 2003 10:16:29 -0000 1.2
+++ OSUserAdapterTest.java 22 Oct 2003 13:14:38 -0000 1.3
@@ -53,6 +53,7 @@
import org.apache.fulcrum.security.model.simple.manager.SimpleUserManager;
import org.apache.fulcrum.testcontainer.BaseUnitTest;
+import com.opensymphony.user.User;
import com.opensymphony.user.UserManager;
import com.opensymphony.user.provider.AccessProvider;
import com.opensymphony.user.provider.CredentialsProvider;
@@ -70,8 +71,11 @@
{
protected UserManager osUserManager;
-
+
protected SecurityService securityService;
+ private org.apache.fulcrum.security.entity.User fulcrumUser;
+ private User osUser;
+
public OSUserAdapterTest(String name) throws Exception
{
super(name);
@@ -80,15 +84,12 @@
{
try
{
- /*
- * this.setRoleFileName(null);
- * this.setConfigurationFileName("src/test/SimpleMemory.xml");
- * securityService = (SecurityService)
- * lookup(SecurityService.ROLE); fulcrumUserManager =
- * securityService.getUserManager();
- *
- * osUserManager = new UserManager("osuser.xml");
- */
+ this.setRoleFileName(null);
+ this.setConfigurationFileName("src/test/OSUserAvalonConf.xml");
+ securityService = (SecurityService) lookup(SecurityService.ROLE);
+ BaseFulcrumProvider.setSecurityService(securityService);
+
+ osUserManager = new UserManager("osuser.xml");
}
catch (Exception e)
{
@@ -99,20 +100,11 @@
{
osUserManager = null;
-
+
securityService = null;
}
public void testUsingAvalonComponents() throws Exception
{
-
- this.setRoleFileName(null);
- this.setConfigurationFileName("src/test/OSUserAvalonConf.xml");
- securityService = (SecurityService) lookup(SecurityService.ROLE);
- BaseFulcrumProvider.setSecurityService(securityService);
-
-
- osUserManager = new UserManager("osuser.xml");
-
Group fulcrumGroup =
securityService.getGroupManager().getGroupInstance(
"TEST_REVOKEALL");
@@ -159,7 +151,7 @@
((SimpleGroupManager) securityService.getGroupManager()).grant(
fulcrumGroup2,
fulcrumRole2);
- org.apache.fulcrum.security.entity.User fulcrumUser =
+ fulcrumUser =
securityService.getUserManager().getUserInstance("Jeannie");
securityService.getUserManager().addUser(fulcrumUser, "wyatt");
((SimpleUserManager) securityService.getUserManager()).grant(
@@ -177,25 +169,33 @@
assertTrue(accessProvider.handles("Jeannie"));
assertTrue(securityService.getUserManager().checkExists("Jeannie"));
- assertEquals("Both should not handle user Bob",accessProvider.handles("Bob") ,securityService.getUserManager().checkExists("Bob"));
-
+ assertEquals(
+ "Both should not handle user Bob",
+ accessProvider.handles("Bob"),
+ securityService.getUserManager().checkExists("Bob"));
fulcrumUser = securityService.getUserManager().getUser("Jeannie");
AccessControlList acl =
securityService.getUserManager().getACL(fulcrumUser);
- assertEquals("Both should have role1",acl.hasRole("role1"),accessProvider.inGroup("Jeannie", "role1"));
-
+ assertEquals(
+ "Both should have role1",
+ acl.hasRole("role1"),
+ accessProvider.inGroup("Jeannie", "role1"));
+
+ assertEquals(
+ "Neither should have role3",
+ acl.hasRole("role3"),
+ accessProvider.inGroup("Jeannie", "role3"));
+
+ Collection credentialProviders =
+ osUserManager.getCredentialsProviders();
+ assertEquals(1, credentialProviders.size());
+ CredentialsProvider credentialProvider =
+ (CredentialsProvider) credentialProviders.toArray()[0];
- assertEquals("Neither should have role3",acl.hasRole("role3"),accessProvider.inGroup("Jeannie", "role3"));
-
- Collection credentialProviders = osUserManager.getCredentialsProviders();
- assertEquals(1,credentialProviders.size());
- CredentialsProvider credentialProvider = (CredentialsProvider)credentialProviders.toArray()[0];
-
-
- assertTrue(credentialProvider.authenticate("Jeannie","wyatt"));
-
+ assertTrue(credentialProvider.authenticate("Jeannie", "wyatt"));
}
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org