[jboss-cvs] JBossAS SVN: r61327 - in branches/Branch_4_2/testsuite: src/main/org/jboss/test/web/servlets and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Mar 14 12:09:52 EDT 2007
Author: anil.saldhana at jboss.com
Date: 2007-03-14 12:09:52 -0400 (Wed, 14 Mar 2007)
New Revision: 61327
Added:
branches/Branch_4_2/testsuite/src/main/org/jboss/test/web/servlets/ProgrammaticLoginTestServlet.java
branches/Branch_4_2/testsuite/src/main/org/jboss/test/web/test/WebProgrammaticLoginTestCase.java
branches/Branch_4_2/testsuite/src/resources/web/programmatic/
branches/Branch_4_2/testsuite/src/resources/web/programmatic/WEB-INF/
branches/Branch_4_2/testsuite/src/resources/web/programmatic/WEB-INF/jboss-web.xml
branches/Branch_4_2/testsuite/src/resources/web/programmatic/WEB-INF/jbosstest-web.xml
branches/Branch_4_2/testsuite/src/resources/web/programmatic/WEB-INF/jbosstest-web.xml.orig
branches/Branch_4_2/testsuite/src/resources/web/programmatic/application.xml
Modified:
branches/Branch_4_2/testsuite/imports/sections/web.xml
Log:
JBAS-4077: test and resources for web programmatic login
Modified: branches/Branch_4_2/testsuite/imports/sections/web.xml
===================================================================
--- branches/Branch_4_2/testsuite/imports/sections/web.xml 2007-03-14 16:08:22 UTC (rev 61326)
+++ branches/Branch_4_2/testsuite/imports/sections/web.xml 2007-03-14 16:09:52 UTC (rev 61327)
@@ -503,6 +503,34 @@
<zipfileset dir="${build.resources}/web/form-auth"
includes="jboss-service.xml"/>
</zip>
-
+
+ <!-- JBAS-4077: Programmatic Web Login -->
+ <war destfile="${build.lib}/programmaticweblogin.war"
+ webxml="${build.resources}/web/programmatic/WEB-INF/jbosstest-web.xml">
+ <webinf dir="${build.resources}/web/form-auth">
+ <include name="jboss-web.xml"/>
+ </webinf>
+ <classes dir="${build.classes}">
+ <include name="org/jboss/test/web/servlets/Programm*Servlet.class"/>
+ </classes>
+ </war>
+ <zip destfile="${build.lib}/programmaticweblogin.ear">
+ <zipfileset dir="${build.resources}/web/form-auth" prefix="META-INF">
+ <include name="jboss-app.xml"/>
+ <include name="security-config.xml"/>
+ </zipfileset>
+ <zipfileset dir="${build.resources}/web/programmatic" prefix="META-INF">
+ <include name="application.xml"/>
+ </zipfileset>
+ <zipfileset dir="${build.resources}/web"
+ fullpath="form-auth-users.properties"
+ includes="users.properties"/>
+ <zipfileset dir="${build.resources}/web"
+ fullpath="form-auth-roles.properties"
+ includes="roles.properties"/>
+ <zipfileset dir="${build.lib}" includes="programmatic*.war"/>
+ <zipfileset dir="${build.resources}/web/form-auth"
+ includes="jboss-service.xml"/>
+ </zip>
</target>
</project>
Added: branches/Branch_4_2/testsuite/src/main/org/jboss/test/web/servlets/ProgrammaticLoginTestServlet.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/web/servlets/ProgrammaticLoginTestServlet.java (rev 0)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/web/servlets/ProgrammaticLoginTestServlet.java 2007-03-14 16:09:52 UTC (rev 61327)
@@ -0,0 +1,71 @@
+/*
+ * 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.web.servlets;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.jboss.web.tomcat.security.login.WebAuthentication;
+
+//$Id$
+
+/**
+ * JBAS-4077: Programmatic Web Login
+ * Servlet picks up the username, password from the request parameters
+ * and then does the web authentication
+ * @author Anil.Saldhana at redhat.com
+ * @since Mar 12, 2007
+ * @version $Revision$
+ */
+public class ProgrammaticLoginTestServlet extends HttpServlet
+{
+ private static final long serialVersionUID = 1L;
+
+ protected void service(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException
+ {
+ String username = request.getParameter("username");
+ String pass = request.getParameter("pass");
+
+ if(username == null || pass == null)
+ throw new RuntimeException("username or password is null");
+ WebAuthentication pwl = new WebAuthentication();
+ pwl.login(username, pass);
+
+ //Only when there is web login, does the principal be visible
+ log("User Principal="+request.getUserPrincipal());
+ log("isUserInRole(Authorized User)="+request.isUserInRole("AuthorizedUser"));
+ if(request.getUserPrincipal() == null || !request.isUserInRole("AuthorizedUser"))
+ throw new ServletException("User is not authenticated or the isUserInRole check failed");
+
+
+ //Log the user out
+ pwl.logout();
+
+ if(request.getUserPrincipal() != null || request.isUserInRole("AuthorizedUser"))
+ throw new ServletException("User is still authenticated or pass: isUserInRole(Authorized User)");
+ }
+}
Added: branches/Branch_4_2/testsuite/src/main/org/jboss/test/web/test/WebProgrammaticLoginTestCase.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/web/test/WebProgrammaticLoginTestCase.java (rev 0)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/web/test/WebProgrammaticLoginTestCase.java 2007-03-14 16:09:52 UTC (rev 61327)
@@ -0,0 +1,115 @@
+/*
+ * 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.web.test;
+
+import java.net.HttpURLConnection;
+
+import junit.framework.Test;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.jboss.test.JBossTestCase;
+
+//$Id$
+
+/**
+ * JBAS-4077: Web Programmatic Login
+ * @author Anil.Saldhana at redhat.com
+ * @since Mar 12, 2007
+ * @version $Revision$
+ */
+public class WebProgrammaticLoginTestCase extends JBossTestCase
+{
+ private String baseURLNoAuth = "http://" + getServerHost()
+ + ":" + Integer.getInteger("web.port", 8080) + "/";
+ private HttpClient httpConn = new HttpClient();
+
+ public WebProgrammaticLoginTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite() throws Exception
+ {
+ return getDeploySetup(WebProgrammaticLoginTestCase.class,
+ "programmaticweblogin.war");
+ }
+
+ /**
+ * Test unsuccessful login
+ * @throws Exception
+ */
+ public void testUnsuccessfulLogin() throws Exception
+ {
+ String path1 = "programmaticweblogin/TestServlet";
+ HttpMethod indexGet = null;
+ try
+ {
+ indexGet = new GetMethod(baseURLNoAuth+path1);
+ int responseCode = httpConn.executeMethod(indexGet);
+ assertTrue("Get Error("+responseCode+")",
+ responseCode == HttpURLConnection.HTTP_INTERNAL_ERROR);
+ }
+ finally
+ {
+ if(indexGet != null)
+ indexGet.releaseConnection();
+ }
+
+ path1 = path1 + "?username=dummy&pass=dummy";
+ try
+ {
+ indexGet = new GetMethod(baseURLNoAuth+path1);
+ int responseCode = httpConn.executeMethod(indexGet);
+ assertTrue("Get Error("+responseCode+")",
+ responseCode == HttpURLConnection.HTTP_INTERNAL_ERROR);
+ }
+ finally
+ {
+ if(indexGet != null)
+ indexGet.releaseConnection();
+ }
+ }
+
+ /**
+ * Test Successful programmatic login in a servlet
+ *
+ */
+ public void testSuccessfulLogin() throws Exception
+ {
+ String path1 = "programmaticweblogin/TestServlet?username=jduke&pass=theduke";
+ HttpMethod indexGet = null;
+ try
+ {
+ indexGet = new GetMethod(baseURLNoAuth+path1);
+ int responseCode = httpConn.executeMethod(indexGet);
+ assertTrue("Get OK("+responseCode+")", responseCode == HttpURLConnection.HTTP_OK);
+ }
+ finally
+ {
+ if(indexGet != null)
+ indexGet.releaseConnection();
+ }
+ }
+
+}
Added: branches/Branch_4_2/testsuite/src/resources/web/programmatic/WEB-INF/jboss-web.xml
===================================================================
Added: branches/Branch_4_2/testsuite/src/resources/web/programmatic/WEB-INF/jbosstest-web.xml
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/web/programmatic/WEB-INF/jbosstest-web.xml (rev 0)
+++ branches/Branch_4_2/testsuite/src/resources/web/programmatic/WEB-INF/jbosstest-web.xml 2007-03-14 16:09:52 UTC (rev 61327)
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<web-app version="2.4"
+ xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+ http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+
+ <description>Programmatic Web Login Tests</description>
+
+ <!-- ### Servlets -->
+ <servlet>
+ <servlet-name>TestServlet</servlet-name>
+ <servlet-class>org.jboss.test.web.servlets.ProgrammaticLoginTestServlet</servlet-class>
+ </servlet>
+
+ <!-- The servlet and jsp page mappings -->
+ <servlet-mapping>
+ <servlet-name>TestServlet</servlet-name>
+ <url-pattern>/TestServlet</url-pattern>
+ </servlet-mapping>
+
+ <login-config>
+ <auth-method>BASIC</auth-method>
+ <realm-name>JBossTest Servlets</realm-name>
+ </login-config>
+
+ <security-role>
+ <description>An AuthorizedUser is one with a valid username and password</description>
+ <role-name>AuthorizedUser</role-name>
+ </security-role>
+</web-app>
+
Added: branches/Branch_4_2/testsuite/src/resources/web/programmatic/WEB-INF/jbosstest-web.xml.orig
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/web/programmatic/WEB-INF/jbosstest-web.xml.orig (rev 0)
+++ branches/Branch_4_2/testsuite/src/resources/web/programmatic/WEB-INF/jbosstest-web.xml.orig 2007-03-14 16:09:52 UTC (rev 61327)
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<web-app version="2.4"
+ xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+ http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+
+ <description>Programmatic Web Login Tests</description>
+
+ <!-- ### Servlets -->
+ <servlet>
+ <servlet-name>TestServlet</servlet-name>
+ <servlet-class>org.jboss.test.web.servlets.ProgrammaticLoginTestServlet</servlet-class>
+ </servlet>
+ <servlet>
+ <servlet-name>ForwardedServlet</servlet-name>
+ <jsp-file>/forwarded.jsp</jsp-file>
+ </servlet>
+
+ <!-- The servlet and jsp page mappings -->
+ <servlet-mapping>
+ <servlet-name>TestServlet</servlet-name>
+ <url-pattern>/TestServlet</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>ForwardedServlet</servlet-name>
+ <url-pattern>/ForwardedServlet</url-pattern>
+ </servlet-mapping>
+
+
+ <!-- ### Security -->
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>Restricted</web-resource-name>
+ <description>Declarative security tests</description>
+ <url-pattern>/restricted/*</url-pattern>
+ <http-method>HEAD</http-method>
+ <http-method>GET</http-method>
+ <http-method>POST</http-method>
+ <http-method>PUT</http-method>
+ <http-method>DELETE</http-method>
+ </web-resource-collection>
+ <auth-constraint>
+ <description>Only authenticated users can access secure content</description>
+ <role-name>AuthorizedUser</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>BASIC</auth-method>
+ <realm-name>JBossTest Servlets</realm-name>
+ </login-config>
+
+ <security-role>
+ <description>An AuthorizedUser is one with a valid username and password</description>
+ <role-name>AuthorizedUser</role-name>
+ </security-role>
+</web-app>
+
Added: branches/Branch_4_2/testsuite/src/resources/web/programmatic/application.xml
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/web/programmatic/application.xml (rev 0)
+++ branches/Branch_4_2/testsuite/src/resources/web/programmatic/application.xml 2007-03-14 16:09:52 UTC (rev 61327)
@@ -0,0 +1,15 @@
+<?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>Programmatic Web Login</display-name>
+
+ <module>
+ <web>
+ <web-uri>programmaticweblogin.war</web-uri>
+ </web>
+ </module>
+
+</application>
More information about the jboss-cvs-commits
mailing list