001: // AuthRealm.java
002: // $Id: AuthRealm.java,v 1.14 2002/06/26 17:55:05 ylafon Exp $
003: // (c) COPYRIGHT MIT and INRIA, 1996.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: package org.w3c.jigsaw.auth;
007:
008: import java.io.File;
009:
010: import java.util.Enumeration;
011: import java.util.Hashtable;
012:
013: import org.w3c.tools.resources.AttributeHolder;
014: import org.w3c.tools.resources.ContainerResource;
015: import org.w3c.tools.resources.ExternalContainer;
016: import org.w3c.tools.resources.MultipleLockException;
017: import org.w3c.tools.resources.Resource;
018: import org.w3c.tools.resources.ResourceContext;
019: import org.w3c.tools.resources.ResourceReference;
020: import org.w3c.tools.resources.ServerInterface;
021:
022: public class AuthRealm extends ExternalContainer {
023:
024: /**
025: * Load the user having this name.
026: * @param name The user's name.
027: * @return An instance of AuthUser or <strong>null</strong> if not found.
028: */
029:
030: public synchronized ResourceReference loadUser(String name) {
031: return lookup(name);
032: }
033:
034: /**
035: * register this new user in the realm.
036: * @param user The new user.
037: */
038:
039: public synchronized void registerUser(AuthUser user) {
040: addResource(user, null);
041: }
042:
043: public void registerResource(String name, Resource resource,
044: Hashtable defs) {
045: if (resource instanceof AuthUser) {
046: registerUser(AuthUser.makeUser(resource, name,
047: new ResourceContext(getContext())));
048: }
049: }
050:
051: /**
052: * Unregister a user from the realm.
053: * @param name The user's name.
054: * @exception org.w3c.tools.resources.MultipleLockException if someone
055: * else has locked this user.
056: */
057:
058: public synchronized void unregisterUser(String name)
059: throws MultipleLockException {
060: delete(name);
061: }
062:
063: /**
064: * Enumerate this realm user's name.
065: */
066:
067: public synchronized Enumeration enumerateUserNames() {
068: return enumerateResourceIdentifiers();
069: }
070:
071: /**
072: * create a new empty realm.
073: * @param name The name of the realm.
074: * @param repository The file to use to store the realm database.
075: */
076: public static AuthRealm makeRealm(ResourceContext context,
077: String name) {
078: Hashtable defs = new Hashtable(3);
079: defs.put(id, name);
080: defs.put(co, context);
081: AuthRealm realm = new AuthRealm(name, context);
082: realm.initialize(defs);
083: return realm;
084: }
085:
086: /**
087: * create a new empty realm.
088: * @param name The name of the realm.
089: * @param repository The file to use to store the realm database.
090: */
091: public static AuthRealm makeRealm(Resource res,
092: ResourceContext context, String name) {
093: AuthRealm realm = (AuthRealm) res;
094: Hashtable defs = new Hashtable(3);
095: defs.put(id, name);
096: defs.put(co, context);
097: realm.initialize(defs);
098: return realm;
099: }
100:
101: /**
102: * Save our store.
103: */
104:
105: public synchronized void save() {
106:
107: }
108:
109: public File getRepository(ResourceContext context) {
110: return new File(context.getServer().getAuthDirectory(),
111: getIdentifier() + ".db");
112: }
113:
114: public AuthRealm(String id, ResourceContext context) {
115: super (id, context, false);
116: }
117:
118: public AuthRealm() {
119: super();
120: }
121:
122: }
|