[jboss-cvs] JBoss Messaging SVN: r4593 - in trunk: src/config and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jun 26 06:03:41 EDT 2008
Author: timfox
Date: 2008-06-26 06:03:40 -0400 (Thu, 26 Jun 2008)
New Revision: 4593
Added:
trunk/src/main/org/jboss/messaging/core/security/impl/JBossASSecurityManager.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/deployers/impl/BasicSecurityDeployerTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/security/impl/JBossASSecurityManagerTest.java
Removed:
trunk/src/main/org/jboss/messaging/core/security/impl/JAASSecurityManager.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/deployers/impl/SecurityManagerDeployerTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/security/impl/JAASSecurityManagerTest.java
Modified:
trunk/docs/userguide/en/modules/configuration.xml
trunk/src/config/jbm-beans.xml
trunk/src/config/jbm-standalone-beans.xml
trunk/src/main/org/jboss/messaging/core/server/impl/QueueImpl.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/deployers/impl/SecurityDeployerTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/JournalImplTestUnit.java
Log:
More test stuff
Modified: trunk/docs/userguide/en/modules/configuration.xml
===================================================================
--- trunk/docs/userguide/en/modules/configuration.xml 2008-06-26 05:57:43 UTC (rev 4592)
+++ trunk/docs/userguide/en/modules/configuration.xml 2008-06-26 10:03:40 UTC (rev 4593)
@@ -793,7 +793,7 @@
<programlisting>
<![CDATA[
<bean name="JBMSecurityManager"
- class="org.jboss.messaging.core.security.impl.JAASSecurityManager"/>
+ class="org.jboss.messaging.core.security.impl.JBossASSecurityManager"/>
]]>
</programlisting>
<para>To replace the Security Manager implement the following interface:</para>
Modified: trunk/src/config/jbm-beans.xml
===================================================================
--- trunk/src/config/jbm-beans.xml 2008-06-26 05:57:43 UTC (rev 4592)
+++ trunk/src/config/jbm-beans.xml 2008-06-26 10:03:40 UTC (rev 4593)
@@ -11,7 +11,7 @@
</constructor>
</bean>
- <bean name="JBMSecurityManager" class="org.jboss.messaging.core.security.impl.JAASSecurityManager"/>
+ <bean name="JBMSecurityManager" class="org.jboss.messaging.core.security.impl.JBossASSecurityManager"/>
<!-- <bean name="JBMSecurityManager" class="org.jboss.messaging.core.security.impl.JBMSecurityManagerImpl">
<constructor>
Modified: trunk/src/config/jbm-standalone-beans.xml
===================================================================
--- trunk/src/config/jbm-standalone-beans.xml 2008-06-26 05:57:43 UTC (rev 4592)
+++ trunk/src/config/jbm-standalone-beans.xml 2008-06-26 10:03:40 UTC (rev 4593)
@@ -27,7 +27,7 @@
<bean name="Configuration" class="org.jboss.messaging.core.config.impl.FileConfiguration"/>
- <!--<bean name="JBMSecurityManager" class="org.jboss.messaging.core.security.impl.JAASSecurityManager"/>-->
+ <!--<bean name="JBMSecurityManager" class="org.jboss.messaging.core.security.impl.JBossASSecurityManager"/>-->
<bean name="JBMSecurityManager" class="org.jboss.messaging.core.security.impl.JBMSecurityManagerImpl">
<constructor>
Deleted: trunk/src/main/org/jboss/messaging/core/security/impl/JAASSecurityManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/security/impl/JAASSecurityManager.java 2008-06-26 05:57:43 UTC (rev 4592)
+++ trunk/src/main/org/jboss/messaging/core/security/impl/JAASSecurityManager.java 2008-06-26 10:03:40 UTC (rev 4593)
@@ -1,161 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * 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.messaging.core.security.impl;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.naming.InitialContext;
-import javax.security.auth.Subject;
-
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.security.CheckType;
-import org.jboss.messaging.core.security.JBMSecurityManager;
-import org.jboss.messaging.core.security.Role;
-import org.jboss.security.AuthenticationManager;
-import org.jboss.security.RealmMapping;
-import org.jboss.security.SimplePrincipal;
-
-/**
- * This implementation delegates to the a real JAAS Authentication Manager and will typically be used within an appserver
- * and it up via jndi.
- *
- * @author <a href="ataylor at redhat.com">Andy Taylor</a>
- */
-public class JAASSecurityManager implements JBMSecurityManager
-{
- private static final Logger log = Logger.getLogger(JAASSecurityManager.class);
-
- // Static --------------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private boolean trace = log.isTraceEnabled();
-
- /**
- * the realmmapping
- */
- private RealmMapping realmMapping;
-
- /**
- * the JAAS Authentication Manager
- */
- private AuthenticationManager authenticationManager;
-
- /**
- * The JNDI name of the AuthenticationManager(and RealmMapping since they are the same object).
- */
- private String securityDomainName = "java:/jaas/messaging";
-
- public boolean validateUser(final String user, final String password)
- {
- SimplePrincipal principal = new SimplePrincipal(user);
-
- char[] passwordChars = null;
-
- if (password != null)
- {
- passwordChars = password.toCharArray();
- }
-
- Subject subject = new Subject();
-
- return authenticationManager.isValid(principal, passwordChars, subject);
- }
-
- public boolean validateUserAndRole(final String user, final String password, final Set<Role> roles, final CheckType checkType)
- {
- SimplePrincipal principal = user == null ? null : new SimplePrincipal(user);
-
- char[] passwordChars = null;
-
- if (password != null)
- {
- passwordChars = password.toCharArray();
- }
-
- Subject subject = new Subject();
-
- boolean authenticated = authenticationManager.isValid(principal, passwordChars, subject);
- // Authenticate. Successful authentication will place a new SubjectContext on thread local,
- // which will be used in the authorization process. However, we need to make sure we clean up
- // thread local immediately after we used the information, otherwise some other people
- // security my be screwed up, on account of thread local security stack being corrupted.
- if (authenticated)
- {
- SecurityActions.pushSubjectContext(principal, passwordChars, subject);
- Set<SimplePrincipal> rolePrincipals = getRolePrincipals(checkType, roles);
-
- authenticated = realmMapping.doesUserHaveRole(principal, rolePrincipals);
-
- if (trace)
- {
- log.trace("user " + user + (authenticated ? " is " : " is NOT ") + "authorized");
- }
- SecurityActions.popSubjectContext();
- }
- return authenticated;
- }
-
- private Set<SimplePrincipal> getRolePrincipals(final CheckType checkType, final Set<Role> roles)
- {
- Set<SimplePrincipal> principals = new HashSet<SimplePrincipal>();
- for (Role role : roles)
- {
- if ((checkType.equals(CheckType.CREATE) && role.isCheckType(CheckType.CREATE)) ||
- (checkType.equals(CheckType.WRITE) && role.isCheckType(CheckType.WRITE)) ||
- (checkType.equals(CheckType.READ) && role.isCheckType(CheckType.READ)))
- {
- principals.add(new SimplePrincipal(role.getName()));
- }
- }
- return principals;
- }
-
- public void setRealmMapping(final RealmMapping realmMapping)
- {
- this.realmMapping = realmMapping;
- }
-
- public void setAuthenticationManager(final AuthenticationManager authenticationManager)
- {
- this.authenticationManager = authenticationManager;
- }
-
- /**
- * lifecycle method, needs to be called
- *
- * @throws Exception
- */
- public void start() throws Exception
- {
- InitialContext ic = new InitialContext();
- authenticationManager = (AuthenticationManager) ic.lookup(securityDomainName);
- realmMapping = (RealmMapping) authenticationManager;
- }
-
- public void setSecurityDomainName(String securityDomainName)
- {
- this.securityDomainName = securityDomainName;
- }
-}
Copied: trunk/src/main/org/jboss/messaging/core/security/impl/JBossASSecurityManager.java (from rev 4577, trunk/src/main/org/jboss/messaging/core/security/impl/JAASSecurityManager.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/security/impl/JBossASSecurityManager.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/security/impl/JBossASSecurityManager.java 2008-06-26 10:03:40 UTC (rev 4593)
@@ -0,0 +1,186 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * 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.messaging.core.security.impl;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.naming.InitialContext;
+import javax.security.auth.Subject;
+
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.security.CheckType;
+import org.jboss.messaging.core.security.JBMSecurityManager;
+import org.jboss.messaging.core.security.Role;
+import org.jboss.messaging.core.server.MessagingComponent;
+import org.jboss.security.AuthenticationManager;
+import org.jboss.security.RealmMapping;
+import org.jboss.security.SimplePrincipal;
+
+/**
+ * This implementation delegates to the JBoss AS security interfaces (which in turn use JAAS)
+ * It can be used when running JBM in JBoss AS
+ *
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ * @author <a href="tim.fox at jboss.com">Tim Fox</a>
+ */
+public class JBossASSecurityManager implements JBMSecurityManager, MessagingComponent
+{
+ private static final Logger log = Logger.getLogger(JBossASSecurityManager.class);
+
+ // Static --------------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private boolean trace = log.isTraceEnabled();
+
+ /**
+ * the realmmapping
+ */
+ private RealmMapping realmMapping;
+
+ /**
+ * the JAAS Authentication Manager
+ */
+ private AuthenticationManager authenticationManager;
+
+ /**
+ * The JNDI name of the AuthenticationManager(and RealmMapping since they are the same object).
+ */
+ private String securityDomainName = "java:/jaas/messaging";
+
+ private boolean started;
+
+ public boolean validateUser(final String user, final String password)
+ {
+ SimplePrincipal principal = new SimplePrincipal(user);
+
+ char[] passwordChars = null;
+
+ if (password != null)
+ {
+ passwordChars = password.toCharArray();
+ }
+
+ Subject subject = new Subject();
+
+ return authenticationManager.isValid(principal, passwordChars, subject);
+ }
+
+ public boolean validateUserAndRole(final String user, final String password, final Set<Role> roles, final CheckType checkType)
+ {
+ SimplePrincipal principal = user == null ? null : new SimplePrincipal(user);
+
+ char[] passwordChars = null;
+
+ if (password != null)
+ {
+ passwordChars = password.toCharArray();
+ }
+
+ Subject subject = new Subject();
+
+ boolean authenticated = authenticationManager.isValid(principal, passwordChars, subject);
+ // Authenticate. Successful authentication will place a new SubjectContext on thread local,
+ // which will be used in the authorization process. However, we need to make sure we clean up
+ // thread local immediately after we used the information, otherwise some other people
+ // security my be screwed up, on account of thread local security stack being corrupted.
+ if (authenticated)
+ {
+ SecurityActions.pushSubjectContext(principal, passwordChars, subject);
+ Set<SimplePrincipal> rolePrincipals = getRolePrincipals(checkType, roles);
+
+ authenticated = realmMapping.doesUserHaveRole(principal, rolePrincipals);
+
+ if (trace)
+ {
+ log.trace("user " + user + (authenticated ? " is " : " is NOT ") + "authorized");
+ }
+ SecurityActions.popSubjectContext();
+ }
+ return authenticated;
+ }
+
+ private Set<SimplePrincipal> getRolePrincipals(final CheckType checkType, final Set<Role> roles)
+ {
+ Set<SimplePrincipal> principals = new HashSet<SimplePrincipal>();
+ for (Role role : roles)
+ {
+ if ((checkType.equals(CheckType.CREATE) && role.isCheckType(CheckType.CREATE)) ||
+ (checkType.equals(CheckType.WRITE) && role.isCheckType(CheckType.WRITE)) ||
+ (checkType.equals(CheckType.READ) && role.isCheckType(CheckType.READ)))
+ {
+ principals.add(new SimplePrincipal(role.getName()));
+ }
+ }
+ return principals;
+ }
+
+ public void setRealmMapping(final RealmMapping realmMapping)
+ {
+ this.realmMapping = realmMapping;
+ }
+
+ public void setAuthenticationManager(final AuthenticationManager authenticationManager)
+ {
+ this.authenticationManager = authenticationManager;
+ }
+
+ /**
+ * lifecycle method, needs to be called
+ *
+ * @throws Exception
+ */
+ public synchronized void start() throws Exception
+ {
+ if (started)
+ {
+ return;
+ }
+
+ InitialContext ic = new InitialContext();
+ authenticationManager = (AuthenticationManager) ic.lookup(securityDomainName);
+ realmMapping = (RealmMapping) authenticationManager;
+
+ started = true;
+ }
+
+ public synchronized void stop()
+ {
+ if (!started)
+ {
+ return;
+ }
+ started = false;
+ }
+
+ public synchronized boolean isStarted()
+ {
+ return started;
+ }
+
+ public void setSecurityDomainName(String securityDomainName)
+ {
+ this.securityDomainName = securityDomainName;
+ }
+}
Modified: trunk/src/main/org/jboss/messaging/core/server/impl/QueueImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/QueueImpl.java 2008-06-26 05:57:43 UTC (rev 4592)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/QueueImpl.java 2008-06-26 10:03:40 UTC (rev 4593)
@@ -93,8 +93,6 @@
private int pos;
- //private boolean locked;
-
private AtomicInteger sizeBytes = new AtomicInteger(0);
private AtomicInteger messagesAdded = new AtomicInteger(0);
@@ -158,21 +156,20 @@
public HandleStatus addLast(final MessageReference ref)
{
-
- lock.lock();
+ lock.lock();
try
{
return add(ref, false);
}
finally
{
- lock.unlock();
+ lock.unlock();
}
}
public HandleStatus addFirst(final MessageReference ref)
{
- lock.lock();
+ lock.lock();
try
{
@@ -180,8 +177,7 @@
}
finally
{
- lock.unlock();
-
+ lock.unlock();
}
}
@@ -486,18 +482,14 @@
tx.commit();
}
- public synchronized void lock()
+ public void lock()
{
lock.lock();
-
- //locked = true;
}
- public synchronized void unlock()
+ public void unlock()
{
lock.unlock();
-
- //locked = false;
}
// Public
Copied: trunk/tests/src/org/jboss/messaging/tests/unit/core/deployers/impl/BasicSecurityDeployerTest.java (from rev 4577, trunk/tests/src/org/jboss/messaging/tests/unit/core/deployers/impl/SecurityManagerDeployerTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/deployers/impl/BasicSecurityDeployerTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/deployers/impl/BasicSecurityDeployerTest.java 2008-06-26 10:03:40 UTC (rev 4593)
@@ -0,0 +1,144 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * 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.messaging.tests.unit.core.deployers.impl;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import org.jboss.messaging.core.deployers.DeploymentManager;
+import org.jboss.messaging.core.deployers.impl.BasicSecurityDeployer;
+import org.jboss.messaging.core.security.JBMUpdateableSecurityManager;
+import org.jboss.messaging.util.XMLUtil;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * tests BasicSecurityDeployer
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class BasicSecurityDeployerTest extends TestCase
+{
+ private BasicSecurityDeployer deployer;
+
+ private static final String simpleSecurityXml = "<deployment>\n" +
+ "</deployment>";
+
+ private static final String singleUserXml = "<deployment>\n" +
+ " <user name=\"guest\" password=\"guest\">\n" +
+ " <role name=\"guest\"/>\n" +
+ " </user>\n" +
+ "</deployment>";
+
+ private static final String multipleUserXml = "<deployment>\n" +
+ " <user name=\"guest\" password=\"guest\">\n" +
+ " <role name=\"guest\"/>\n" +
+ " <role name=\"foo\"/>\n" +
+ " </user>\n" +
+ " <user name=\"anotherguest\" password=\"anotherguest\">\n" +
+ " <role name=\"anotherguest\"/>\n" +
+ " <role name=\"foo\"/>\n" +
+ " <role name=\"bar\"/>\n" +
+ " </user>\n" +
+ "</deployment>";
+
+ protected void setUp() throws Exception
+ {
+ DeploymentManager deploymentManager = EasyMock.createNiceMock(DeploymentManager.class);
+ deployer = new BasicSecurityDeployer(deploymentManager);
+ }
+
+ protected void tearDown() throws Exception
+ {
+ deployer = null;
+ }
+
+ private void deploy(String xml) throws Exception
+ {
+ NodeList children = XMLUtil.stringToElement(xml).getChildNodes();
+ for (int i = 0; i < children.getLength(); i++)
+ {
+ Node node = children.item(i);
+ if(node.getNodeName().equals("user"))
+ {
+ deployer.deploy(node);
+ }
+ }
+ }
+
+ private void undeploy(String xml) throws Exception
+ {
+ NodeList children = XMLUtil.stringToElement(xml).getChildNodes();
+ for (int i = 0; i < children.getLength(); i++)
+ {
+ Node node = children.item(i);
+ if(node.getNodeName().equals("user"))
+ {
+ deployer.undeploy(node);
+ }
+ }
+ }
+
+ public void testSimpleDefaultSecurity() throws Exception
+ {
+ JBMUpdateableSecurityManager securityManager = EasyMock.createStrictMock(JBMUpdateableSecurityManager.class);
+ deployer.setJbmSecurityManager(securityManager);
+ EasyMock.replay(securityManager);
+ deploy(simpleSecurityXml);
+ }
+
+ public void testSingleUserDeploySecurity() throws Exception
+ {
+ JBMUpdateableSecurityManager securityManager = EasyMock.createStrictMock(JBMUpdateableSecurityManager.class);
+ deployer.setJbmSecurityManager(securityManager);
+ securityManager.addUser("guest", "guest");
+ securityManager.addRole("guest", "guest");
+ EasyMock.replay(securityManager);
+ deploy(singleUserXml);
+ }
+
+ public void testMultipleUserDeploySecurity() throws Exception
+ {
+ JBMUpdateableSecurityManager securityManager = EasyMock.createStrictMock(JBMUpdateableSecurityManager.class);
+ deployer.setJbmSecurityManager(securityManager);
+ securityManager.addUser("guest", "guest");
+ securityManager.addRole("guest", "guest");
+ securityManager.addRole("guest", "foo");
+ securityManager.addUser("anotherguest", "anotherguest");
+ securityManager.addRole("anotherguest", "anotherguest");
+ securityManager.addRole("anotherguest", "foo");
+ securityManager.addRole("anotherguest", "bar");
+
+ EasyMock.replay(securityManager);
+ deploy(multipleUserXml);
+ }
+
+ public void testUndeploy() throws Exception
+ {
+ JBMUpdateableSecurityManager securityManager = EasyMock.createStrictMock(JBMUpdateableSecurityManager.class);
+ deployer.setJbmSecurityManager(securityManager);
+ securityManager.removeUser("guest");
+ securityManager.removeUser("anotherguest");
+
+ EasyMock.replay(securityManager);
+ undeploy(multipleUserXml);
+ }
+}
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/deployers/impl/SecurityDeployerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/deployers/impl/SecurityDeployerTest.java 2008-06-26 05:57:43 UTC (rev 4592)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/deployers/impl/SecurityDeployerTest.java 2008-06-26 10:03:40 UTC (rev 4593)
@@ -67,8 +67,6 @@
public void testSingle() throws Exception
{
-
-
Element e = XMLUtil.stringToElement(conf);
Role role = new Role("durpublisher", true, true, true);
Role role2 = new Role("guest", true, true, false);
@@ -79,8 +77,7 @@
roles.add(role3);
repository.addMatch("topics.testTopic", roles);
EasyMock.replay(repository);
- deployer.deploy(e);
-
+ deployer.deploy(e);
}
public void testMultiple() throws Exception
@@ -97,8 +94,8 @@
EasyMock.replay(repository);
deployer.deploy(XMLUtil.stringToElement(conf));
deployer.deploy(XMLUtil.stringToElement(conf2));
-
}
+
public void testNoRolesAdded() throws Exception
{
HashSet<Role> roles = new HashSet<Role>();
Deleted: trunk/tests/src/org/jboss/messaging/tests/unit/core/deployers/impl/SecurityManagerDeployerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/deployers/impl/SecurityManagerDeployerTest.java 2008-06-26 05:57:43 UTC (rev 4592)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/deployers/impl/SecurityManagerDeployerTest.java 2008-06-26 10:03:40 UTC (rev 4593)
@@ -1,143 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * 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.messaging.tests.unit.core.deployers.impl;
-
-import junit.framework.TestCase;
-import org.easymock.EasyMock;
-import org.jboss.messaging.core.deployers.DeploymentManager;
-import org.jboss.messaging.core.deployers.impl.BasicSecurityDeployer;
-import org.jboss.messaging.core.security.JBMUpdateableSecurityManager;
-import org.jboss.messaging.util.XMLUtil;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-/**
- * tests BasicSecurityDeployer
- * @author <a href="ataylor at redhat.com">Andy Taylor</a>
- */
-public class SecurityManagerDeployerTest extends TestCase
-{
- BasicSecurityDeployer deployer;
- String simpleSecurityXml = "<deployment>\n" +
- "</deployment>";
-
- String singleUserXml = "<deployment>\n" +
- " <user name=\"guest\" password=\"guest\">\n" +
- " <role name=\"guest\"/>\n" +
- " </user>\n" +
- "</deployment>";
-
- String multipleUserXml = "<deployment>\n" +
- " <user name=\"guest\" password=\"guest\">\n" +
- " <role name=\"guest\"/>\n" +
- " <role name=\"foo\"/>\n" +
- " </user>\n" +
- " <user name=\"anotherguest\" password=\"anotherguest\">\n" +
- " <role name=\"anotherguest\"/>\n" +
- " <role name=\"foo\"/>\n" +
- " <role name=\"bar\"/>\n" +
- " </user>\n" +
- "</deployment>";
-
- protected void setUp() throws Exception
- {
- DeploymentManager deploymentManager = EasyMock.createNiceMock(DeploymentManager.class);
- deployer = new BasicSecurityDeployer(deploymentManager);
- }
-
- protected void tearDown() throws Exception
- {
- deployer = null;
- }
-
- private void deploy(String xml) throws Exception
- {
- NodeList children = XMLUtil.stringToElement(xml).getChildNodes();
- for (int i = 0; i < children.getLength(); i++)
- {
- Node node = children.item(i);
- if(node.getNodeName().equals("user"))
- {
- deployer.deploy(node);
- }
- }
- }
-
- private void undeploy(String xml) throws Exception
- {
- NodeList children = XMLUtil.stringToElement(xml).getChildNodes();
- for (int i = 0; i < children.getLength(); i++)
- {
- Node node = children.item(i);
- if(node.getNodeName().equals("user"))
- {
- deployer.undeploy(node);
- }
- }
- }
-
- public void testSimpleDefaultSecurity() throws Exception
- {
- JBMUpdateableSecurityManager securityManager = EasyMock.createStrictMock(JBMUpdateableSecurityManager.class);
- deployer.setJbmSecurityManager(securityManager);
- EasyMock.replay(securityManager);
- deploy(simpleSecurityXml);
- }
-
- public void testSingleUserDeploySecurity() throws Exception
- {
- JBMUpdateableSecurityManager securityManager = EasyMock.createStrictMock(JBMUpdateableSecurityManager.class);
- deployer.setJbmSecurityManager(securityManager);
- securityManager.addUser("guest", "guest");
- securityManager.addRole("guest", "guest");
- EasyMock.replay(securityManager);
- deploy(singleUserXml);
- }
-
- public void testMultipleUserDeploySecurity() throws Exception
- {
- JBMUpdateableSecurityManager securityManager = EasyMock.createStrictMock(JBMUpdateableSecurityManager.class);
- deployer.setJbmSecurityManager(securityManager);
- securityManager.addUser("guest", "guest");
- securityManager.addRole("guest", "guest");
- securityManager.addRole("guest", "foo");
- securityManager.addUser("anotherguest", "anotherguest");
- securityManager.addRole("anotherguest", "anotherguest");
- securityManager.addRole("anotherguest", "foo");
- securityManager.addRole("anotherguest", "bar");
-
- EasyMock.replay(securityManager);
- deploy(multipleUserXml);
- }
-
- public void testUndeploy() throws Exception
- {
- JBMUpdateableSecurityManager securityManager = EasyMock.createStrictMock(JBMUpdateableSecurityManager.class);
- deployer.setJbmSecurityManager(securityManager);
- securityManager.removeUser("guest");
- securityManager.removeUser("anotherguest");
-
- EasyMock.replay(securityManager);
- undeploy(multipleUserXml);
- }
-}
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/JournalImplTestUnit.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/JournalImplTestUnit.java 2008-06-26 05:57:43 UTC (rev 4592)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/JournalImplTestUnit.java 2008-06-26 10:03:40 UTC (rev 4593)
@@ -381,15 +381,6 @@
* */
private int calculateNumberOfFiles(int fileSize, int alignment, int ... record) throws Exception
{
-
-
-// log.info("Processing calculateNumberOfFiles(" + fileSize + ", " + alignment);
-// for (int recordN: record)
-// {
-// System.out.print(", " + recordN);
-// }
-// System.out.println(");");
-
int headerSize = calculateRecordSize(JournalImpl.SIZE_HEADER, alignment);
int currentPosition = headerSize;
int totalFiles = 0;
@@ -399,8 +390,6 @@
int numberOfRecords = record[i];
int recordSize = calculateRecordSize(record[i+1], alignment);
-// log.info(" numberOfRecords = " + numberOfRecords + " recordSize=" + recordSize);
-
while (numberOfRecords>0)
{
int recordsFit = (fileSize - currentPosition) / recordSize;
@@ -408,25 +397,20 @@
{
currentPosition = currentPosition + numberOfRecords*recordSize;
numberOfRecords = 0;
-// log.info(" Adding " + numberOfRecords + " records of size " + recordSize + " numberOfFiles = " + totalFiles + " Position=" + currentPosition);
}
else if (recordsFit > 0)
{
currentPosition = currentPosition + recordsFit*recordSize;
numberOfRecords -= recordsFit;
-// log.info(" Adding " + recordsFit + " (fitting) of size " + recordSize + " numberOfFiles = " + totalFiles + " Position = " + currentPosition);
}
else
{
totalFiles++;
currentPosition = headerSize;
-// log.info(" Exploded... totalFiles=" + totalFiles);
}
}
}
- // System.out.println(" Returning " + totalFiles);
-
return totalFiles;
}
@@ -2768,25 +2752,20 @@
commit(1);
deleteTx(2, 1, 2, 3, 4, 5, 6);
commit(2);
-
-
-
-// // Just to make sure the commit won't be released. The commit will be on the same file as addTx(3);
-addTx(3, 11);
-addTx(4, 31);
-commit(3);
-log.info("Debug on Journal before stopJournal - \n" + debugJournal());
+ // Just to make sure the commit won't be released. The commit will be on the same file as addTx(3);
+ addTx(3, 11);
+ addTx(4, 31);
+ commit(3);
-stopJournal();
-createJournal();
-startJournal();
-loadAndCheck();
+ log.info("Debug on Journal before stopJournal - \n" + debugJournal());
-
+ stopJournal();
+ createJournal();
+ startJournal();
+ loadAndCheck();
}
-
+
protected abstract int getAlignment();
-
-
+
}
Deleted: trunk/tests/src/org/jboss/messaging/tests/unit/core/security/impl/JAASSecurityManagerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/security/impl/JAASSecurityManagerTest.java 2008-06-26 05:57:43 UTC (rev 4592)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/security/impl/JAASSecurityManagerTest.java 2008-06-26 10:03:40 UTC (rev 4593)
@@ -1,150 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * 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.messaging.tests.unit.core.security.impl;
-
-import junit.framework.TestCase;
-import org.easymock.EasyMock;
-import org.easymock.IArgumentMatcher;
-import org.jboss.messaging.core.security.CheckType;
-import org.jboss.messaging.core.security.Role;
-import org.jboss.messaging.core.security.impl.JAASSecurityManager;
-import org.jboss.security.AuthenticationManager;
-import org.jboss.security.RealmMapping;
-import org.jboss.security.SimplePrincipal;
-
-import javax.security.auth.Subject;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * tests the JAASSecurityManager
- *
- * @author <a href="ataylor at redhat.com">Andy Taylor</a>
- */
-public class JAASSecurityManagerTest extends TestCase
-{
- JAASSecurityManager securityManager;
-
- protected void setUp() throws Exception
- {
- securityManager = new JAASSecurityManager();
- }
-
- protected void tearDown() throws Exception
- {
- securityManager = null;
- }
-
- public void testValidatingUser()
- {
- AuthenticationManager authenticationManager = EasyMock.createStrictMock(AuthenticationManager.class);
- securityManager.setAuthenticationManager(authenticationManager);
- SimplePrincipal principal = new SimplePrincipal("newuser1");
- char[] passwordChars = "newpassword1".toCharArray();
- Subject subject = new Subject();
- EasyMock.expect(authenticationManager.isValid(principal(principal), EasyMock.aryEq(passwordChars), subject(subject))).andReturn(true);
- EasyMock.replay(authenticationManager);
-
- securityManager.validateUser("newuser1", "newpassword1");
- }
-
- public void testValidatingUserAndRole()
- {
- AuthenticationManager authenticationManager = EasyMock.createStrictMock(AuthenticationManager.class);
- securityManager.setAuthenticationManager(authenticationManager);
- RealmMapping realmMapping = EasyMock.createStrictMock(RealmMapping.class);
- securityManager.setRealmMapping(realmMapping);
- SimplePrincipal principal = new SimplePrincipal("newuser1");
- char[] passwordChars = "newpassword1".toCharArray();
- Subject subject = new Subject();
- EasyMock.expect(authenticationManager.isValid(principal(principal), EasyMock.aryEq(passwordChars), subject(subject))).andReturn(true);
- EasyMock.replay(authenticationManager);
- EasyMock.expect(realmMapping.doesUserHaveRole(principal(principal), EasyMock.isA(Set.class))).andReturn(true);
- EasyMock.replay(realmMapping);
- HashSet<Role> roleHashSet = new HashSet<Role>();
- roleHashSet.add(new Role("newuser1", true, true, true));
- securityManager.validateUserAndRole("newuser1", "newpassword1", roleHashSet, CheckType.CREATE);
- }
-
- public static SimplePrincipal principal(SimplePrincipal principal)
- {
- EasyMock.reportMatcher(new SimplePrincipalMatcher(principal));
- return principal;
- }
-
- public static Subject subject(Subject subject)
- {
- EasyMock.reportMatcher(new SubjectMatcher(subject));
- return subject;
- }
-
- static class SimplePrincipalMatcher implements IArgumentMatcher
- {
- SimplePrincipal principal;
-
- public SimplePrincipalMatcher(SimplePrincipal principal)
- {
- this.principal = principal;
- }
-
- public boolean matches(Object o)
- {
- if (o instanceof SimplePrincipal)
- {
- SimplePrincipal that = (SimplePrincipal) o;
- return that.getName().equals(principal.getName());
- }
- return false;
- }
-
- public void appendTo(StringBuffer stringBuffer)
- {
- stringBuffer.append("Invalid Principal created");
- }
- }
-
- static class SubjectMatcher implements IArgumentMatcher
- {
- Subject subject;
-
- public SubjectMatcher(Subject subject)
- {
- this.subject = subject;
- }
-
- public boolean matches(Object o)
- {
- if (o instanceof Subject)
- {
- Subject that = (Subject) o;
- return true;
- }
- return false;
- }
-
- public void appendTo(StringBuffer stringBuffer)
- {
- stringBuffer.append("Invalid Subject created");
- }
- }
-}
Copied: trunk/tests/src/org/jboss/messaging/tests/unit/core/security/impl/JBossASSecurityManagerTest.java (from rev 4577, trunk/tests/src/org/jboss/messaging/tests/unit/core/security/impl/JAASSecurityManagerTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/security/impl/JBossASSecurityManagerTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/security/impl/JBossASSecurityManagerTest.java 2008-06-26 10:03:40 UTC (rev 4593)
@@ -0,0 +1,156 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * 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.messaging.tests.unit.core.security.impl;
+
+import java.security.Principal;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.naming.InitialContext;
+import javax.security.auth.Subject;
+import javax.security.auth.message.MessageInfo;
+
+import junit.framework.TestCase;
+
+import org.easymock.EasyMock;
+import org.easymock.IArgumentMatcher;
+import org.jboss.messaging.core.security.CheckType;
+import org.jboss.messaging.core.security.Role;
+import org.jboss.messaging.core.security.impl.JBossASSecurityManager;
+import org.jboss.security.AuthenticationManager;
+import org.jboss.security.RealmMapping;
+import org.jboss.security.SimplePrincipal;
+
+/**
+ * tests the JBossASSecurityManager
+ *
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class JBossASSecurityManagerTest extends TestCase
+{
+ private JBossASSecurityManager securityManager;
+
+ protected void setUp() throws Exception
+ {
+ securityManager = new JBossASSecurityManager();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ securityManager = null;
+ }
+
+ public void testValidatingUser()
+ {
+ AuthenticationManager authenticationManager = EasyMock.createStrictMock(AuthenticationManager.class);
+ securityManager.setAuthenticationManager(authenticationManager);
+ SimplePrincipal principal = new SimplePrincipal("newuser1");
+ char[] passwordChars = "newpassword1".toCharArray();
+ Subject subject = new Subject();
+ EasyMock.expect(authenticationManager.isValid(principal(principal), EasyMock.aryEq(passwordChars), subject(subject))).andReturn(true);
+ EasyMock.replay(authenticationManager);
+
+ securityManager.validateUser("newuser1", "newpassword1");
+ }
+
+ public void testValidatingUserAndRole()
+ {
+ AuthenticationManager authenticationManager = EasyMock.createStrictMock(AuthenticationManager.class);
+ securityManager.setAuthenticationManager(authenticationManager);
+ RealmMapping realmMapping = EasyMock.createStrictMock(RealmMapping.class);
+ securityManager.setRealmMapping(realmMapping);
+ SimplePrincipal principal = new SimplePrincipal("newuser1");
+ char[] passwordChars = "newpassword1".toCharArray();
+ Subject subject = new Subject();
+ EasyMock.expect(authenticationManager.isValid(principal(principal), EasyMock.aryEq(passwordChars), subject(subject))).andReturn(true);
+ EasyMock.replay(authenticationManager);
+ EasyMock.expect(realmMapping.doesUserHaveRole(principal(principal), EasyMock.isA(Set.class))).andReturn(true);
+ EasyMock.replay(realmMapping);
+ HashSet<Role> roleHashSet = new HashSet<Role>();
+ roleHashSet.add(new Role("newuser1", true, true, true));
+ securityManager.validateUserAndRole("newuser1", "newpassword1", roleHashSet, CheckType.CREATE);
+ }
+
+ public static SimplePrincipal principal(SimplePrincipal principal)
+ {
+ EasyMock.reportMatcher(new SimplePrincipalMatcher(principal));
+ return principal;
+ }
+
+ public static Subject subject(Subject subject)
+ {
+ EasyMock.reportMatcher(new SubjectMatcher(subject));
+ return subject;
+ }
+
+ private static class SimplePrincipalMatcher implements IArgumentMatcher
+ {
+ SimplePrincipal principal;
+
+ public SimplePrincipalMatcher(SimplePrincipal principal)
+ {
+ this.principal = principal;
+ }
+
+ public boolean matches(Object o)
+ {
+ if (o instanceof SimplePrincipal)
+ {
+ SimplePrincipal that = (SimplePrincipal) o;
+ return that.getName().equals(principal.getName());
+ }
+ return false;
+ }
+
+ public void appendTo(StringBuffer stringBuffer)
+ {
+ stringBuffer.append("Invalid Principal created");
+ }
+ }
+
+ private static class SubjectMatcher implements IArgumentMatcher
+ {
+ Subject subject;
+
+ public SubjectMatcher(Subject subject)
+ {
+ this.subject = subject;
+ }
+
+ public boolean matches(Object o)
+ {
+ if (o instanceof Subject)
+ {
+ Subject that = (Subject) o;
+ return true;
+ }
+ return false;
+ }
+
+ public void appendTo(StringBuffer stringBuffer)
+ {
+ stringBuffer.append("Invalid Subject created");
+ }
+ }
+}
More information about the jboss-cvs-commits
mailing list