[jboss-cvs] JBossAS SVN: r70579 - in branches/JBPAPP_4_2_0_GA_CP/ejb3/src: test/org/jboss/ejb3/test/jaccpropagation and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat Mar 8 10:27:02 EST 2008
Author: bdecoste
Date: 2008-03-08 10:27:02 -0500 (Sat, 08 Mar 2008)
New Revision: 70579
Modified:
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test-configs/jaccpropagation/conf/login-config.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/CustomLoginModule.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/CustomPrincipalImpl.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/SessionBean.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-configs/jaccpropagation/conf/login-config.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test-configs/jaccpropagation/conf/login-config.xml 2008-03-08 12:50:32 UTC (rev 70578)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test-configs/jaccpropagation/conf/login-config.xml 2008-03-08 15:27:02 UTC (rev 70579)
@@ -149,7 +149,9 @@
<application-policy name = "custom">
<authentication>
<login-module code = "org.jboss.ejb3.test.jaccpropagation.CustomLoginModule"
- flag = "required" />
+ flag = "required">
+ <module-option name = "principalClass">org.jboss.ejb3.test.jaccpropagation.CustomPrincipalImpl</module-option>
+ </login-module>
</authentication>
</application-policy>
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-08 12:50:32 UTC (rev 70578)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/Client.java 2008-03-08 15:27:02 UTC (rev 70579)
@@ -49,27 +49,49 @@
InitialContext ctx = new InitialContext();
SessionRemote session = (SessionRemote)ctx.lookup("SessionBean/remote");
+
+ log.info("!!! initial principal " + SecurityAssociation.getPrincipal());
+ log.info("!!! initial subject " + SecurityAssociation.getSubject());
- CustomPrincipalImpl principal = new CustomPrincipalImpl("somebody");
- principal.setCustom("");
+ CustomPrincipalImpl customPrincipal = new CustomPrincipalImpl("somebody");
+ customPrincipal.setCustomRole("CustomRole1");
Object credential = "password".toCharArray();
- Subject subject = new Subject();
+ java.util.Set<java.security.Principal> principalsSet = new java.util.HashSet<java.security.Principal>();
+ principalsSet.add(customPrincipal);
- SecurityAssociation.pushSubjectContext(subject, principal, credential);
+ Subject activeSubject = SecurityAssociation.getSubject();
+ Subject newSubject = new Subject(); //false, principalsSet, activeSubject.getPublicCredentials(), activeSubject.getPrivateCredentials());
- session.testCustomPrincipal();
+ log.info("!!! newSubject " + newSubject);
- Subject activeSubject = SecurityAssociation.getSubject();
+ SecurityAssociation.pushSubjectContext(newSubject, customPrincipal, credential);
+
+ log.info("!!! before principal " + SecurityAssociation.getPrincipal());
+ log.info("!!! before subject " + SecurityAssociation.getSubject() + " " + SecurityAssociation.getSubject().getPrincipals());
+
+ result = session.testCustomPrincipal();
+
+ log.info("!!! after principal " + SecurityAssociation.getPrincipal());
+ log.info("!!! after subject " + SecurityAssociation.getSubject());
+
+ activeSubject = SecurityAssociation.getSubject();
- CustomPrincipalImpl customPrincipal = new CustomPrincipalImpl("somebody");
- customPrincipal.setCustom("custom");
+ customPrincipal.setCustomRole("CustomRole2");
- Subject newSubject = new Subject();
+ newSubject = new Subject(); //false, principalsSet, activeSubject.getPublicCredentials(), activeSubject.getPrivateCredentials());
+
+ log.info("!!! newSubject " + newSubject);
SecurityAssociation.pushSubjectContext(newSubject, customPrincipal, credential);
+ log.info("!!! before principal " + SecurityAssociation.getPrincipal());
+ log.info("!!! before subject " + SecurityAssociation.getSubject());
+
result = session.testCustomPrincipal();
+
+ log.info("!!! after principal " + SecurityAssociation.getPrincipal());
+ log.info("!!! after subject " + SecurityAssociation.getSubject());
return result;
}
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/CustomLoginModule.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/CustomLoginModule.java 2008-03-08 12:50:32 UTC (rev 70578)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/CustomLoginModule.java 2008-03-08 15:27:02 UTC (rev 70579)
@@ -84,14 +84,9 @@
protected Principal createIdentity(String username)
throws Exception
{
- if (getCallbackPrincipal() != null)
- {
- return getCallbackPrincipal();
- }
- else
- {
- return super.createIdentity(username);
- }
+ Principal principal = super.createIdentity(username);
+
+ return principal;
}
protected Principal getIdentity()
@@ -123,7 +118,18 @@
protected Group[] getRoleSets() throws LoginException
{
- return super.getRoleSets();
+ Group[] groups = super.getRoleSets();
+
+ for (Group group : groups)
+ {
+ if (group.getName().equals("Roles"))
+ {
+ CustomPrincipalImpl customPrincipal = (CustomPrincipalImpl)getIdentity();
+ group.addMember(new CustomPrincipalImpl(customPrincipal.getCustomRole()));
+ }
+ }
+
+ return groups;
}
protected boolean getUseFirstPass()
@@ -140,6 +146,8 @@
protected Group createGroup(String name, Set principals)
{
- return super.createGroup(name, principals);
+ Group group = super.createGroup(name, principals);
+
+ return group;
}
}
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/CustomPrincipalImpl.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/CustomPrincipalImpl.java 2008-03-08 12:50:32 UTC (rev 70578)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/CustomPrincipalImpl.java 2008-03-08 15:27:02 UTC (rev 70579)
@@ -32,7 +32,7 @@
{
private String name;
- private String custom;
+ private String customRole;
public CustomPrincipalImpl(String name)
{
@@ -52,7 +52,7 @@
public String toString()
{
- return this.getClass() + ":" + name + ":" + custom;
+ return this.getClass() + ":" + name + ":" + customRole;
}
public String getName()
@@ -60,13 +60,13 @@
return name;
}
- public String getCustom()
+ public String getCustomRole()
{
- return custom;
+ return customRole;
}
- public void setCustom(String custom)
+ public void setCustomRole(String customRole)
{
- this.custom = custom;
+ this.customRole = customRole;
}
}
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/SessionBean.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/SessionBean.java 2008-03-08 12:50:32 UTC (rev 70578)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/SessionBean.java 2008-03-08 15:27:02 UTC (rev 70579)
@@ -27,6 +27,7 @@
import java.util.Set;
import java.util.Iterator;
+import javax.annotation.security.RolesAllowed;
import javax.ejb.Remote;
import javax.ejb.Stateless;
@@ -48,6 +49,7 @@
{
private static final Logger log = Logger.getLogger(SessionBean.class);
+ @RolesAllowed({"CustomRole1", "CustomRole2"})
public String testCustomPrincipal() throws Exception
{
String result = "";
@@ -56,9 +58,14 @@
Principal principal = SecurityAssociation.getPrincipal();
if (principal != null)
- log.info(" SA " + principal.getClass() + " " + principal);
+ log.info(" SA Principal " + principal.getClass() + " " + principal);
- Subject subject = (Subject) PolicyContext.getContext("javax.security.auth.Subject.container");
+
+ Subject subject = SecurityAssociation.getSubject();
+ if (subject != null)
+ log.info(" SA Subject " + subject);
+
+ subject = (Subject) PolicyContext.getContext("javax.security.auth.Subject.container");
Set<Principal> principalSet = subject.getPrincipals();
Iterator<Principal> principalIter = principalSet.iterator();
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-08 12:50:32 UTC (rev 70578)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jaccpropagation/unit/JaccPropagationTestCase.java 2008-03-08 15:27:02 UTC (rev 70579)
@@ -70,7 +70,7 @@
String content = result.getResponseBodyAsString();
System.out.println(content);
- assertTrue(content.contains("somebody:custom"));
+ assertTrue(content.contains("somebody:CustomRole2"));
}
finally
{
@@ -78,7 +78,7 @@
}
}
- public void testLocalJaasPropagation() throws Exception
+ public void atestLocalJaasPropagation() throws Exception
{
MBeanServerConnection server = getServer();
ObjectName tomcat = new ObjectName("jboss.web:service=WebServer");
@@ -94,7 +94,7 @@
String content = result.getResponseBodyAsString();
System.out.println(content);
- assertTrue(content.contains("somebody:custom"));
+ assertTrue(content.contains("somebody:CustomRole2"));
}
finally
{
@@ -102,7 +102,7 @@
}
}
- public void testRemoteSAPropagation() throws Exception
+ public void atestRemoteSAPropagation() throws Exception
{
String result = Client.processSecurityAssociationRequest();
@@ -111,7 +111,7 @@
assertTrue(result.contains("somebody:custom"));
}
- public void testRemoteJaasPropagation() throws Exception
+ public void atestRemoteJaasPropagation() throws Exception
{
String result = Client.processJaasRequest();
More information about the jboss-cvs-commits
mailing list