User: starksm
Date: 01/04/04 14:49:15
Added: src/main/org/jboss/security/srp SRPPermission.java
SRPServerProxy.java SRPService.java
SRPServiceMBean.java SRPVerifierStoreService.java
SRPVerifierStoreServiceMBean.java
Log:
Move all SRP related classes to the srp package
Revision Changes Path
1.1 jbosssx/src/main/org/jboss/security/srp/SRPPermission.java
Index: SRPPermission.java
===================================================================
package org.jboss.security.srp;
import java.security.BasicPermission;
/** A custom permission class for protecting access to sensitive SRP information
like the private session key and private key.
The following table lists all the possible SRPPermission target names,
and for each provides a description of what the permission allows
and a discussion of the risks of granting code the permission.
<table border=1 cellpadding=5>
<tr>
<th>Permission Target Name</th>
<th>What the Permission Allows</th>
<th>Risks of Allowing this Permission</th>
</tr>
<tr>
<td>getSessionKey</td>
<td>Access the private SRP session key</td>
<td>This provides access the the private session key that results from
the SRP negiotation. Access to this key will allow one to encrypt/decrypt msgs
that have been encrypted with the session key.
</td>
</tr>
</table>
@author [EMAIL PROTECTED]
@version $Revision:
*/
public class SRPPermission extends BasicPermission
{
/** Creates new SRPPermission */
public SRPPermission(String name)
{
super(name);
}
public SRPPermission(String name, String actions)
{
super(name, actions);
}
}
1.1 jbosssx/src/main/org/jboss/security/srp/SRPServerProxy.java
Index: SRPServerProxy.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.security.srp;
import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.jboss.security.srp.SRPServerInterface;
/** A serializable proxy that is bound into JNDI with a reference to the
RMI implementation of a SRPServerInterface. This allows a client to lookup
the interface and not have the RMI stub for the server as it will be downloaded
to them when the SRPServerProxy is unserialized.
@author [EMAIL PROTECTED]
@version $Revision: 1.1 $
*/
public class SRPServerProxy implements InvocationHandler, Serializable
{
private SRPServerInterface server;
/** Create a SRPServerProxy given the SRPServerInterface that method
invocations are to be delegated to.
*/
SRPServerProxy(SRPServerInterface server)
{
this.server = server;
}
/** The InvocationHandler invoke method. All calls are simply delegated to
the SRPServerInterface server object.
*/
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
Object ret = null;
try
{
ret = method.invoke(server, args);
}
catch(InvocationTargetException e)
{
throw e.getTargetException();
}
catch(Throwable e)
{
e.printStackTrace();
throw e;
}
return ret;
}
}
1.1 jbosssx/src/main/org/jboss/security/srp/SRPService.java
Index: SRPService.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.security.srp;
import java.lang.reflect.Proxy;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.naming.NonSerializableFactory;
import org.jboss.security.SimplePrincipal;
import org.jboss.security.srp.SRPRemoteServer;
import org.jboss.security.srp.SRPRemoteServer.SRPServerListener;
import org.jboss.security.srp.SRPServerInterface;
import org.jboss.security.srp.SRPServerSession;
import org.jboss.security.srp.SRPVerifierStore;
import org.jboss.util.ServiceMBeanSupport;
import org.jboss.util.TimedCachePolicy;
/** The JMX mbean interface for the SRP service. This mbean sets up an
RMI implementation of the 'Secure Remote Password' cryptographic authentication
system described in RFC2945.
@author [EMAIL PROTECTED]
@version $Revision: 1.1 $
*/
public class SRPService extends ServiceMBeanSupport implements SRPServiceMBean,
SRPServerListener
{
private SRPRemoteServer server;
private int serverPort = 10099;
private SRPVerifierStore verifierStore;
private String verifierSourceJndiName = "srp:DefaultVerifierSource";
private String serverJndiName = "srp:SRPServerInterface";
private String cacheJndiName = "srp:AuthenticationCache";
private TimedCachePolicy cachePolicy;
// --- Begin SRPServiceMBean interface methods
/** Get the jndi name for the SRPVerifierSource implementation binding.
*/
public String getVerifierSourceJndiName()
{
return verifierSourceJndiName;
}
/** set the jndi name for the SRPVerifierSource implementation binding.
*/
public void setVerifierSourceJndiName(String jndiName)
{
this.verifierSourceJndiName = jndiName;
}
/** Get the jndi name under which the SRPServerInterface proxy should be bound
*/
public String getJndiName()
{
return serverJndiName;
}
/** Set the jndi name under which the SRPServerInterface proxy should be bound
*/
public void setJndiName(String jndiName)
{
this.serverJndiName = jndiName;
}
/** Get the jndi name under which the SRPServerInterface proxy should be bound
*/
public String getAuthenticationCacheJndiName()
{
return cacheJndiName;
}
/** Set the jndi name under which the SRPServerInterface proxy should be bound
*/
public void setAuthenticationCacheJndiName(String jndiName)
{
this.cacheJndiName = jndiName;
}
/** Get the RMI port for the SRPServerInterface
*/
public int getServerPort()
{
return serverPort;
}
/** Get the RMI port for the SRPServerInterface
*/
public void setServerPort(int serverPort)
{
this.serverPort = serverPort;
}
// --- End SRPServiceMBean interface methods
/** Called when username has sucessfully completed the SRP login. This
places the SRP session into the credential cache using a
SimplePrincipal based on the username as the key.
*/
public void verifiedUser(String username, SRPServerSession session)
{
try
{
SimplePrincipal principal = new SimplePrincipal(username);
synchronized( cachePolicy )
{ /* We only insert a principal if there is no current entry.
*/
if( cachePolicy.peek(principal) == null )
cachePolicy.insert(principal, session);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public String getName()
{
return "SRPService";
}
public void initService() throws Exception
{
}
public void startService() throws Exception
{
loadStore();
server = new SRPRemoteServer(verifierStore, serverPort);
server.addSRPServerListener(this);
// Bind a proxy into jndi
SRPServerProxy proxyHandler = new SRPServerProxy(server);
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Class[] interfaces = {SRPServerInterface.class};
Object proxy = Proxy.newProxyInstance(loader, interfaces, proxyHandler);
InitialContext ctx = new InitialContext();
ctx.rebind(serverJndiName, proxy);
System.out.println("Bound SRPServerProxy at "+serverJndiName);
// The type of cache needs to be externalized...
cachePolicy = new TimedCachePolicy(1800, false, 60);
cachePolicy.init();
cachePolicy.start();
// Bind a reference to store using NonSerializableFactory as the
ObjectFactory
NonSerializableFactory.rebind(ctx, cacheJndiName, cachePolicy);
System.out.println("Bound AuthenticationCache at "+cacheJndiName);
}
private void loadStore() throws NamingException
{
InitialContext ctx = new InitialContext();
// Get the SRPVerifierStore implementation
verifierStore = (SRPVerifierStore) ctx.lookup(verifierSourceJndiName);
if( server != null )
{
server.setVerifierStore(verifierStore);
}
}
}
1.1 jbosssx/src/main/org/jboss/security/srp/SRPServiceMBean.java
Index: SRPServiceMBean.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.security.srp;
import javax.naming.NamingException;
/** The JMX mbean interface for the SRP service. This mbean sets up an
RMI implementation of the 'Secure Remote Password' cryptographic authentication
system developed by Tom Wu ([EMAIL PROTECTED]). For more info on SRP
see http://www-cs-students.stanford.edu/~tjw/srp/.
@author [EMAIL PROTECTED]
@version $Revision: 1.1 $
*/
public interface SRPServiceMBean extends org.jboss.util.ServiceMBean
{
// Constants -----------------------------------------------------
public static final String OBJECT_NAME = ":service=SRPService";
/** Get the jndi name for the SRPVerifierSource implementation binding.
*/
public String getVerifierSourceJndiName();
/** set the jndi name for the SRPVerifierSource implementation binding.
*/
public void setVerifierSourceJndiName(String jndiName);
/** Get the jndi name under which the SRPServerInterface proxy should be bound
*/
public String getJndiName();
/** Set the jndi name under which the SRPServerInterface proxy should be bound
*/
public void setJndiName(String jndiName);
/** Get the jndi name under which the SRPServerInterface proxy should be bound
*/
public String getAuthenticationCacheJndiName();
/** Set the jndi name under which the SRPServerInterface proxy should be bound
*/
public void setAuthenticationCacheJndiName(String jndiName);
/** Get the RMI port for the SRPRemoteServerInterface
*/
public int getServerPort();
/** Set the RMI port for the SRPRemoteServerInterface
*/
public void setServerPort(int port);
}
1.1
jbosssx/src/main/org/jboss/security/srp/SRPVerifierStoreService.java
Index: SRPVerifierStoreService.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.security.srp;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import javax.management.MBeanRegistration;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.naming.InitialContext;
import org.jboss.naming.NonSerializableFactory;
import org.jboss.security.srp.SerialObjectStore;
import org.jboss.util.ServiceMBeanSupport;
/** The JMX mbean interface for the SRP password verifier store. This
implementation uses the SerialObjectStore as a simple and yet secure
source of usernames and their password verifiers and verifier salts. It
also provides a simple interface for adding and deleting users from the
SerialObjectStore. The mbean stores a non-serializable reference to the
SRPVerifierStore interface in JNDI under the property.
@see org.jboss.security.srp.SerialObjectStore
@author [EMAIL PROTECTED]
@version $Revision: 1.1 $
*/
public class SRPVerifierStoreService extends ServiceMBeanSupport implements
SRPVerifierStoreServiceMBean
{
private SerialObjectStore store;
private String fileName = "SRPVerifierStore.ser";
private String jndiName = "srp:DefaultVerifierSource";
// --- Begin SRPVerifierStoreServiceMBean interface methods
/** Get the jndi name for the SRPVerifierSource implementation binding.
*/
public String getJndiName()
{
return jndiName;
}
/** set the jndi name for the SRPVerifierSource implementation binding.
*/
public void setJndiName(String jndiName)
{
this.jndiName = jndiName;
}
public void setStoreFile(String fileName) throws IOException
{
this.fileName = fileName;
if( store != null )
{
File storeFile = new File(fileName);
store.save(storeFile);
}
}
public void addUser(String username,String password) throws IOException
{
try
{
store.addUser(username, password);
save();
System.out.println("Added username: "+username);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void delUser(String username) throws IOException
{
store.delUser(username);
System.out.println("Deleted username: "+username);
save();
}
// --- End SRPVerifierStoreServiceMBean interface methods
public String getName()
{
return "SRPVerifierStoreService";
}
public void initService() throws Exception
{
}
public void startService() throws Exception
{
File storeFile = new File(fileName);
store = new SerialObjectStore(storeFile);
System.out.println("Created SerialObjectStore at:
"+storeFile.getAbsolutePath());
InitialContext ctx = new InitialContext();
// Bind a reference to store using NonSerializableFactory as the
ObjectFactory
NonSerializableFactory.rebind(ctx, jndiName, store);
}
private void save() throws IOException
{
if( store != null )
{ // Try to locate the file on the classpath
File storeFile = new File(fileName);
ClassLoader loader = Thread.currentThread().getContextClassLoader();
URL url = loader.getResource(fileName);
if( url == null )
{ // Try to locate the file's parent on the classpath
String parent = storeFile.getParent();
if( parent != null )
{
url = loader.getResource(parent);
if( url != null )
{
storeFile = new File(url.getFile(), storeFile.getName());
}
// else, just go with storeFile as a system file path
}
}
else
{
storeFile = new File(url.getFile());
}
store.save(storeFile);
}
}
}
1.1
jbosssx/src/main/org/jboss/security/srp/SRPVerifierStoreServiceMBean.java
Index: SRPVerifierStoreServiceMBean.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.security.srp;
import java.io.IOException;
/** The JMX mbean interface for the SRP password verifier store.
@author [EMAIL PROTECTED]
@version $Revision: 1.1 $
*/
public interface SRPVerifierStoreServiceMBean extends org.jboss.util.ServiceMBean
{
/** Get the jndi name for the SRPVerifierSource implementation binding.
*/
public String getJndiName();
/** set the jndi name for the SRPVerifierSource implementation binding.
*/
public void setJndiName(String jndiName);
/** Set the location of the user password verifier store
*/
public void setStoreFile(String fileName) throws IOException;
/** Add a user to the store.
*/
public void addUser(String username, String password) throws IOException;
/** Delete a user to the store.
*/
public void delUser(String username) throws IOException;
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development