User: starksm
Date: 01/07/14 09:02:43
Modified: src/main/org/jboss/test/security/ejb EntityBeanImpl.java
Log:
Move security and perf AppCallbackHandler.java to util and import it
from there
Revision Changes Path
1.4 +116 -68
jbosstest/src/main/org/jboss/test/security/ejb/EntityBeanImpl.java
Index: EntityBeanImpl.java
===================================================================
RCS file:
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/security/ejb/EntityBeanImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- EntityBeanImpl.java 2001/07/11 08:30:34 1.3
+++ EntityBeanImpl.java 2001/07/14 16:02:43 1.4
@@ -1,68 +1,116 @@
-package org.jboss.test.security.ejb;
-
-import java.rmi.RemoteException;
-import java.security.Principal;
-import javax.ejb.*;
-
-/** A BMP entity bean that creates beans on the fly with
-a key equal to that passed to findByPrimaryKey. Obviously
-not a real entity bean. It is used to test Principal propagation
-using the echo method.
-
-@author [EMAIL PROTECTED]
-@version $Revision: 1.3 $
-*/
-public class EntityBeanImpl implements EntityBean
-{
- private String key;
- private EntityContext context;
-
- public void ejbActivate()
- {
- System.out.println("EntityBean.ejbActivate() called");
- }
-
- public void ejbPassivate()
- {
- System.out.println("EntityBean.ejbPassivate() called");
- }
-
- public void ejbRemove()
- {
- System.out.println("EntityBean.ejbRemove() called");
- }
- public void ejbLoad()
- {
- System.out.println("EntityBean.ejbLoad() called");
- key = (String) context.getPrimaryKey();
- }
- public void ejbStore()
- {
- System.out.println("EntityBean.ejbStore() called");
- }
-
- public void setEntityContext(EntityContext context)
- {
- this.context = context;
- }
- public void unsetEntityContext()
- {
- this.context = null;
- }
-
- public String echo(String arg)
- {
- System.out.println("EntityBean.echo, arg="+arg);
- Principal p = context.getCallerPrincipal();
- boolean isInternalRole = context.isCallerInRole("InternalRole");
- System.out.println("EntityBean.echo, callerPrincipal="+p);
- System.out.println("EntityBean.echo,
isCallerInRole('InternalRole')="+isInternalRole);
- return p.getName();
- }
-
- public String ejbFindByPrimaryKey(String key)
- {
- System.out.println("EntityBean.ejbFindByPrimaryKey, key="+key);
- return key;
- }
-}
+package org.jboss.test.security.ejb;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
+import java.rmi.RemoteException;
+import java.security.Principal;
+import javax.ejb.EJBException;
+import javax.ejb.EntityBean;
+import javax.ejb.EntityContext;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.security.auth.Subject;
+
+/** A BMP entity bean that creates beans on the fly with
+a key equal to that passed to findByPrimaryKey. Obviously
+not a real entity bean. It is used to test Principal propagation
+using the echo method.
+
+@author [EMAIL PROTECTED]
+@version $Revision: 1.4 $
+*/
+public class EntityBeanImpl implements EntityBean
+{
+ private String key;
+ private EntityContext context;
+
+ public void ejbActivate()
+ {
+ System.out.println("EntityBean.ejbActivate() called");
+ }
+
+ public void ejbPassivate()
+ {
+ System.out.println("EntityBean.ejbPassivate() called");
+ }
+
+ public void ejbRemove()
+ {
+ System.out.println("EntityBean.ejbRemove() called");
+ }
+ public void ejbLoad()
+ {
+ System.out.println("EntityBean.ejbLoad() called");
+ key = (String) context.getPrimaryKey();
+ }
+ public void ejbStore()
+ {
+ System.out.println("EntityBean.ejbStore() called");
+ }
+
+ public void setEntityContext(EntityContext context)
+ {
+ this.context = context;
+ }
+ public void unsetEntityContext()
+ {
+ this.context = null;
+ }
+
+ public String echo(String arg)
+ {
+ System.out.println("EntityBean.echo, arg="+arg);
+ Principal p = context.getCallerPrincipal();
+ boolean isInternalRole = context.isCallerInRole("InternalRole");
+ System.out.println("EntityBean.echo, callerPrincipal="+p);
+ System.out.println("EntityBean.echo,
isCallerInRole('InternalRole')="+isInternalRole);
+ // Check the java:comp/env/security/security-domain
+ try
+ {
+ InitialContext ctx = new InitialContext();
+ Object securityMgr =
ctx.lookup("java:comp/env/security/security-domain");
+ System.out.println("Checking java:comp/env/security/security-domain");
+ if( securityMgr == null )
+ throw new EJBException("Failed to find security mgr under:
java:comp/env/security/security-domain");
+ System.out.println("Found SecurityManager: "+securityMgr);
+ /* I'm using this runtime introspection to determin if the security
+ manager supports a getActiveSubject() method because the
+ org.jboss.security.SubjectSecurityManager interface is not part of
+ the standard client jars which are used to build the jbosstest suite.
+ Not legal EJB code, but this is test code.
+ */
+ Class securityMgrClass = securityMgr.getClass();
+ Class[] parameterTypes = {};
+ Method getActiveSubject =
securityMgrClass.getDeclaredMethod("getActiveSubject", parameterTypes);
+ Object[] args = {};
+ Subject activeSubject = (Subject) getActiveSubject.invoke(securityMgr,
args);
+ System.out.println("ActiveSubject: "+activeSubject);
+ if( activeSubject == null )
+ throw new EJBException("No ActiveSubject found");
+ }
+ catch(NoSuchMethodException e)
+ {
+ // Ok, not a SubjectSecurityManager
+ }
+ catch(InvocationTargetException e)
+ {
+ // Ok, not a SubjectSecurityManager
+ }
+ catch(IllegalAccessException e)
+ {
+ // Ok, not a SubjectSecurityManager
+ }
+ catch(NamingException e)
+ {
+ e.printStackTrace();
+ throw new EJBException("Naming exception: "+e.toString(true));
+ }
+ return p.getName();
+ }
+
+ public String ejbFindByPrimaryKey(String key)
+ {
+ System.out.println("EntityBean.ejbFindByPrimaryKey, key="+key);
+ return key;
+ }
+}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development