import java.util.*;
import javax.naming.*;
import javax.naming.directory.*;
import com.novell.service.session.*;
import com.novell.java.security.*;
import com.novell.service.server.*;
import com.novell.java.lang.*;
import com.novell.service.security.*;
public class MultiUserSessionTest
{
public static void main(String args[])
{
if(args.length != 4)
{
System.out.print("Usage: Java MultiUserSessionTest ServerName UserName ");
System.out.println("Password Vol/Dir/File");
System.out.println("Example: java SessionTest serv1 admin passw sys/java");
System.exit(0);
}
try
{
String serverName = args[0];
String userName = args[1];
String password = args[2];
String fileName = "FileSystem/" + args[3];
SessionManager sm1 = SessionManagerFactory.getPrivate(new SessionEnv());
SessionManager sm2 = SessionManagerFactory.getPrivate(new SessionEnv());
Session s1 = sm1.getSession(serverName);
Session s2 = sm2.getSession(serverName);
Identity ident = s1.createIdentity(userName);
if(ident instanceof PasswordIdentityFactory)
{
ident = (Identity)
((PasswordIdentityFactory)ident).getPasswordIdentityInstance();
((PasswordIdentity)ident).setPassword(new Password(password));
}
Authenticator.login(ident);
DirContext ctx1 = getServerDirContext(sm1, serverName);
DirContext ctx2 = getServerDirContext(sm2, serverName);
ctx1 = (DirContext)ctx1.lookup(fileName);
try
{
ctx2 = (DirContext)ctx2.lookup(fileName);
throw new Exception("lookup(" + fileName +
") should have thrown an exception");
}
catch(NamingException e)
{
}
System.out.println("Successful");
}
catch(Exception e)
{
dumpException(e);
}
}
public static ServerDirContext getServerDirContext(SessionManager sm, String serverName) throws Exception
{
Hashtable hash = new Hashtable();
hash.put(Context.INITIAL_CONTEXT_FACTORY, "com.novell.service.server.ServerInitialContextFactory");
hash.put(Context.PROVIDER_URL, serverName);
hash.put(com.novell.utility.naming.Environment.SESSION_MANAGER_OBJECT, sm);
DirContext ctx1 = new InitialDirContext(hash);
ServerDirContext ctx2 = (ServerDirContext)ctx1.lookup("");
return ctx2;
}
synchronized static public void dumpException(Throwable e)
{
System.out.flush();
System.err.flush();
System.out.println("Dumping Exception...");
while(e != null)
{
e.printStackTrace();
if (e instanceof HasRootCauses)
{
System.out.println("\nRoot causes...");
Enumeration enum = ((HasRootCauses)e).getRootCauses();
while (enum.hasMoreElements())
{
dumpException((Throwable)enum.nextElement());
}
}
if (e instanceof HasRootCause)
e = ((HasRootCause)e).getRootCause();
else if (e instanceof NamingException)
e = ((NamingException)e).getRootCause();
else if(e instanceof java.rmi.RemoteException)
e = ((java.rmi.RemoteException)e).detail;
else
e = null;
if(e != null)
System.out.println("Root cause...");
}
System.err.flush();
System.out.flush();
}
}