001: // RealmsCatalog.java
002: // $Id: RealmsCatalog.java,v 1.16 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.util.Enumeration;
009: import java.util.Hashtable;
010:
011: import java.io.File;
012: import java.io.PrintStream;
013:
014: import org.w3c.tools.resources.AbstractContainer;
015: import org.w3c.tools.resources.AttributeHolder;
016: import org.w3c.tools.resources.ContainerResource;
017: import org.w3c.tools.resources.DummyResourceReference;
018: import org.w3c.tools.resources.ExternalContainer;
019: import org.w3c.tools.resources.MultipleLockException;
020: import org.w3c.tools.resources.Resource;
021: import org.w3c.tools.resources.ResourceContext;
022: import org.w3c.tools.resources.ResourceReference;
023: import org.w3c.tools.resources.ServerInterface;
024:
025: public class RealmsCatalog extends ExternalContainer {
026:
027: protected String rep = null;
028:
029: /**
030: * Load the given realm and return the AuthRealm instance.
031: * @param name The realm identifier.
032: */
033:
034: public synchronized ResourceReference loadRealm(String name) {
035: return lookup(name);
036: }
037:
038: /**
039: * Enumerate the list of available realms.
040: */
041:
042: public synchronized Enumeration enumerateRealmNames() {
043: return enumerateResourceIdentifiers();
044: }
045:
046: /**
047: * register the given new realm.
048: * @param realm The new realm to register.
049: */
050:
051: public synchronized void registerRealm(AuthRealm realm) {
052: System.out.println("register realm : " + realm.getIdentifier());
053: addResource(realm, null);
054: }
055:
056: public synchronized void registerRealm(String name) {
057: registerRealm(AuthRealm.makeRealm(new ResourceContext(
058: getContext()), name));
059: }
060:
061: public void registerResource(String name, Resource resource,
062: Hashtable defs) {
063: if (resource instanceof AuthRealm) {
064: registerRealm(AuthRealm.makeRealm(resource,
065: new ResourceContext(getContext()), name));
066: }
067: }
068:
069: /**
070: * Unregister the given realm from the catalog.
071: * @param name The name of the catalog.
072: * @exception org.w3c.tools.resources.MultipleLockException if someone
073: * else has locked this realm.
074: */
075:
076: public synchronized void unregisterRealm(String name)
077: throws MultipleLockException {
078: delete(name);
079: }
080:
081: /**
082: * Save the catalog back to disk.
083: */
084:
085: public synchronized void save() {
086:
087: }
088:
089: public File getRepository(ResourceContext context) {
090: return new File(context.getServer().getAuthDirectory(), rep);
091: }
092:
093: public RealmsCatalog(ResourceContext context) {
094: this (context, "realms.db");
095: }
096:
097: public RealmsCatalog(ResourceContext context, String rep) {
098: super ();
099: this .rep = (rep.endsWith(".db")) ? rep : rep + ".db";
100: this .transientFlag = true;
101: Hashtable h = new Hashtable(3);
102: h.put(id, "realms");
103: h.put(co, context);
104: initialize(h);
105: context.setResourceReference(new DummyResourceReference(this));
106: }
107: }
|