--- /dev/null
+// AuthRealm.java\r
+// $Id: AuthRealm.java,v 1.1 2010/06/15 12:28:54 smhuang Exp $\r
+// (c) COPYRIGHT MIT and INRIA, 1996.\r
+// Please first read the full copyright statement in file COPYRIGHT.html\r
+\r
+package org.w3c.jigsaw.auth;\r
+\r
+import java.io.File;\r
+\r
+import java.util.Enumeration;\r
+import java.util.Hashtable;\r
+\r
+import org.w3c.tools.resources.AttributeHolder;\r
+import org.w3c.tools.resources.ContainerResource;\r
+import org.w3c.tools.resources.ExternalContainer;\r
+import org.w3c.tools.resources.MultipleLockException;\r
+import org.w3c.tools.resources.Resource;\r
+import org.w3c.tools.resources.ResourceContext;\r
+import org.w3c.tools.resources.ResourceReference;\r
+import org.w3c.tools.resources.ServerInterface;\r
+\r
+public class AuthRealm extends ExternalContainer {\r
+\r
+ /**\r
+ * Load the user having this name.\r
+ * @param name The user's name.\r
+ * @return An instance of AuthUser or <strong>null</strong> if not found.\r
+ */\r
+\r
+ public synchronized ResourceReference loadUser(String name) {\r
+ return lookup(name);\r
+ }\r
+\r
+ /**\r
+ * register this new user in the realm.\r
+ * @param user The new user.\r
+ */\r
+\r
+ public synchronized void registerUser(AuthUser user) {\r
+ addResource(user, null);\r
+ }\r
+\r
+ public void registerResource(String name,\r
+ Resource resource,\r
+ Hashtable defs) \r
+ {\r
+ if( resource instanceof AuthUser) {\r
+ registerUser(AuthUser.makeUser(resource,\r
+ name, \r
+ new ResourceContext(getContext())));\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Unregister a user from the realm.\r
+ * @param name The user's name.\r
+ * @exception org.w3c.tools.resources.MultipleLockException if someone\r
+ * else has locked this user.\r
+ */\r
+\r
+ public synchronized void unregisterUser(String name) \r
+ throws MultipleLockException\r
+ {\r
+ delete(name);\r
+ }\r
+\r
+ /**\r
+ * Enumerate this realm user's name.\r
+ */\r
+\r
+ public synchronized Enumeration enumerateUserNames() {\r
+ return enumerateResourceIdentifiers();\r
+ }\r
+\r
+ /**\r
+ * create a new empty realm.\r
+ * @param name The name of the realm.\r
+ * @param repository The file to use to store the realm database.\r
+ */\r
+ public static AuthRealm makeRealm(ResourceContext context, String name) {\r
+ Hashtable defs = new Hashtable(3) ;\r
+ defs.put(id, name) ;\r
+ defs.put(co, context);\r
+ AuthRealm realm = new AuthRealm(name, context) ;\r
+ realm.initialize(defs) ;\r
+ return realm ;\r
+ }\r
+\r
+ /**\r
+ * create a new empty realm.\r
+ * @param name The name of the realm.\r
+ * @param repository The file to use to store the realm database.\r
+ */\r
+ public static AuthRealm makeRealm(Resource res,\r
+ ResourceContext context, \r
+ String name) {\r
+ AuthRealm realm = (AuthRealm) res;\r
+ Hashtable defs = new Hashtable(3) ;\r
+ defs.put(id, name) ;\r
+ defs.put(co, context);\r
+ realm.initialize(defs) ;\r
+ return realm ;\r
+ }\r
+\r
+ /**\r
+ * Save our store.\r
+ */\r
+\r
+ public synchronized void save() {\r
+\r
+ }\r
+\r
+ public File getRepository(ResourceContext context) {\r
+ return new File(context.getServer().getAuthDirectory(),\r
+ getIdentifier()+".db");\r
+ }\r
+\r
+ public AuthRealm(String id, ResourceContext context) {\r
+ super(id, context, false);\r
+ }\r
+\r
+ public AuthRealm() {\r
+ super() ;\r
+ }\r
+\r
+}\r