[jboss-cvs] jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/security/ex3 ...
Norman Richards
norman.richards at jboss.com
Wed Nov 1 13:14:21 EST 2006
User: nrichards
Date: 06/11/01 13:14:21
Added: jbossas/j2ee/examples/src/main/org/jboss/book/security/ex3
Echo.java EchoBean.java EchoHome.java ExClient.java
ExClientSetup.java ejb-jar.xml jboss-service.xml
jboss.xml log4j.xml roles.properties
users.properties
Log:
modified for j2ee guide
Revision Changes Path
1.1 date: 2006/11/01 18:14:21; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/security/ex3/Echo.java
Index: Echo.java
===================================================================
package org.jboss.book.security.ex3;
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:21; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/security/ex3/EchoBean.java
Index: EchoBean.java
===================================================================
package org.jboss.book.security.ex3;
import java.rmi.RemoteException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
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:21; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/security/ex3/EchoHome.java
Index: EchoHome.java
===================================================================
package org.jboss.book.security.ex3;
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:21; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/security/ex3/ExClient.java
Index: ExClient.java
===================================================================
package org.jboss.book.security.ex3;
import java.rmi.RemoteException;
import javax.naming.InitialContext;
import javax.security.auth.login.LoginContext;
import org.jboss.security.auth.callback.UsernamePasswordHandler;
import org.jboss.util.ChapterExRepository;
/**
*
* @author Scott.Stark at jboss.org
* @version $Revision: 1.1 $
*/
public class ExClient
{
public static void main(String args[]) throws Exception
{
// Setup the example log4j repository
ChapterExRepository.init(ExClient.class);
// Login using SRP
System.out.println("Logging in using the 'srp' configuration");
String username = args[0];
char[] password = args[1].toCharArray();
UsernamePasswordHandler handler = new UsernamePasswordHandler(username, password);
LoginContext lc = new LoginContext("srp", handler);
lc.login();
InitialContext iniCtx = new InitialContext();
Object ref = iniCtx.lookup("EchoBean3");
EchoHome home = (EchoHome) ref;
Echo echo = home.create();
System.out.println("Created Echo");
System.out.println("Echo.echo()#1 = "+echo.echo("This is call 1"));
Thread.currentThread().sleep(15*1000);
/* This will fail due to a SRP cache timeout if the JaasSecurityManager
cache timeout is also set to the same values.
*/
try
{
System.out.println("Echo.echo()#2 = "+echo.echo("This is call 2"));
}
catch(Throwable e)
{
while( e instanceof RemoteException )
{
RemoteException re = (RemoteException) e;
e = re.detail;
}
System.out.println("Echo.echo()#2 failed with exception: "+e.getMessage());
}
lc.logout();
}
}
1.1 date: 2006/11/01 18:14:21; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/security/ex3/ExClientSetup.java
Index: ExClientSetup.java
===================================================================
package org.jboss.book.security.ex3;
import java.net.InetAddress;
import javax.management.ObjectName;
import javax.naming.InitialContext;
import javax.security.auth.login.LoginException;
import javax.security.auth.login.LoginContext;
import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
/** A program that creates an account for username=jduke, password=theduke
using the SRPVerifierStoreService MBean addUser operation.
@author Scott.Stark at jboss.org
@version $Revision: 1.1 $
*/
public class ExClientSetup
{
public static void main(String args[]) throws Exception
{
String username = args[0];
String password = args[1];
System.out.println("Accessing the Security:service=SRPVerifierStore MBean server");
String serverName = InetAddress.getLocalHost().getHostName();
String connectorName = "jmx:" +serverName+ ":rmi";
RMIAdaptor server = (RMIAdaptor) new InitialContext().lookup(connectorName);
ObjectName srpStore = new ObjectName("Security:service=SRPVerifierStore");
System.out.println("Creating username="+username+", password="+password);
Object[] params = {"jduke", "theduke"};
String[] signature = {"java.lang.String", "java.lang.String"};
server.invoke(srpStore, "addUser", params, signature);
System.out.println("User jduke added");
}
}
1.1 date: 2006/11/01 18:14:21; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/security/ex3/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>EchoBean3</ejb-name>
<home>org.jboss.book.security.ex3.EchoHome</home>
<remote>org.jboss.book.security.ex3.Echo</remote>
<ejb-class>org.jboss.book.security.ex3.EchoBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor>
<security-role>
<role-name>Echo</role-name>
</security-role>
<method-permission>
<role-name>Echo</role-name>
<method>
<ejb-name>EchoBean3</ejb-name>
<method-name>*</method-name>
</method>
</method-permission>
</assembly-descriptor>
</ejb-jar>
1.1 date: 2006/11/01 18:14:21; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/security/ex3/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-EX3">
<attribute name="AuthConfig">META-INF/login-config.xml</attribute>
<attribute name="SecurityConfigName">jboss.security:service=XMLLoginConfig</attribute>
</mbean>
<!-- The SRP service that provides the SRP RMI server and server side
authentication cache -->
<mbean code="org.jboss.security.srp.SRPService"
name="jboss.docs.security:service=SRPService">
<attribute name="VerifierSourceJndiName">srp-test/security-ex3</attribute>
<attribute name="JndiName">srp-test/SRPServerInterface</attribute>
<attribute name="AuthenticationCacheJndiName">srp-test/AuthenticationCache</attribute>
<attribute name="AuthenticationCacheTimeout">10</attribute>
<attribute name="AuthenticationCacheResolution">5</attribute>
<attribute name="ServerPort">0</attribute>
<depends>jboss.docs.security:service=PropertiesVerifierStore</depends>
</mbean>
<!-- The SRP store handler service that provides the user password verifier
information -->
<mbean code="org.jboss.book.security.ex3.service.PropertiesVerifierStore"
name="jboss.docs.security:service=PropertiesVerifierStore">
<attribute name="JndiName">srp-test/security-ex3</attribute>
</mbean>
</server>
1.1 date: 2006/11/01 18:14:21; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/security/ex3/jboss.xml
Index: jboss.xml
===================================================================
<?xml version="1.0"?>
<jboss>
<security-domain>java:/jaas/security-ex3</security-domain>
</jboss>
1.1 date: 2006/11/01 18:14:21; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/security/ex3/log4j.xml
Index: log4j.xml
===================================================================
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>
<param name="Threshold" value="INFO"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%p,%c{1}] %m%n"/>
</layout>
</appender>
<appender name="FILE" class="org.apache.log4j.FileAppender">
<param name="File" value="logs/ex3-trace.log" />
<param name="Append" value="false" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%p,%c{1}] %m%n"/>
</layout>
</appender>
<category name="org.jboss.security" additivity="false">
<priority value="TRACE" class="org.jboss.logging.XLevel"/>
<appender-ref ref="FILE"/>
</category>
<category name="org.jboss.security.auth.login.XMLLoginConfigImpl" additivity="false">
<priority value="INFO" />
<appender-ref ref="FILE"/>
</category>
<root>
<level value ="DEBUG"/>
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</root>
</log4j:configuration>
1.1 date: 2006/11/01 18:14:21; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/security/ex3/roles.properties
Index: roles.properties
===================================================================
jduke=Echo,TheDuke
1.1 date: 2006/11/01 18:14:21; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/security/ex3/users.properties
Index: users.properties
===================================================================
jduke=theduke
More information about the jboss-cvs-commits
mailing list