Methods Summary |
---|
public static com.imaginary.lwp.Identifier | currentIdentifier()Provides a client application with its identifier so that
it can pass it to a transactional method.
return currentIdentifier((AuthenticationRole)null);
|
public static com.imaginary.lwp.Identifier | currentIdentifier(java.lang.Object cred)
return (Identifier)identifiers.get(new AuthenticationRole(cred));
|
public static com.imaginary.lwp.Identifier | currentIdentifier(AuthenticationRole r)
return (Identifier)identifiers.get(r);
|
public boolean | equals(java.lang.Object ob)
if( ob instanceof Identifier ) {
Identifier id = (Identifier)ob;
if( key != id.key ) {
return false;
}
return true;
}
return false;
|
private static long | getRandomNumber()Generates a secure, random long used for key generation.
byte[] value = new byte[60];
long l = 0;
if( randomizer == null ) {
randomizer = new SecureRandom();
}
randomizer.nextBytes(value);
for(int i=0; i<60; i++) {
l = l + (value[i]<<i);
}
return l;
|
public static com.imaginary.lwp.Identifier | getServerID()
if( serverID == null ) {
serverID = new Identifier("LWPSERVER");
}
return serverID;
|
public java.lang.String | getUserID()
return userID;
|
public int | hashCode()A hash code based on the key.
return (new Long(key)).hashCode();
|
static boolean | isAuthenticated(com.imaginary.lwp.Identifier id)Looks through the list of authenticated users for
any authentication matching the specified identifier.
synchronized( authenticated ) {
Iterator it;
HashMap map;
if( id == null ) {
System.out.println("ID was null.");
return false;
}
if( id.userID.equals("LWPSERVER") ) {
if( id.key == getServerID().key ) {
return true;
}
else {
return false;
}
}
if( !authenticated.containsKey(id.userID) ) {
return false;
}
map = (HashMap)authenticated.get(id.userID);
it = map.entrySet().iterator();
while( it.hasNext() ) {
Map.Entry ent = (Map.Entry)it.next();
AuthenticationMonitor mon;
mon = (AuthenticationMonitor)ent.getValue();
if( mon.id.key == id.key ) {
mon.lastTouched = (new Date()).getTime();
return true;
}
}
return false;
}
|
public static com.imaginary.lwp.Identifier | login(java.lang.String uid, java.lang.String pw)Authenticates the specified user ID against the specified password.
This method finds the server and sends the user ID and password
to it for authentication. If the password does not match the
currently stored password, then an exception is thrown. Otherwise
it will store the identifier the server hands back. This method
authenticates for a default role.
return login(uid, pw, null);
|
public static com.imaginary.lwp.Identifier | login(java.lang.String uid, java.lang.String pw, AuthenticationRole r)Authenticates the specified user ID against the specified password.
This method finds the server and sends the user ID and password
to it for authentication. If the password does not match the
currently stored password, then an exception is thrown. Otherwise
it will store the identifier the server hands back.
String url = System.getProperty(LWPProperties.RMI_URL);
ObjectServer server;
try {
Identifier id;
server = (ObjectServer)Naming.lookup(url);
id = server.login(uid, pw, r);
if( id != null ) {
identifiers.put(r, id);
}
return id;
}
catch( MalformedURLException e ) {
throw new AuthenticationException(e);
}
catch( NotBoundException e ) {
throw new AuthenticationException(e);
}
catch( RemoteException e ) {
throw new AuthenticationException(e);
}
|
static void | monitor()A thread that goes through the list of authenticated users and
throws out people who have not touched the system in a while.
Thread t = new Thread() {
public void run() {
ArrayList uids = new ArrayList();
while( true ) {
Iterator keys;
try { Thread.sleep(600000); }
catch( InterruptedException e ) { }
synchronized( authenticated ) {
Iterator it = authenticated.keySet().iterator();
while( it.hasNext() ) {
uids.add(it.next());
}
}
keys = uids.iterator();
while( keys.hasNext() ) {
String uid = (String)keys.next();
long time = (new Date()).getTime();
try { Thread.sleep(1000); }
catch( InterruptedException e ) { }
synchronized( authenticated ) {
if( authenticated.containsKey(uid) ) {
HashMap map = (HashMap)authenticated.get(uid);
Iterator roles = map.keySet().iterator();
while( roles.hasNext() ) {
AuthenticationRole r;
AuthenticationMonitor mon;
long diff;
r = (AuthenticationRole)roles.next();
mon = (AuthenticationMonitor)map.get(r);
diff = time - mon.lastTouched;
// 30 minutes
if( diff > 1800000 ) {
map.remove(r);
if( map.size() < 1 ) {
authenticated.remove(uid);
}
}
}
}
}
}
}
}
};
t.setPriority(Thread.MIN_PRIORITY);
t.start();
|
public java.lang.String | toLocaleString(java.util.Locale loc)
return toString();
|
public java.lang.String | toString()
return userID;
|
static boolean | validateCreate(com.imaginary.lwp.Identifier id, BaseEntity ent)This implementation currently only verifies that the user is
authenticated.
return isAuthenticated(id);
|
static boolean | validateRead(com.imaginary.lwp.Identifier id, BaseEntity ent)
return isAuthenticated(id);
|
static boolean | validateRemove(com.imaginary.lwp.Identifier id, BaseEntity ent)This implementation currently only verifies that the user is
authenticated.
return isAuthenticated(id);
|
static boolean | validateStore(com.imaginary.lwp.Identifier id, BaseEntity ent)This implementation currently only verifies that the user is
authenticated.
return isAuthenticated(id);
|