[jboss-cvs] JBossAS SVN: r64330 - in projects/security/security-jboss-sx/trunk/src/tests: resources/config and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jul 27 13:20:23 EDT 2007
Author: anil.saldhana at jboss.com
Date: 2007-07-27 13:20:23 -0400 (Fri, 27 Jul 2007)
New Revision: 64330
Added:
projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authentication/jaspi/JASPILoginModuleDelgateUnitTestCase.java
projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authentication/jaspi/LoginModuleServerAuthModule.java
Modified:
projects/security/security-jboss-sx/trunk/src/tests/resources/config/jaspi-config.xml
Log:
usecase where JASPI ServerAuthModule delegates to a login module
Added: projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authentication/jaspi/JASPILoginModuleDelgateUnitTestCase.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authentication/jaspi/JASPILoginModuleDelgateUnitTestCase.java (rev 0)
+++ projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authentication/jaspi/JASPILoginModuleDelgateUnitTestCase.java 2007-07-27 17:20:23 UTC (rev 64330)
@@ -0,0 +1,128 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, JBoss Inc., and individual contributors as indicated
+ * 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.test.authentication.jaspi;
+
+import java.net.URL;
+import java.util.HashMap;
+
+import javax.security.auth.Subject;
+import javax.security.auth.login.Configuration;
+import javax.security.auth.message.AuthException;
+import javax.security.auth.message.AuthStatus;
+import javax.security.auth.message.MessageInfo;
+import javax.security.auth.message.config.AuthConfigFactory;
+import javax.security.auth.message.config.AuthConfigProvider;
+import javax.security.auth.message.config.ServerAuthConfig;
+import javax.security.auth.message.config.ServerAuthContext;
+
+import org.jboss.security.SecurityConstants;
+import org.jboss.security.auth.callback.AppCallbackHandler;
+import org.jboss.security.auth.login.XMLLoginConfigImpl;
+import org.jboss.security.auth.message.GenericMessageInfo;
+import org.jboss.security.auth.message.config.JBossAuthConfigProvider;
+import org.jboss.security.plugins.JBossSecurityContext;
+import org.jboss.security.plugins.SecurityContextAssociation;
+
+import junit.framework.TestCase;
+
+//$Id$
+
+/**
+ * Test the delegation to a JAAS Login Module
+ * by a Server Auth Module
+ * @author Anil.Saldhana at redhat.com
+ * @since Jul 27, 2007
+ * @version $Revision$
+ */
+public class JASPILoginModuleDelgateUnitTestCase extends TestCase
+{
+ AuthConfigFactory factory = null;
+ String layer = SecurityConstants.SERVLET_LAYER;
+ String appId = "localhost /petstore";
+
+ String configFile="config/jaspi-config.xml";
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ factory = AuthConfigFactory.getFactory();
+ factory.registerConfigProvider(new JBossAuthConfigProvider(new HashMap()),
+ layer, appId, "Test Config Provider");
+
+ JBossSecurityContext jsc = new JBossSecurityContext("conf-jaspi-2");
+ SecurityContextAssociation.setSecurityContext(jsc);
+
+ XMLLoginConfigImpl xli = new XMLLoginConfigImpl();
+ Configuration.setConfiguration(xli);
+
+ URL configURL = Thread.currentThread().getContextClassLoader().getResource(configFile);
+ assertNotNull("Config URL",configURL);
+
+ xli.setConfigURL(configURL);
+ xli.loadConfig();
+ }
+
+ public void testSuccessfulJASPI() throws Exception
+ {
+ AuthConfigProvider provider = factory.getConfigProvider(layer,appId,null);
+ ServerAuthConfig serverConfig = provider.getServerAuthConfig(layer,appId,
+ new AppCallbackHandler("jduke","theduke".toCharArray()));
+ assertNotNull("ServerAuthConfig is not null", serverConfig);
+
+ MessageInfo mi = new GenericMessageInfo(new Object(), new Object());
+ String authContextID = serverConfig.getAuthContextID(mi);
+ assertNotNull("AuthContext ID != null",authContextID);
+ ServerAuthContext sctx = serverConfig.getAuthContext(authContextID,
+ new Subject(), new HashMap());
+ assertNotNull("ServerAuthContext != null",sctx);
+ Subject clientSubject = new Subject();
+ Subject serviceSubject = new Subject();
+ AuthStatus status = sctx.validateRequest(mi, clientSubject, serviceSubject);
+ assertEquals(AuthStatus.SUCCESS, status );
+ }
+
+ public void testUnSuccessfulJASPI() throws Exception
+ {
+ AuthConfigProvider provider = factory.getConfigProvider(layer,appId,null);
+ ServerAuthConfig serverConfig = provider.getServerAuthConfig(layer,appId,
+ new AppCallbackHandler("jduke","badpwd".toCharArray()));
+ assertNotNull("ServerAuthConfig is not null", serverConfig);
+
+ MessageInfo mi = new GenericMessageInfo(new Object(), new Object());
+ String authContextID = serverConfig.getAuthContextID(mi);
+ assertNotNull("AuthContext ID != null",authContextID);
+ ServerAuthContext sctx = serverConfig.getAuthContext(authContextID,
+ new Subject(), new HashMap());
+ assertNotNull("ServerAuthContext != null",sctx);
+ Subject clientSubject = new Subject();
+ Subject serviceSubject = new Subject();
+ try
+ {
+ AuthStatus status = sctx.validateRequest(mi, clientSubject, serviceSubject);
+ assertEquals(AuthStatus.FAILURE, status );
+ }
+ catch(AuthException ae)
+ {
+ //Pass
+ }
+ }
+}
Added: projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authentication/jaspi/LoginModuleServerAuthModule.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authentication/jaspi/LoginModuleServerAuthModule.java (rev 0)
+++ projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authentication/jaspi/LoginModuleServerAuthModule.java 2007-07-27 17:20:23 UTC (rev 64330)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, JBoss Inc., and individual contributors as indicated
+ * 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.test.authentication.jaspi;
+
+import java.util.Map;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.login.LoginContext;
+import javax.security.auth.login.LoginException;
+import javax.security.auth.message.AuthException;
+import javax.security.auth.message.AuthStatus;
+import javax.security.auth.message.MessageInfo;
+import javax.security.auth.message.MessagePolicy;
+
+import org.jboss.security.auth.container.modules.AbstractServerAuthModule;
+
+//$Id$
+
+/**
+ * Test Server Auth Module that delegates to a login module
+ * @author Anil.Saldhana at redhat.com
+ * @since Jul 25, 2007
+ * @version $Revision$
+ */
+public class LoginModuleServerAuthModule extends AbstractServerAuthModule
+{
+
+ public LoginModuleServerAuthModule()
+ {
+ this.supportedTypes.add(Object.class);
+ }
+
+ @Override
+ protected boolean validate() throws AuthException
+ {
+ throw new IllegalStateException("Configure a login module in the module options");
+ }
+
+ public AuthStatus secureResponse(MessageInfo arg0, Subject arg1) throws AuthException
+ {
+ return null;
+ }
+}
Modified: projects/security/security-jboss-sx/trunk/src/tests/resources/config/jaspi-config.xml
===================================================================
--- projects/security/security-jboss-sx/trunk/src/tests/resources/config/jaspi-config.xml 2007-07-27 17:18:52 UTC (rev 64329)
+++ projects/security/security-jboss-sx/trunk/src/tests/resources/config/jaspi-config.xml 2007-07-27 17:20:23 UTC (rev 64330)
@@ -22,4 +22,14 @@
login-module-stack-ref="lm-stack"/>
</authentication-jaspi>
</application-policy>
+
+ <application-policy name="conf-jaspi-2">
+ <authentication-jaspi>
+ <auth-module code="org.jboss.test.authentication.jaspi.LoginModuleServerAuthModule">
+ <module-option name="login-module-delegate">org.jboss.security.auth.spi.UsersRolesLoginModule</module-option>
+ <module-option name="usersProperties">users.properties</module-option>
+ <module-option name="rolesProperties">roles.properties</module-option>
+ </auth-module>
+ </authentication-jaspi>
+ </application-policy>
</policy>
More information about the jboss-cvs-commits
mailing list