[jboss-cvs] jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/security/ex1 ...
Norman Richards
norman.richards at jboss.com
Wed Nov 1 13:14:20 EST 2006
User: nrichards
Date: 06/11/01 13:14:20
Added: jbossas/j2ee/examples/src/main/org/jboss/book/security/ex1
Echo.java EchoBean.java EchoHome.java
EchoSecurityProxy.java ExClient.java ejb-jar.xml
jboss-service.xml jboss.xml roles.properties
users.properties
Log:
modified for j2ee guide
Revision Changes Path
1.1 date: 2006/11/01 18:14:20; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/security/ex1/Echo.java
Index: Echo.java
===================================================================
package org.jboss.book.security.ex1;
import java.rmi.RemoteException;
import javax.ejb.EJBObject;
/**
*
* @author Scott.Stark at jboss.org
* @version $Revision: 1.1 $
*/
public interface Echo extends EJBObject
{
public String echo(String arg) throws RemoteException;
}
1.1 date: 2006/11/01 18:14:20; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/security/ex1/EchoBean.java
Index: EchoBean.java
===================================================================
package org.jboss.book.security.ex1;
import java.rmi.RemoteException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.naming.Context;
import org.apache.log4j.Category;
public class EchoBean implements SessionBean
{
private static final Category log = Category.getInstance(EchoBean.class);
private SessionContext sessionCtx;
public void ejbCreate()
{
log.debug("ejbCreate: ");
}
public void ejbLoad()
{
log.debug("ejbLoad");
}
public void ejbRemove()
{
log.debug("ejbRemove");
}
public void ejbStore()
{
log.debug("ejbStore");
}
public void setSessionContext(SessionContext context)
{
sessionCtx = context;
log.debug("setSessionContext");
}
public void unsetSessionContext()
{
sessionCtx = null;
log.debug("unsetSessionContext");
}
public void ejbActivate()
{
log.debug("ejbActivate");
}
public void ejbPassivate()
{
log.debug("ejbPassivate");
}
public String echo(String arg)
{
log.debug("echo, arg="+arg);
return arg;
}
}
1.1 date: 2006/11/01 18:14:20; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/security/ex1/EchoHome.java
Index: EchoHome.java
===================================================================
package org.jboss.book.security.ex1;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
/**
*
* @author Scott.Stark at jboss.org
* @version $Revision: 1.1 $
*/
public interface EchoHome extends EJBHome
{
public Echo create()
throws RemoteException, CreateException;
}
1.1 date: 2006/11/01 18:14:20; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/security/ex1/EchoSecurityProxy.java
Index: EchoSecurityProxy.java
===================================================================
package org.jboss.book.security.ex1;
import java.lang.reflect.Method;
import javax.ejb.EJBContext;
import org.apache.log4j.Category;
import org.jboss.security.SecurityProxy;
/**
* A simple example of a custom SecurityProxy implementation that
* demonstrates method argument based security checks.
*
* @author Scott.Stark at jboss.org
* @version $Revision: 1.1 $
*/
public class EchoSecurityProxy
implements SecurityProxy
{
Category log = Category.getInstance(EchoSecurityProxy.class);
Method echo;
public void init(Class beanHome, Class beanRemote,
Object securityMgr)
throws InstantiationException
{
init(beanHome, beanRemote, null, null, securityMgr);
}
public void init(Class beanHome, Class beanRemote,
Class beanLocalHome, Class beanLocal, Object securityMgr)
throws InstantiationException
{
log.debug("init, beanHome=" + beanHome + ", beanRemote=" + beanRemote +
", beanLocalhome=" + beanLocalHome + ", beanLocal=" + beanLocal +
", securityMgr=" + securityMgr);
// Get the echo method for equality testing in invoke
try {
Class[] params = {String.class};
echo = beanRemote.getDeclaredMethod("echo", params);
} catch(Exception e) {
String msg = "Failed to find an echo(String) method";
log.error(msg, e);
throw new InstantiationException(msg);
}
}
public void setEJBContext(EJBContext ctx)
{
log.debug("setEJBContext, ctx=" + ctx);
}
public void invokeHome(Method m, Object[] args)
throws SecurityException
{
// We don't validate access to home methods
}
public void invoke(Method m, Object[] args, Object bean)
throws SecurityException
{
log.debug("invoke, m=" + m);
// Check for the echo method
if (m.equals(echo)) {
// Validate that the msg arg is not 4 letter word
String arg = (String) args[0];
if (arg == null || arg.length() == 4) {
throw new SecurityException("No 4 letter words");
}
// We are not responsible for doing the invoke
}
}
}
1.1 date: 2006/11/01 18:14:20; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/security/ex1/ExClient.java
Index: ExClient.java
===================================================================
package org.jboss.book.security.ex1;
import javax.naming.InitialContext;
import org.apache.log4j.Logger;
/**
; * @author Scott.Stark at jboss.org
* @version $Revision: 1.1 $
*/
public class ExClient
{
public static void main(String args[])
throws Exception
{
Logger log = Logger.getLogger("ExClient");
log.info("Looking up EchoBean");
InitialContext iniCtx = new InitialContext();
Object ref = iniCtx.lookup("security.EchoBean");
EchoHome home = (EchoHome) ref;
Echo echo = home.create();
log.info("Created Echo");
log.info("Echo.echo('Hello') = " + echo.echo("Hello"));
log.info("Echo.echo('Four') = " + echo.echo("Four"));
}
}
1.1 date: 2006/11/01 18:14:20; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/security/ex1/ejb-jar.xml
Index: ejb-jar.xml
===================================================================
<?xml version="1.0"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
"http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>EchoBean</ejb-name>
<home>org.jboss.book.security.ex1.EchoHome</home>
<remote>org.jboss.book.security.ex1.Echo</remote>
<ejb-class>org.jboss.book.security.ex1.EchoBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor>
<method-permission>
<unchecked/>
<method>
<ejb-name>EchoBean</ejb-name>
<method-name>*</method-name>
</method>
</method-permission>
</assembly-descriptor>
</ejb-jar>
1.1 date: 2006/11/01 18:14:20; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/security/ex1/jboss-service.xml
Index: jboss-service.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<server>
<!-- The custom JAAS login configuration that installs
a Configuration capable of dynamically updating the
config settings
-->
<mbean code="org.jboss.book.security.service.SecurityConfig"
name="jboss.docs.security:service=LoginConfig-EX1">
<attribute name="AuthConfig">META-INF/login-config.xml</attribute>
<attribute name="SecurityConfigName">jboss.security:service=XMLLoginConfig</attribute>
</mbean>
</server>
1.1 date: 2006/11/01 18:14:20; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/security/ex1/jboss.xml
Index: jboss.xml
===================================================================
<?xml version="1.0"?>
<jboss>
<security-domain>java:/jaas/security-ex1</security-domain>
<enterprise-beans>
<session>
<ejb-name>EchoBean</ejb-name>
<jndi-name>security.EchoBean</jndi-name>
<security-proxy>org.jboss.book.security.ex1.EchoSecurityProxy</security-proxy>
</session>
</enterprise-beans>
</jboss>
1.1 date: 2006/11/01 18:14:20; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/security/ex1/roles.properties
Index: roles.properties
===================================================================
jduke=Echo,TheDuke
1.1 date: 2006/11/01 18:14:20; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/security/ex1/users.properties
Index: users.properties
===================================================================
jduke=theduke
More information about the jboss-cvs-commits
mailing list