[jboss-cvs] JBossAS SVN: r79768 - in trunk/testsuite: src/main/org/jboss/test/security/test and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Oct 20 16:28:45 EDT 2008
Author: anil.saldhana at jboss.com
Date: 2008-10-20 16:28:45 -0400 (Mon, 20 Oct 2008)
New Revision: 79768
Added:
trunk/testsuite/src/main/org/jboss/test/security/test/SecurityDomainTolerateUnitTestCase.java
trunk/testsuite/src/resources/security/sdtolerate/
trunk/testsuite/src/resources/security/sdtolerate/application.xml
trunk/testsuite/src/resources/security/sdtolerate/ejb/
trunk/testsuite/src/resources/security/sdtolerate/ejb/ejb-jar.xml
trunk/testsuite/src/resources/security/sdtolerate/ejb/jboss.xml
trunk/testsuite/src/resources/security/sdtolerate/r.properties
trunk/testsuite/src/resources/security/sdtolerate/sdtolerate-jboss-beans.xml
trunk/testsuite/src/resources/security/sdtolerate/u.properties
trunk/testsuite/src/resources/security/sdtolerate/web/
trunk/testsuite/src/resources/security/sdtolerate/web/WEB-INF/
trunk/testsuite/src/resources/security/sdtolerate/web/WEB-INF/jboss-web.xml
trunk/testsuite/src/resources/security/sdtolerate/web/WEB-INF/web.xml
trunk/testsuite/src/resources/security/sdtolerate/web/index.jsp
trunk/testsuite/src/resources/security/sdtolerate/web/login.jsp
trunk/testsuite/src/resources/security/sdtolerate/web/loginError.jsp
Modified:
trunk/testsuite/imports/sections/security.xml
Log:
JBAS-6060: tolerate a security domain without the java:/jaas prefix
Modified: trunk/testsuite/imports/sections/security.xml
===================================================================
--- trunk/testsuite/imports/sections/security.xml 2008-10-20 20:28:37 UTC (rev 79767)
+++ trunk/testsuite/imports/sections/security.xml 2008-10-20 20:28:45 UTC (rev 79768)
@@ -408,5 +408,48 @@
</fileset>
</war>
+ <!-- JBAS-6060: Tolerate security domain with no java:/jaas prefix -->
+ <war warfile="${build.lib}/sdtolerate.war"
+ webxml="${build.resources}/security/sdtolerate/web/WEB-INF/web.xml">
+ <webinf dir="${build.resources}/security/sdtolerate/web/WEB-INF">
+ <include name="jboss-web.xml"/>
+ </webinf>
+ <fileset dir="${build.resources}/security/sdtolerate/web">
+ <include name="*jsp"/>
+ <include name="*html"/>
+ </fileset>
+ </war>
+
+ <jar destfile="${build.lib}/sdtolerate.jar">
+ <metainf dir="${build.resources}/security/sdtolerate/ejb">
+ <include name="ejb-jar.xml" />
+ <include name="jboss.xml" />
+ </metainf>
+ <fileset dir="${build.classes}">
+ <include name="org/jboss/test/security/ejb/StatelessSessionBean.*"/>
+ <include name="org/jboss/test/security/interfaces/StatelessSession*"/>
+ </fileset>
+ </jar>
+
+ <jar destfile="${build.lib}/sdtolerate-resources.jar">
+ <fileset dir="${build.resources}/security/sdtolerate">
+ <include name="*.properties" />
+ </fileset>
+ </jar>
+
+ <ear earfile="${build.lib}/sdtolerate.ear"
+ appxml="${build.resources}/security/sdtolerate/application.xml">
+ <fileset dir="${build.lib}">
+ <include name="sdtolerate.jar"/>
+ <include name="sdtolerate.war"/>
+ </fileset>
+ <fileset dir="${build.resources}/security/sdtolerate">
+ <include name="*-jboss-beans.xml" />
+ </fileset>
+ <zipfileset dir="${build.lib}" prefix="lib">
+ <include name="sdtolerate-resources.jar" />
+ </zipfileset>
+ </ear>
+
</target>
</project>
Added: trunk/testsuite/src/main/org/jboss/test/security/test/SecurityDomainTolerateUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/security/test/SecurityDomainTolerateUnitTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/security/test/SecurityDomainTolerateUnitTestCase.java 2008-10-20 20:28:45 UTC (rev 79768)
@@ -0,0 +1,181 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.security.test;
+
+import java.net.HttpURLConnection;
+
+import javax.rmi.PortableRemoteObject;
+import javax.security.auth.login.Configuration;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.httpclient.Cookie;
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpState;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.jboss.security.auth.login.XMLLoginConfigImpl;
+import org.jboss.security.client.SecurityClient;
+import org.jboss.security.client.SecurityClientFactory;
+import org.jboss.test.JBossTestCase;
+import org.jboss.test.JBossTestSetup;
+import org.jboss.test.security.interfaces.StatelessSession;
+import org.jboss.test.security.interfaces.StatelessSessionHome;
+
+/**
+ * JBAS-6060: Tolerate security domain in web and ejb2
+ * deployment descriptors with no java:/jaas prefix
+ * @author Anil.Saldhana at redhat.com
+ * @since Oct 20, 2008
+ */
+public class SecurityDomainTolerateUnitTestCase extends JBossTestCase
+{
+ private static String login_config = "security/sdtolerate/sdtolerate-jboss-beans.xml";
+
+ private String username = "harry";
+ private String password = "potter";
+
+ public SecurityDomainTolerateUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testEJB() throws Exception
+ {
+ log.debug("+++ testEJBNullSecurityDomain");
+ Object obj = getInitialContext().lookup("null.StatelessSession");
+ obj = PortableRemoteObject.narrow(obj, StatelessSessionHome.class);
+ StatelessSessionHome home = (StatelessSessionHome) obj;
+ log.debug("Found null.StatelessSession Home");
+ StatelessSession bean = null;
+ try
+ {
+ bean = home.create();
+ fail("Invoking create() should fail");
+ }
+ catch (Exception e)
+ {
+ Throwable t = e.getCause();
+ if (t instanceof SecurityException)
+ {
+ log.debug("Invoking create() was correctly denied by a SecurityException:", e);
+ }
+ else
+ {
+ log.debug("Invoking create() failed by an unexpected reason:", e);
+ fail("Unexpected exception");
+ }
+ }
+ SecurityClient client = SecurityClientFactory.getSecurityClient();
+ client.setSimple(username, password);
+ client.login();
+ try
+ {
+ bean = home.create();
+ bean.echo("hi");
+ }
+ catch(Exception e)
+ {
+ fail(e.getLocalizedMessage());
+ }
+ }
+
+ public void testWeb() throws Exception
+ {
+ String baseURLNoAuth = "http://" + getServerHost() +
+ ":" + Integer.getInteger("web.port", 8080) + "/";
+ HttpClient httpConn = new HttpClient();
+ GetMethod indexGet = new GetMethod(baseURLNoAuth + "sdtolerate/");
+ int responseCode = httpConn.executeMethod(indexGet);
+ String body = indexGet.getResponseBodyAsString();
+ assertTrue("Get OK(" + responseCode + ")", responseCode == HttpURLConnection.HTTP_OK);
+ assertTrue("Redirected to login page", body.indexOf("j_security_check") > 0);
+ HttpState state = httpConn.getState();
+ Cookie[] cookies = state.getCookies();
+ String sessionID = null;
+ for (int c = 0; c < cookies.length; c++)
+ {
+ Cookie k = cookies[c];
+ if (k.getName().equalsIgnoreCase("JSESSIONID"))
+ sessionID = k.getValue();
+ }
+ getLog().debug("Saw JSESSIONID=" + sessionID);
+ // Submit the login form
+ PostMethod formPost = new PostMethod(baseURLNoAuth + "sdtolerate/j_security_check");
+ formPost.addRequestHeader("Referer", baseURLNoAuth + "sdtolerate/login.jsp");
+ formPost.addParameter("j_username", this.username);
+ formPost.addParameter("j_password", new String(password));
+ responseCode = httpConn.executeMethod(formPost);
+ String loginResult = formPost.getResponseBodyAsString();
+ if( loginResult.indexOf("Encountered a login error") > 0 )
+ fail("Login Failed");
+
+ String response = formPost.getStatusText();
+ log.debug("responseCode="+responseCode+", response="+response);
+ assertTrue("Saw HTTP_MOVED_TEMP", responseCode == HttpURLConnection.HTTP_MOVED_TEMP);
+
+ // Follow the redirect to the index.jsp
+ Header location = formPost.getResponseHeader("Location");
+ String indexURI = location.getValue();
+ GetMethod war1Index = new GetMethod(indexURI);
+ responseCode = httpConn.executeMethod(war1Index);
+ response = war1Index.getStatusText();
+ log.debug("responseCode="+responseCode+", response="+response);
+ assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
+ }
+
+ /**
+ * Setup the test suite.
+ */
+ public static Test suite() throws Exception
+ {
+ TestSuite suite = new TestSuite();
+ suite.addTest(new TestSuite(SecurityDomainTolerateUnitTestCase.class));
+
+ // Create an initializer for the test suite
+ TestSetup wrapper = new JBossTestSetup(suite)
+ {
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ Configuration.setConfiguration(XMLLoginConfigImpl.getInstance());
+ redeploy("sdtolerate.ear");
+ redeploy(getResourceURL(login_config));
+ flushAuthCache();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ undeploy(getResourceURL(login_config));
+ undeploy("sdtolerate.ear");
+ super.tearDown();
+ }
+ };
+ return wrapper;
+ }
+
+}
\ No newline at end of file
Added: trunk/testsuite/src/resources/security/sdtolerate/application.xml
===================================================================
--- trunk/testsuite/src/resources/security/sdtolerate/application.xml (rev 0)
+++ trunk/testsuite/src/resources/security/sdtolerate/application.xml 2008-10-20 20:28:45 UTC (rev 79768)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE application PUBLIC
+ "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"
+ "http://java.sun.com/dtd/application_1_3.dtd">
+
+<application>
+ <display-name>Security Domain Toleration Tests</display-name>
+
+ <module>
+ <web>
+ <web-uri>sdtolerate.war</web-uri>
+ <context-root>/sdtolerate</context-root>
+ </web>
+ </module>
+
+ <module>
+ <ejb>sdtolerate.jar</ejb>
+ </module>
+</application>
Added: trunk/testsuite/src/resources/security/sdtolerate/ejb/ejb-jar.xml
===================================================================
--- trunk/testsuite/src/resources/security/sdtolerate/ejb/ejb-jar.xml (rev 0)
+++ trunk/testsuite/src/resources/security/sdtolerate/ejb/ejb-jar.xml 2008-10-20 20:28:45 UTC (rev 79768)
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE ejb-jar PUBLIC
+ "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
+ "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
+
+<ejb-jar>
+ <display-name>SecurityTests</display-name>
+ <enterprise-beans>
+ <session>
+ <description>A secured trival echo session bean</description>
+ <ejb-name>StatelessSession</ejb-name>
+ <home>org.jboss.test.security.interfaces.StatelessSessionHome</home>
+ <remote>org.jboss.test.security.interfaces.StatelessSession</remote>
+ <local-home>org.jboss.test.security.interfaces.StatelessSessionLocalHome</local-home>
+ <local>org.jboss.test.security.interfaces.StatelessSessionLocal</local>
+ <ejb-class>org.jboss.test.security.ejb.StatelessSessionBean</ejb-class>
+ <session-type>Stateless</session-type>
+ <transaction-type>Container</transaction-type>
+ <security-role-ref>
+ <role-name>EchoCaller</role-name>
+ <role-link>Echo</role-link>
+ </security-role-ref>
+ </session>
+ </enterprise-beans>
+
+ <assembly-descriptor>
+ <security-role>
+ <description>The role required to invoke the echo method</description>
+ <role-name>Echo</role-name>
+ </security-role>
+
+ <!-- Methods anyone can access -->
+ <method-permission>
+ <unchecked/>
+ <method>
+ <ejb-name>StatelessSession</ejb-name>
+ <method-name>unchecked</method-name>
+ </method>
+ <method>
+ <ejb-name>StatelessSession</ejb-name>
+ <method-name>remove</method-name>
+ </method>
+ </method-permission>
+
+ <!-- The methods the Echo role can access -->
+ <method-permission>
+ <role-name>Echo</role-name>
+ <method>
+ <ejb-name>StatelessSession</ejb-name>
+ <method-name>create</method-name>
+ </method>
+ <method>
+ <ejb-name>StatelessSession</ejb-name>
+ <method-name>echo</method-name>
+ </method>
+ <method>
+ <ejb-name>StatelessSession</ejb-name>
+ <method-name>npeError</method-name>
+ </method>
+ </method-permission>
+
+ <!-- No one can access the excluded() method of the
+ StatelessSession and StatelessSession2 beans -->
+ <exclude-list>
+ <description>A method that no one can access in this deployment</description>
+ <method>
+ <ejb-name>StatelessSession</ejb-name>
+ <method-name>excluded</method-name>
+ </method>
+ </exclude-list>
+
+ </assembly-descriptor>
+
+</ejb-jar>
Added: trunk/testsuite/src/resources/security/sdtolerate/ejb/jboss.xml
===================================================================
--- trunk/testsuite/src/resources/security/sdtolerate/ejb/jboss.xml (rev 0)
+++ trunk/testsuite/src/resources/security/sdtolerate/ejb/jboss.xml 2008-10-20 20:28:45 UTC (rev 79768)
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<!DOCTYPE jboss PUBLIC
+ "-//JBoss//DTD JBOSS 4.0//EN"
+ "http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd">
+
+<!-- The jboss.xml descriptor for the ejb-null-security-domain.jar ejb unit.
+This descriptor redefines the JNDI names of the beans in the ejb-jar.xml
+descriptor so that there is no conflict with the security.jar deployment.
+-->
+<jboss>
+ <security-domain>ejb-test</security-domain>
+ <unauthenticated-principal>nobody</unauthenticated-principal>
+
+ <enterprise-beans>
+ <session>
+ <ejb-name>StatelessSession</ejb-name>
+ <jndi-name>null.StatelessSession</jndi-name>
+ </session>
+ </enterprise-beans>
+
+</jboss>
Added: trunk/testsuite/src/resources/security/sdtolerate/r.properties
===================================================================
--- trunk/testsuite/src/resources/security/sdtolerate/r.properties (rev 0)
+++ trunk/testsuite/src/resources/security/sdtolerate/r.properties 2008-10-20 20:28:45 UTC (rev 79768)
@@ -0,0 +1 @@
+harry=magician,Echo
Added: trunk/testsuite/src/resources/security/sdtolerate/sdtolerate-jboss-beans.xml
===================================================================
--- trunk/testsuite/src/resources/security/sdtolerate/sdtolerate-jboss-beans.xml (rev 0)
+++ trunk/testsuite/src/resources/security/sdtolerate/sdtolerate-jboss-beans.xml 2008-10-20 20:28:45 UTC (rev 79768)
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <application-policy xmlns="urn:jboss:security-beans:1.0" name="web-test">
+ <authentication>
+ <login-module code = "org.jboss.security.auth.spi.UsersRolesLoginModule"
+ flag = "required">
+ <module-option name = "unauthenticatedIdentity">anonymous</module-option>
+ <module-option name="usersProperties">u.properties</module-option>
+ <module-option name="rolesProperties">r.properties</module-option>
+ </login-module>
+ </authentication>
+ </application-policy>
+
+ <application-policy xmlns="urn:jboss:security-beans:1.0" name="ejb-test">
+ <authentication>
+ <login-module code = "org.jboss.security.auth.spi.UsersRolesLoginModule"
+ flag = "required">
+ <module-option name = "unauthenticatedIdentity">anonymous</module-option>
+ <module-option name="usersProperties">u.properties</module-option>
+ <module-option name="rolesProperties">r.properties</module-option>
+ </login-module>
+ </authentication>
+ </application-policy>
+
+</deployment>
Added: trunk/testsuite/src/resources/security/sdtolerate/u.properties
===================================================================
--- trunk/testsuite/src/resources/security/sdtolerate/u.properties (rev 0)
+++ trunk/testsuite/src/resources/security/sdtolerate/u.properties 2008-10-20 20:28:45 UTC (rev 79768)
@@ -0,0 +1 @@
+harry=potter
Added: trunk/testsuite/src/resources/security/sdtolerate/web/WEB-INF/jboss-web.xml
===================================================================
--- trunk/testsuite/src/resources/security/sdtolerate/web/WEB-INF/jboss-web.xml (rev 0)
+++ trunk/testsuite/src/resources/security/sdtolerate/web/WEB-INF/jboss-web.xml 2008-10-20 20:28:45 UTC (rev 79768)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE jboss-web
+ PUBLIC "-//JBoss//DTD Web Application 2.4//EN"
+ "http://www.jboss.org/j2ee/dtd/jboss-web_4_0.dtd">
+<jboss-web>
+ <security-domain>web-test</security-domain>
+</jboss-web>
Added: trunk/testsuite/src/resources/security/sdtolerate/web/WEB-INF/web.xml
===================================================================
--- trunk/testsuite/src/resources/security/sdtolerate/web/WEB-INF/web.xml (rev 0)
+++ trunk/testsuite/src/resources/security/sdtolerate/web/WEB-INF/web.xml 2008-10-20 20:28:45 UTC (rev 79768)
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE web-app
+ PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd">
+<web-app>
+ <display-name>Security Domain Tolerance Test</display-name>
+ <welcome-file-list>
+ <welcome-file>index.jsp</welcome-file>
+ </welcome-file-list>
+
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>allJspPages</web-resource-name>
+ <description>All JSP Pages</description>
+ <url-pattern>*.jsp</url-pattern>
+ <http-method>GET</http-method>
+ <http-method>POST</http-method>
+ </web-resource-collection>
+ <auth-constraint>
+ <role-name>magician</role-name>
+ </auth-constraint>
+ <user-data-constraint>
+ <description>no description</description>
+ <transport-guarantee>NONE</transport-guarantee>
+ </user-data-constraint>
+ </security-constraint>
+
+ <login-config>
+ <auth-method>FORM</auth-method>
+ <realm-name>JBossRealm</realm-name>
+ <form-login-config>
+ <form-login-page>/login.jsp</form-login-page>
+ <form-error-page>/loginError.jsp</form-error-page>
+ </form-login-config>
+ </login-config>
+
+ <security-role>
+ <role-name>magician</role-name>
+ </security-role>
+</web-app>
Added: trunk/testsuite/src/resources/security/sdtolerate/web/index.jsp
===================================================================
--- trunk/testsuite/src/resources/security/sdtolerate/web/index.jsp (rev 0)
+++ trunk/testsuite/src/resources/security/sdtolerate/web/index.jsp 2008-10-20 20:28:45 UTC (rev 79768)
@@ -0,0 +1 @@
+Just a regular static page.
Added: trunk/testsuite/src/resources/security/sdtolerate/web/login.jsp
===================================================================
--- trunk/testsuite/src/resources/security/sdtolerate/web/login.jsp (rev 0)
+++ trunk/testsuite/src/resources/security/sdtolerate/web/login.jsp 2008-10-20 20:28:45 UTC (rev 79768)
@@ -0,0 +1,15 @@
+<html>
+<body>
+ <form action="j_security_check" method="post" id="login">
+ <p>
+ User ID: <input type="text" size="20" name="j_username" id="user
+name_id"/>
+ <br>
+ Password: <input type="password" size="20" name="j_password"/>
+ <br>
+ <br>
+ <input type="submit" value="submit">
+ </p>
+ </form>
+</body>
+</html>
Added: trunk/testsuite/src/resources/security/sdtolerate/web/loginError.jsp
===================================================================
--- trunk/testsuite/src/resources/security/sdtolerate/web/loginError.jsp (rev 0)
+++ trunk/testsuite/src/resources/security/sdtolerate/web/loginError.jsp 2008-10-20 20:28:45 UTC (rev 79768)
@@ -0,0 +1 @@
+Encountered a login error!!
More information about the jboss-cvs-commits
mailing list