[jboss-cvs] JBossAS SVN: r83155 - in branches/JBPAPP_4_2_0_GA_CP/ejb3: src/resources/test and 9 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jan 21 10:56:26 EST 2009
Author: wolfc
Date: 2009-01-21 10:56:26 -0500 (Wed, 21 Jan 2009)
New Revision: 83155
Added:
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp584/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp584/META-INF/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp584/META-INF/jboss-service.xml
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp584/META-INF/login-config.xml
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp584/web/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp584/web/WEB-INF/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp584/web/WEB-INF/jboss-web.xml
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp584/web/WEB-INF/web.xml
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp584/web/index.jsp
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/DynamicViewBean.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/DynamicViewRemote.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/jaas/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/jaas/MyLoginModule.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/jaas/MyPrincipal.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/unit/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/unit/DynamicSecurityUnitTestCase.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/web/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/web/MyServlet.java
Modified:
branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml
Log:
JBPAPP-584: unit test
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml 2009-01-21 13:55:52 UTC (rev 83154)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml 2009-01-21 15:56:26 UTC (rev 83155)
@@ -2097,6 +2097,32 @@
<build-simple-jar name="jbas4489"/>
</target>
+ <target name="jbpapp584" depends="compile-classes">
+ <mkdir dir="${build.lib}"/>
+
+ <jar jarfile="${build.lib}/jbpapp584-jaas.sar">
+ <fileset dir="${build.classes}">
+ <include name="org/jboss/ejb3/test/jbpapp584/jaas/*.class"/>
+ </fileset>
+ <fileset dir="${resources}/test/jbpapp584" includes="META-INF/*.xml"/>
+ </jar>
+
+ <jar jarfile="${build.lib}/jbpapp584.jar">
+ <fileset dir="${build.classes}">
+ <include name="org/jboss/ejb3/test/jbpapp584/*.class"/>
+ </fileset>
+ <!-- fileset dir="${resources}/test/jbpapp584"/ -->
+ </jar>
+
+ <jar jarfile="${build.lib}/jbpapp584.war">
+ <fileset dir="${build.classes}">
+ <include name="org/jboss/ejb3/test/jbpapp584/web/*.class"/>
+ </fileset>
+ <fileset dir="${resources}/test/jbpapp584/web"/>
+ </jar>
+
+ </target>
+
<target name="jbpapp999" depends="compile-classes">
<mkdir dir="${build.lib}"/>
@@ -3830,6 +3856,7 @@
ejbthree1109,
ejbthree1239,
ejbthree1504,
+ jbpapp584,
jbpapp999,
jbpapp1186,
jbpapp1224,
@@ -4466,6 +4493,9 @@
<param name="test" value="jbas4489"/>
</antcall>
<antcall target="test" inheritRefs="true">
+ <param name="test" value="jbpapp584"/>
+ </antcall>
+ <antcall target="test" inheritRefs="true">
<param name="test" value="jbpapp999"/>
</antcall>
<antcall target="test" inheritRefs="true">
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp584/META-INF/jboss-service.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp584/META-INF/jboss-service.xml (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp584/META-INF/jboss-service.xml 2009-01-21 15:56:26 UTC (rev 83155)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<server>
+ <mbean code="org.jboss.security.auth.login.DynamicLoginConfig"
+ name="jboss.jbpapp584:service=DynamicLoginConfig">
+ <attribute name="AuthConfig">META-INF/login-config.xml</attribute>
+ <!-- The service which supports dynamic processing of login-config.xml
+ configurations.
+ -->
+ <depends optional-attribute-name="LoginConfigService">
+ jboss.security:service=XMLLoginConfig
+ </depends>
+ <!-- Optionally specify the security mgr service to use when
+ this service is stopped to flush the auth caches of the domains
+ registered by this service.
+ -->
+ <depends optional-attribute-name="SecurityManagerService">
+ jboss.security:service=JaasSecurityManager
+ </depends>
+ </mbean>
+</server>
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp584/META-INF/login-config.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp584/META-INF/login-config.xml (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp584/META-INF/login-config.xml 2009-01-21 15:56:26 UTC (rev 83155)
@@ -0,0 +1,13 @@
+<?xml version='1.0'?>
+<!DOCTYPE policy PUBLIC
+ "-//JBoss//DTD JBOSS Security Config 3.0//EN"
+ "http://www.jboss.org/j2ee/dtd/security_config.dtd">
+<policy>
+ <application-policy name="jbpapp584">
+ <authentication>
+ <login-module flag="required" code="org.jboss.ejb3.test.jbpapp584.jaas.MyLoginModule">
+ <module-option name ="principalClass">org.jboss.ejb3.test.jbpapp584.jaas.MyPrincipal</module-option>
+ </login-module>
+ </authentication>
+ </application-policy>
+</policy>
\ No newline at end of file
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp584/web/WEB-INF/jboss-web.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp584/web/WEB-INF/jboss-web.xml (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp584/web/WEB-INF/jboss-web.xml 2009-01-21 15:56:26 UTC (rev 83155)
@@ -0,0 +1,8 @@
+<?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>java:/jaas/jbpapp584</security-domain>
+</jboss-web>
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp584/web/WEB-INF/web.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp584/web/WEB-INF/web.xml (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp584/web/WEB-INF/web.xml 2009-01-21 15:56:26 UTC (rev 83155)
@@ -0,0 +1,36 @@
+<?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">
+
+ <servlet>
+ <servlet-name>MyServlet</servlet-name>
+ <servlet-class>org.jboss.ejb3.test.jbpapp584.web.MyServlet</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>MyServlet</servlet-name>
+ <url-pattern>/MyServlet</url-pattern>
+ </servlet-mapping>
+
+ <login-config>
+ <auth-method>BASIC</auth-method>
+ </login-config>
+
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>servlet</web-resource-name>
+ <url-pattern>/MyServlet</url-pattern>
+ </web-resource-collection>
+ <auth-constraint>
+ <role-name>User</role-name>
+ </auth-constraint>
+ </security-constraint>
+
+ <security-role>
+ <role-name>User</role-name>
+ </security-role>
+</web-app>
\ No newline at end of file
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp584/web/index.jsp
===================================================================
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/DynamicViewBean.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/DynamicViewBean.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/DynamicViewBean.java 2009-01-21 15:56:26 UTC (rev 83155)
@@ -0,0 +1,71 @@
+/*
+ * 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.ejb3.test.jbpapp584;
+
+import java.security.Principal;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.Resource;
+import javax.annotation.security.RolesAllowed;
+import javax.ejb.Remote;
+import javax.ejb.SessionContext;
+import javax.ejb.Stateless;
+
+import org.jboss.annotation.security.SecurityDomain;
+import org.jboss.ejb3.test.jbpapp584.jaas.MyPrincipal;
+
+/**
+ * Based on the option specified in the custom principal you'll see different results.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateless
+ at SecurityDomain("jbpapp584")
+ at RolesAllowed("User")
+ at Remote(DynamicViewRemote.class)
+public class DynamicViewBean implements DynamicViewRemote
+{
+ @Resource
+ private SessionContext ctx;
+
+ public String[] getResults()
+ {
+ Principal caller = ctx.getCallerPrincipal();
+ List<String> list = new ArrayList<String>();
+ list.add(caller.getClass().getName());
+ list.add(caller.getName());
+ if(ctx.isCallerInRole("User"))
+ list.add("User");
+ if(ctx.isCallerInRole("Manager"))
+ list.add("Manager");
+ if(caller instanceof MyPrincipal)
+ {
+ MyPrincipal p = (MyPrincipal) caller;
+ String option = p.getOption();
+ if(option != null)
+ list.add(option);
+ }
+ return list.toArray(new String[0]);
+ }
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/DynamicViewRemote.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/DynamicViewRemote.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/DynamicViewRemote.java 2009-01-21 15:56:26 UTC (rev 83155)
@@ -0,0 +1,31 @@
+/*
+ * 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.ejb3.test.jbpapp584;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface DynamicViewRemote
+{
+ String[] getResults();
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/jaas/MyLoginModule.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/jaas/MyLoginModule.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/jaas/MyLoginModule.java 2009-01-21 15:56:26 UTC (rev 83155)
@@ -0,0 +1,95 @@
+/*
+ * 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.ejb3.test.jbpapp584.jaas;
+
+import java.security.Principal;
+import java.security.acl.Group;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.login.LoginException;
+
+import org.jboss.security.SimpleGroup;
+import org.jboss.security.auth.spi.UsernamePasswordLoginModule;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MyLoginModule extends UsernamePasswordLoginModule
+{
+ private void addMemberOrWarn(Group group, String name)
+ {
+ Principal p = createIdentityOrWarn(name);
+ if(p != null)
+ group.addMember(p);
+ }
+
+ private Principal createIdentityOrWarn(String username)
+ {
+ try
+ {
+ return createIdentity(username);
+ }
+ catch(Exception e)
+ {
+ log.warn("Failed to create identity for '" + username + "'", e);
+ return null;
+ }
+ }
+
+ @Override
+ protected String getUsersPassword() throws LoginException
+ {
+ return "jbpapp584";
+ }
+
+ @Override
+ protected Group[] getRoleSets() throws LoginException
+ {
+ String username = getUsername();
+ List<Group> groups = new ArrayList<Group>();
+ Group rolesGroup = new SimpleGroup("Roles");
+ groups.add(rolesGroup);
+
+ addMemberOrWarn(rolesGroup, username);
+ addMemberOrWarn(rolesGroup, "User");
+
+ // http://www.jboss.org/community/docs/DOC-12517
+ Group callerPrincipal = new SimpleGroup("CallerPrincipal");
+ groups.add(callerPrincipal);
+ callerPrincipal.addMember(getIdentity());
+
+ return groups.toArray(new Group[0]);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options)
+ {
+ super.initialize(subject, callbackHandler, sharedState, options);
+ }
+
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/jaas/MyPrincipal.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/jaas/MyPrincipal.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/jaas/MyPrincipal.java 2009-01-21 15:56:26 UTC (rev 83155)
@@ -0,0 +1,53 @@
+/*
+ * 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.ejb3.test.jbpapp584.jaas;
+
+import org.jboss.security.SimplePrincipal;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MyPrincipal extends SimplePrincipal
+{
+ private static final long serialVersionUID = 1L;
+
+ private String option;
+
+ /**
+ * @param name
+ */
+ public MyPrincipal(String name)
+ {
+ super(name);
+ }
+
+ public String getOption()
+ {
+ return option;
+ }
+
+ public void setOption(String option)
+ {
+ this.option = option;
+ }
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/unit/DynamicSecurityUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/unit/DynamicSecurityUnitTestCase.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/unit/DynamicSecurityUnitTestCase.java 2009-01-21 15:56:26 UTC (rev 83155)
@@ -0,0 +1,109 @@
+/*
+ * 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.ejb3.test.jbpapp584.unit;
+
+import javax.servlet.http.HttpServletResponse;
+
+import junit.framework.Test;
+
+import org.apache.commons.httpclient.Cookie;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpURL;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.jboss.test.JBossTestCase;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class DynamicSecurityUnitTestCase extends JBossTestCase
+{
+ public DynamicSecurityUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * A simple sanity test.
+ */
+ public void test1() throws Exception
+ {
+ HttpClient client = new HttpClient();
+ client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("Test", "jbpapp584"));
+ String host = System.getProperty("jboss.bind.address", "localhost");
+ GetMethod method = new GetMethod("http://" + host + ":8080/jbpapp584/MyServlet?option=A");
+ int responseCode = client.executeMethod(method);
+ String actual = method.getResponseBodyAsString();
+ method.releaseConnection();
+
+ assertEquals("Http request failed " + actual, HttpServletResponse.SC_OK, responseCode);
+
+ String expected = "org.jboss.ejb3.test.jbpapp584.jaas.MyPrincipal\r\nTest\r\nUser\r\nA\r\n";
+ assertEquals(expected, actual);
+ }
+
+ /**
+ * Make sure that we can switch options in one session.
+ */
+ public void testSwitchOption() throws Exception
+ {
+ HttpClient client = new HttpClient();
+ client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("Bill", "jbpapp584"));
+ String host = System.getProperty("jboss.bind.address", "localhost");
+ GetMethod method = new GetMethod();
+ // do work on company A
+ {
+ method.setURI(new HttpURL("http://" + host + ":8080/jbpapp584/MyServlet?option=CompanyA"));
+ int responseCode = client.executeMethod(method);
+ String actual = method.getResponseBodyAsString();
+
+ assertEquals("Http request failed " + actual, HttpServletResponse.SC_OK, responseCode);
+
+ String expected = "org.jboss.ejb3.test.jbpapp584.jaas.MyPrincipal\r\nBill\r\nUser\r\nCompanyA\r\n";
+ assertEquals(expected, actual);
+ }
+ // make sure we're in a HttpSession
+ Cookie cookies[] = client.getState().getCookies();
+ assertEquals(1, cookies.length);
+ Cookie cookie = cookies[0];
+ assertEquals("JSESSIONID", cookie.getName());
+ // do work on company B
+ {
+ method.setURI(new HttpURL("http://" + host + ":8080/jbpapp584/MyServlet?option=CompanyB"));
+ int responseCode = client.executeMethod(method);
+ String actual = method.getResponseBodyAsString();
+
+ assertEquals("Http request failed " + actual, HttpServletResponse.SC_OK, responseCode);
+
+ String expected = "org.jboss.ejb3.test.jbpapp584.jaas.MyPrincipal\r\nBill\r\nUser\r\nCompanyB\r\n";
+ assertEquals(expected, actual);
+ }
+ method.releaseConnection();
+ }
+
+ public static Test suite() throws Exception
+ {
+ return getDeploySetup(DynamicSecurityUnitTestCase.class, "jbpapp584-jaas.sar,jbpapp584.jar,jbpapp584.war");
+ }
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/web/MyServlet.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/web/MyServlet.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/web/MyServlet.java 2009-01-21 15:56:26 UTC (rev 83155)
@@ -0,0 +1,93 @@
+/*
+ * 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.ejb3.test.jbpapp584.web;
+
+import java.io.IOException;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.servlet.ServletException;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.jboss.ejb3.test.jbpapp584.DynamicViewRemote;
+import org.jboss.ejb3.test.jbpapp584.jaas.MyPrincipal;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MyServlet extends HttpServlet
+{
+ private static final long serialVersionUID = 1L;
+
+ private DynamicViewRemote bean;
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+ {
+ // create a session for recurring visits
+ req.getSession();
+
+ resp.setContentType("text/plain");
+ ServletOutputStream out = resp.getOutputStream();
+
+ // do a blatant cast and ignore the consequences
+ MyPrincipal p = (MyPrincipal) req.getUserPrincipal();
+
+ String option = req.getParameter("option");
+ p.setOption(option);
+
+ String results[] = bean.getResults();
+ for(String result : results)
+ {
+ out.println(result);
+ }
+
+ out.flush();
+ }
+
+ @Override
+ public void init() throws ServletException
+ {
+ super.init();
+
+ try
+ {
+ InitialContext ctx = new InitialContext();
+ try
+ {
+ bean = (DynamicViewRemote) ctx.lookup("DynamicViewBean/remote");
+ }
+ finally
+ {
+ ctx.close();
+ }
+ }
+ catch(NamingException e)
+ {
+ throw new ServletException(e);
+ }
+ }
+}
More information about the jboss-cvs-commits
mailing list