[jboss-cvs] JBossAS SVN: r70896 - in branches/JBPAPP_4_2_0_GA_CP/ejb3/src: test/org/jboss/ejb3/test/jaccpropagation and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sun Mar 16 16:02:49 EDT 2008
Author: bdecoste
Date: 2008-03-16 16:02:48 -0400 (Sun, 16 Mar 2008)
New Revision: 70896
Modified:
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jaccpropagation/WEB-INF/test-web.xml
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/Client.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/servlets/EJBServlet.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/unit/HttpUtils.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/unit/JaccPropagationTestCase.java
Log:
test for jacc propagation (work in progress)
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jaccpropagation/WEB-INF/test-web.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jaccpropagation/WEB-INF/test-web.xml 2008-03-16 19:36:25 UTC (rev 70895)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jaccpropagation/WEB-INF/test-web.xml 2008-03-16 20:02:48 UTC (rev 70896)
@@ -8,16 +8,16 @@
<description>EJB3 Servlet Access Test</description>
- <security-constraint>
- <web-resource-collection>
- <web-resource-name>Restricted</web-resource-name>
- <url-pattern>/*</url-pattern>
- </web-resource-collection>
- <auth-constraint>
- <role-name>allowed</role-name>
- </auth-constraint>
- </security-constraint>
+ <filter>
+ <filter-name>SecurityFilter</filter-name>
+ <filter-class>org.jboss.ejb3.test.jaccpropagation.servlets.SecurityFilter</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>SecurityFilter</filter-name>
+ <servlet-name>EJBServlet</servlet-name>
+ </filter-mapping>
+
<servlet>
<servlet-name>EJBServlet</servlet-name>
<servlet-class>org.jboss.ejb3.test.jaccpropagation.servlets.EJBServlet</servlet-class>
@@ -29,6 +29,16 @@
<url-pattern>/EJBServlet</url-pattern>
</servlet-mapping>
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>Restricted</web-resource-name>
+ <url-pattern>/*</url-pattern>
+ </web-resource-collection>
+ <auth-constraint>
+ <role-name>allowed</role-name>
+ </auth-constraint>
+ </security-constraint>
+
<security-role>
<role-name>allowed</role-name>
</security-role>
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/Client.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/Client.java 2008-03-16 19:36:25 UTC (rev 70895)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/Client.java 2008-03-16 20:02:48 UTC (rev 70896)
@@ -36,11 +36,12 @@
public class Client
{
private static final Logger log = Logger.getLogger(Client.class);
- private static final String SESSION_PRINCIPAL = "SessionPrincipal";
- private static final String SESSION_CREDENTIAL = "SessionCredential";
+ public static final String SESSION_PRINCIPAL = "SessionPrincipal";
+ public static final String SESSION_CREDENTIAL = "SessionCredential";
public static final String JAAS_MODE = "JAAS";
public static final String SA_MODE = "SA";
+ public static final String SIMPLE = "SIMPLE";
HttpServletRequest request;
@@ -54,6 +55,19 @@
this.request = request;
}
+ public String processSimple() throws Exception
+ {
+ log.info("!!! simple principal " + SecurityAssociation.getPrincipal());
+ log.info("!!! simple subject " + SecurityAssociation.getSubject());
+
+ InitialContext ctx = new InitialContext();
+ SessionRemote session = (SessionRemote)ctx.lookup("SessionBean/remote");
+
+ String result = session.testCustomPrincipal2();
+
+ return result;
+ }
+
public String processSecurityAssociationRequest() throws Exception
{
String result = "";
@@ -71,7 +85,6 @@
CustomPrincipalImpl customPrincipal = (CustomPrincipalImpl)SecurityAssociation.getPrincipal();
customPrincipal.setCustomRole("CustomRole1");
-
Subject newSubject = new Subject();
SecurityAssociation.pushSubjectContext(newSubject, customPrincipal, credential);
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/servlets/EJBServlet.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/servlets/EJBServlet.java 2008-03-16 19:36:25 UTC (rev 70895)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/servlets/EJBServlet.java 2008-03-16 20:02:48 UTC (rev 70896)
@@ -23,27 +23,15 @@
import java.io.IOException;
import java.io.PrintWriter;
-import java.security.Principal;
-import java.security.acl.Group;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-import javax.security.auth.Subject;
-
-import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jboss.ejb3.test.jaccpropagation.Client;
-import org.jboss.ejb3.test.jaccpropagation.CustomPrincipalImpl;
-import org.jboss.ejb3.test.jaccpropagation.SessionRemote;
import org.jboss.logging.Logger;
-import org.jboss.security.SecurityAssociation;
-import org.jboss.security.SimplePrincipal;
/**
* @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
@@ -56,14 +44,15 @@
throws ServletException, IOException
{
String result = "";
+ String mode = request.getParameter("mode");
try
{
- String mode = request.getParameter("mode");
-
Client client = new Client(request);
if (mode.equals(Client.JAAS_MODE))
result = client.processJaasRequest();
+ else if (mode.equals(Client.SIMPLE))
+ result = client.processSimple();
else
result = client.processSecurityAssociationRequest();
}
@@ -71,8 +60,9 @@
{
e.printStackTrace();
- throw new ServletException("Failed to call OptimizedEJB/Session30 through remote and local interfaces", e);
+ throw new ServletException("Failed to call propagate", e);
}
+
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/unit/HttpUtils.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/unit/HttpUtils.java 2008-03-16 19:36:25 UTC (rev 70895)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/unit/HttpUtils.java 2008-03-16 20:02:48 UTC (rev 70896)
@@ -83,6 +83,12 @@
{
return accessURL(url, "JBossTest Servlets", HttpURLConnection.HTTP_OK);
}
+
+ public static HttpMethodBase accessURL(URL url, URL url2) throws Exception
+ {
+ return accessURL(url, url2, "JBossTest Servlets", HttpURLConnection.HTTP_OK);
+ }
+
/** Perform a get on the indicated URL and assert that the response code
* matches the expectedHttpCode argument.
*
@@ -97,6 +103,14 @@
{
return accessURL(url, realm, expectedHttpCode, null);
}
+
+ public static HttpMethodBase accessURL(URL url, URL url2, String realm,
+ int expectedHttpCode)
+ throws Exception
+ {
+ return accessURL(url, url2, realm, expectedHttpCode, null);
+ }
+
public static HttpMethodBase accessURL(URL url, String realm,
int expectedHttpCode, int type)
throws Exception
@@ -109,6 +123,14 @@
{
return accessURL(url, realm, expectedHttpCode, hdrs, GET);
}
+
+ public static HttpMethodBase accessURL(URL url, URL url2, String realm,
+ int expectedHttpCode, Header[] hdrs)
+ throws Exception
+ {
+ return accessURL(url, url2, realm, expectedHttpCode, hdrs, GET);
+ }
+
public static HttpMethodBase accessURL(URL url, String realm,
int expectedHttpCode, Header[] hdrs, int type)
throws Exception
@@ -146,7 +168,74 @@
}
return request;
}
+
+ public static HttpMethodBase accessURL(URL url, URL url2, String realm,
+ int expectedHttpCode, Header[] hdrs, int type)
+ throws Exception
+ {
+ HttpClient httpConn = new HttpClient();
+ HttpMethodBase request = createMethod(url, type);
+
+ try
+ {
+ log.debug("Connecting to: "+url);
+ String userInfo = url.getUserInfo();
+ if( userInfo != null )
+ {
+ UsernamePasswordCredentials auth = new UsernamePasswordCredentials(userInfo);
+ httpConn.getState().setCredentials(realm, url.getHost(), auth);
+ }
+ log.debug("RequestURI: "+request.getURI());
+ int responseCode = httpConn.executeMethod(request);
+ String response = request.getStatusText();
+ System.out.println("responseCode="+responseCode+", response="+response);
+ // Validate that we are seeing the requested response code
+ if( responseCode != expectedHttpCode )
+ {
+ throw new IOException("Expected reply code:"+expectedHttpCode
+ +", actual="+responseCode);
+ }
+ }
+ catch(IOException e)
+ {
+ throw e;
+ }
+
+ HttpMethodBase request2 = createMethod(url2, type);
+
+ int hdrCount = hdrs != null ? hdrs.length : 0;
+ for(int n = 0; n < hdrCount; n ++)
+ request2.addRequestHeader(hdrs[n]);
+ try
+ {
+ log.debug("Connecting to: "+url2);
+ String userInfo = url2.getUserInfo();
+
+ if( userInfo != null )
+ {
+ UsernamePasswordCredentials auth = new UsernamePasswordCredentials(userInfo);
+ httpConn.getState().setCredentials(realm, url2.getHost(), auth);
+ }
+ log.debug("RequestURI: "+request2.getURI());
+ int responseCode2 = httpConn.executeMethod(request2);
+ String response2 = request2.getStatusText();
+ System.out.println("responseCode="+responseCode2+", response="+response2);
+ // Validate that we are seeing the requested response code
+ if( responseCode2 != expectedHttpCode )
+ {
+ throw new IOException("Expected reply code:"+expectedHttpCode
+ +", actual="+responseCode2);
+ }
+ }
+ catch(IOException e)
+ {
+ throw e;
+ }
+
+ return request2;
+ }
+
public static HttpMethodBase createMethod(URL url, int type)
{
HttpMethodBase request = null;
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/unit/JaccPropagationTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/unit/JaccPropagationTestCase.java 2008-03-16 19:36:25 UTC (rev 70895)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/unit/JaccPropagationTestCase.java 2008-03-16 20:02:48 UTC (rev 70896)
@@ -65,8 +65,9 @@
assertTrue((Boolean)server.getAttribute(tomcat, USE_JBOSS));
URL url = new URL(baseURL+"jaccpropagation/EJBServlet?mode=" + Client.SA_MODE);
- HttpMethodBase result = HttpUtils.accessURL(url);
-
+ URL url2 = new URL(baseURL+"jaccpropagation/EJBServlet?mode=" + Client.SIMPLE);
+ HttpMethodBase result = HttpUtils.accessURL(url, url2);
+
String content = result.getResponseBodyAsString();
System.out.println(content);
More information about the jboss-cvs-commits
mailing list