[jboss-cvs] JBossAS SVN: r74851 - in trunk/testsuite/src: resources/security and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jun 19 14:46:09 EDT 2008
Author: sguilhen at redhat.com
Date: 2008-06-19 14:46:08 -0400 (Thu, 19 Jun 2008)
New Revision: 74851
Added:
trunk/testsuite/src/resources/security/jaassecdomain-tests-beans.xml
Modified:
trunk/testsuite/src/main/org/jboss/test/security/test/JaasSecurityDomainUnitTestCase.java
Log:
JBAS-5356: Enhanced the JaasSecurityDomainUnitTestCase to test security domains deployed as microcontainer beans.
Modified: trunk/testsuite/src/main/org/jboss/test/security/test/JaasSecurityDomainUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/security/test/JaasSecurityDomainUnitTestCase.java 2008-06-19 18:31:46 UTC (rev 74850)
+++ trunk/testsuite/src/main/org/jboss/test/security/test/JaasSecurityDomainUnitTestCase.java 2008-06-19 18:46:08 UTC (rev 74851)
@@ -70,6 +70,15 @@
cipher.init(Cipher.DECRYPT_MODE, cipherKey, cipherSpec);
byte[] decode = cipher.doFinal(encode);
assertTrue("secret == decode", Arrays.equals(secret, decode));
+
+ // repeat the test, this time invoking the sec domain that was configured as a microcontainer bean.
+ ObjectName exportedName = new ObjectName("jboss.security:service=JaasSecurityDomain,domain=testTmpFilePassword2");
+ // invoke the encode operation using the bean's exported MBean interface.
+ byte[] encode2 = (byte[]) super.invoke(exportedName, "encode", args, sig);
+ assertTrue("secret != encode2", Arrays.equals(secret, encode2) == false);
+
+ byte[] decode2 = cipher.doFinal(encode2);
+ assertTrue("secret == decode2", Arrays.equals(secret, decode2));
}
public void testFilePassword() throws Exception
@@ -89,6 +98,15 @@
cipher.init(Cipher.DECRYPT_MODE, cipherKey, cipherSpec);
byte[] decode = cipher.doFinal(encode);
assertTrue("secret == decode", Arrays.equals(secret, decode));
+
+ // repeat the test, this time invoking the sec domain that was configured as a microcontainer bean.
+ ObjectName exportedName = new ObjectName("jboss.security:service=JaasSecurityDomain,domain=testFilePassword2");
+ // invoke the encode operation using the bean's exported MBean interface.
+ byte[] encode2 = (byte[]) super.invoke(exportedName, "encode", args, sig);
+ assertTrue("secret != encode2", Arrays.equals(secret, encode2) == false);
+
+ byte[] decode2 = cipher.doFinal(encode2);
+ assertTrue("secret == decode2", Arrays.equals(secret, decode2));
}
public void testEncodeDecode() throws Exception
@@ -102,7 +120,19 @@
args = new Object[]{encode};
byte[] decode = (byte[]) super.invoke(name, "decode", args, sig);
assertTrue("secret == decode", Arrays.equals(secret, decode));
+
+ // repeat the test, this time invoking the sec domain that was configured as a microcontainer bean.
+ ObjectName exportedName = new ObjectName("jboss.security:service=JaasSecurityDomain,domain=encode-decode2");
+ // invoke the encode operation using the bean's exported MBean interface.
+ args = new Object[]{secret};
+ byte[] encode2 = (byte[]) super.invoke(exportedName, "encode", args, sig);
+ assertTrue("secret != encode2", Arrays.equals(secret, encode2) == false);
+ // invoke the decode operation using the bean's exported MBean interface.
+ args = new Object[]{encode2};
+ byte[] decode2 = (byte[]) super.invoke(exportedName, "decode", args, sig);
+ assertTrue("secret == decode2", Arrays.equals(secret, decode2));
}
+
public void testEncodeDecode64() throws Exception
{
ObjectName name = new ObjectName("jboss.security:service=JaasSecurityDomain,domain=encode-decode");
@@ -114,6 +144,16 @@
String[] sig2 = {"java.lang.String"};
byte[] decode = (byte[]) super.invoke(name, "decode64", args2, sig2);
assertTrue("secret == decode", Arrays.equals(secret, decode));
+
+ // repeat the test, this time invoking the sec domain that was configured as a microcontainer bean.
+ ObjectName exportedName = new ObjectName("jboss.security:service=JaasSecurityDomain,domain=encode-decode2");
+ // invoke the encode64 operation using the bean's exported MBean interface.
+ String encode2 = (String) super.invoke(exportedName, "encode64", args, sig);
+ // invoke the decode64 operation using the bean's exported MBean interface.
+ args = new Object[]{encode2};
+ sig = new String[]{"java.lang.String"};
+ byte[] decode2 = (byte[]) super.invoke(exportedName, "decode64", args, sig);
+ assertTrue("secret == decode2", Arrays.equals(secret, decode2));
}
/**
@@ -127,8 +167,9 @@
// Create an initializer for the test suite
TestSetup wrapper = new JBossTestSetup(suite)
{
+ File password;
File tmpPassword;
- File password;
+ File tmpPassword2;
protected void setUp() throws Exception
{
super.setUp();
@@ -138,7 +179,13 @@
writer.write("password1");
writer.close();
- // Create the opaque password file for testFilePassword
+ // Create a tmp password file for testTmpFilePassword2
+ tmpPassword2 = new File(System.getProperty("java.io.tmpdir"), "tmp.password2");
+ writer = new FileWriter(tmpPassword2);
+ writer.write("password1");
+ writer.close();
+
+ // Create the opaque password file for testFilePassword and testFilePassword2
password = new File(System.getProperty("java.io.tmpdir")+ "/tst.password");
String[] args2 = {
"12345678", // salt
@@ -149,16 +196,26 @@
FilePassword.main(args2);
getLog().info("Created password file: "+args2[2]);
- String url = getResourceURL("security/jaassecdomain-tests-service.xml");
- deploy(url);
+ // deploy the security domains defined as mbeans.
+ String url1 = getResourceURL("security/jaassecdomain-tests-service.xml");
+ deploy(url1);
+ // deploy the security domains defined as microcontainer beans.
+ String url2 = getResourceURL("security/jaassecdomain-tests-beans.xml");
+ deploy(url2);
flushAuthCache("unit-tests");
}
protected void tearDown() throws Exception
{
+ // delete the created test files.
+ password.delete();
tmpPassword.delete();
- password.delete();
- String url = getResourceURL("security/jaassecdomain-tests-service.xml");
- undeploy(url);
+ tmpPassword2.delete();
+ // undeploy the security domain mbeans.
+ String url1 = getResourceURL("security/jaassecdomain-tests-service.xml");
+ undeploy(url1);
+ // undeploy the security domain beans.
+ String url2 = getResourceURL("security/jaassecdomain-tests-beans.xml");
+ undeploy(url2);
super.tearDown();
}
Added: trunk/testsuite/src/resources/security/jaassecdomain-tests-beans.xml
===================================================================
--- trunk/testsuite/src/resources/security/jaassecdomain-tests-beans.xml (rev 0)
+++ trunk/testsuite/src/resources/security/jaassecdomain-tests-beans.xml 2008-06-19 18:46:08 UTC (rev 74851)
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- JaasSecurityDomain Microcontainer Beans -->
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <!-- Test a plaintext password -->
+ <bean name="JaasSecurityDomain:encode-decode2" class="org.jboss.security.plugins.JaasSecurityDomain">
+ <constructor>
+ <parameter>encode-decode2</parameter>
+ </constructor>
+ <property name="keyStorePass">unit-tests</property>
+ <property name="salt">abcdefgh</property>
+ <property name="iterationCount">13</property>
+ <!-- introduce a JMX annotation to export this bean as an MBean -->
+ <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.security:service=JaasSecurityDomain,domain=encode-decode2",exposedInterface=org.jboss.security.plugins.JaasSecurityDomainMBean.class)</annotation>
+ </bean>
+
+ <!-- Test a password obtained from a class using a tmp file -->
+ <bean name="JaasSecurityDomain:testTmpFilePassword2" class="org.jboss.security.plugins.JaasSecurityDomain">
+ <constructor>
+ <parameter>testTmpFilePassword2</parameter>
+ </constructor>
+ <property name="keyStorePass">{CLASS}org.jboss.security.plugins.TmpFilePassword:${java.io.tmpdir}/tmp.password2</property>
+ <property name="salt">abcdefgh</property>
+ <property name="iterationCount">13</property>
+ <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.security:service=JaasSecurityDomain,domain=testTmpFilePassword2",exposedInterface=org.jboss.security.plugins.JaasSecurityDomainMBean.class)</annotation>
+ </bean>
+
+ <!-- Test a password obtained from a class using an opaqued file -->
+ <bean name="JaasSecurityDomain:testFilePassword2" class="org.jboss.security.plugins.JaasSecurityDomain">
+ <constructor>
+ <parameter>testFilePassword2</parameter>
+ </constructor>
+ <property name="keyStorePass">{CLASS}org.jboss.security.plugins.FilePassword:${java.io.tmpdir}/tst.password</property>
+ <property name="salt">abcdefgh</property>
+ <property name="iterationCount">13</property>
+ <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.security:service=JaasSecurityDomain,domain=testFilePassword2",exposedInterface=org.jboss.security.plugins.JaasSecurityDomainMBean.class)</annotation>
+ </bean>
+
+</deployment>
More information about the jboss-cvs-commits
mailing list