[jboss-cvs] JBossAS SVN: r84650 - projects/security/security-jboss-sx/branches/Branch_2_0/jbosssx/src/test/java/org/jboss/test/authentication/jaas.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Feb 23 13:38:42 EST 2009
Author: sguilhen at redhat.com
Date: 2009-02-23 13:38:42 -0500 (Mon, 23 Feb 2009)
New Revision: 84650
Modified:
projects/security/security-jboss-sx/branches/Branch_2_0/jbosssx/src/test/java/org/jboss/test/authentication/jaas/LoginModulesUnitTestCase.java
Log:
SECURITY-370: merged changes from trunk
Modified: projects/security/security-jboss-sx/branches/Branch_2_0/jbosssx/src/test/java/org/jboss/test/authentication/jaas/LoginModulesUnitTestCase.java
===================================================================
--- projects/security/security-jboss-sx/branches/Branch_2_0/jbosssx/src/test/java/org/jboss/test/authentication/jaas/LoginModulesUnitTestCase.java 2009-02-23 18:37:30 UTC (rev 84649)
+++ projects/security/security-jboss-sx/branches/Branch_2_0/jbosssx/src/test/java/org/jboss/test/authentication/jaas/LoginModulesUnitTestCase.java 2009-02-23 18:38:42 UTC (rev 84650)
@@ -51,6 +51,7 @@
* @author Scott.Stark at jboss.org
* @version $Revision$
*/
+ at SuppressWarnings("unchecked")
public class LoginModulesUnitTestCase extends TestCase
{
@@ -61,11 +62,13 @@
*/
static class TestConfig extends Configuration
{
- public void refresh()
+ @Override
+ public void refresh()
{
}
- public AppConfigurationEntry[] getAppConfigurationEntry(String name)
+ @Override
+ public AppConfigurationEntry[] getAppConfigurationEntry(String name)
{
AppConfigurationEntry[] entry = null;
try
@@ -168,6 +171,39 @@
AppConfigurationEntry[] entry = {ace,anotherAce};
return entry;
}
+
+ /**
+ * <p>
+ * Obtains a configuration that uses a module that fails the validation phase. As the flag
+ * {@code throwValidateError} is not set to true, the validation exception should be available to the test method.
+ * </p>
+ *
+ * @return the test {@code AppConfigurationEntry}.
+ */
+ AppConfigurationEntry[] testValidateError()
+ {
+ AppConfigurationEntry entry = new AppConfigurationEntry(ValidateErrorLoginModule.class.getName(),
+ AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, new HashMap());
+ return new AppConfigurationEntry[]
+ {entry};
+ }
+
+ /**
+ * <p>
+ * Obtains a configuration that uses a module that fails the validation phase. As the flag
+ * {@code throwValidateError} is set to true, the validation exception should available to the test method.
+ * </p>
+ *
+ * @return the test {@code AppConfigurationEntry}.
+ */
+ AppConfigurationEntry[] testValidateErrorWithFlag()
+ {
+ HashMap options = new HashMap();
+ options.put("throwValidateError", "true");
+ AppConfigurationEntry entry = new AppConfigurationEntry(ValidateErrorLoginModule.class.getName(),
+ AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, options);
+ return new AppConfigurationEntry[]{entry};
+ }
AppConfigurationEntry[] other()
{
@@ -180,7 +216,8 @@
public static class TestLoginModule extends UsernamePasswordLoginModule
{
- protected Group[] getRoleSets()
+ @Override
+ protected Group[] getRoleSets()
{
SimpleGroup roles = new SimpleGroup("Roles");
Group[] roleSets = {roles};
@@ -190,7 +227,8 @@
}
/** This represents the 'true' password
*/
- protected String getUsersPassword()
+ @Override
+ protected String getUsersPassword()
{
return "secret";
}
@@ -200,7 +238,8 @@
{
/** This represents the 'true' password in its hashed form
*/
- protected String getUsersPassword()
+ @Override
+ protected String getUsersPassword()
{
MessageDigest md = null;
try
@@ -221,7 +260,8 @@
{
/** This represents the 'true' password in its hashed form
*/
- protected String getUsersPassword()
+ @Override
+ protected String getUsersPassword()
{
MessageDigest md = null;
try
@@ -241,13 +281,31 @@
return passwordHash;
}
}
+
+ /**
+ * <p>
+ * Login module used in the throwValidateError tests.
+ * </p>
+ */
+ public static class ValidateErrorLoginModule extends TestLoginModule
+ {
+
+ @Override
+ protected boolean validatePassword(String inputPassword, String expectedPassword)
+ {
+ // sets a validate error and returns false.
+ super.setValidateError(new Exception("Validate Exception"));
+ return false;
+ }
+ }
public LoginModulesUnitTestCase(String testName)
{
super(testName);
}
- protected void setUp() throws Exception
+ @Override
+protected void setUp() throws Exception
{
// Install the custom JAAS configuration
Configuration.setConfiguration(new TestConfig());
@@ -389,4 +447,43 @@
lc.logout();
}
+ /**
+ * <p>
+ * Tests the behavior of the {@code throwValidateError flag}. The test uses a login module that fails the validation
+ * phase and sets a validation exception with an error message. In the first scenario, a configuration that doesn't
+ * set the {@code throwValidateError} flag is used. As a result, the exception that is caught should not have any
+ * cause set. In the second scenario, a configuration that sets the flag to {@code true} is used. As a result, the
+ * exception that is caught should contain the validation exception as the root cause.
+ * </p>
+ *
+ * @throws Exception if an error occurs while running the test.
+ */
+ public void testValidateError() throws Exception
+ {
+ // test the configuration that doesn't set the throwValidateError flag.
+ LoginContext context = new LoginContext("testValidateError", new UsernamePasswordHandler(null, null));
+ try
+ {
+ context.login();
+ fail("Login should have failed as the validation of the test module was unsuccessful");
+ }
+ catch(LoginException le)
+ {
+ assertNull("Unexpected root throwable found", le.getCause());
+ }
+
+ // test the configuration that sets the throwValidateError flag.
+ context = new LoginContext("testValidateErrorWithFlag", new UsernamePasswordHandler(null, null));
+ try
+ {
+ context.login();
+ fail("Login should have failed as the validation of the test module was unsuccessful");
+ }
+ catch(LoginException le)
+ {
+ assertNotNull("Unexpected null root thorwable", le.getCause());
+ assertEquals("Invalid root message", "Validate Exception", le.getCause().getMessage());
+ }
+
+ }
}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list