--- /dev/null
+// AuthUserPrincipal.java\r
+// $Id: AuthUserPrincipal.java,v 1.1 2010/06/15 12:22:08 smhuang Exp $\r
+// (c) COPYRIGHT MIT, INRIA and Keio, 1999.\r
+// Please first read the full copyright statement in file COPYRIGHT.html\r
+\r
+package org.w3c.jigsaw.acl;\r
+\r
+import java.net.InetAddress;\r
+import java.security.Principal;\r
+import java.util.Hashtable;\r
+\r
+import org.w3c.jigsaw.auth.AuthUser;\r
+import org.w3c.jigsaw.auth.IPMatcher;\r
+\r
+/**\r
+ * @version $Revision: 1.1 $\r
+ * @author Benoît Mahé (bmahe@w3.org)\r
+ */\r
+public class AuthUserPrincipal implements AclPrincipal {\r
+\r
+ protected String name = null;\r
+ protected String password = null;\r
+ protected String realm = null;\r
+ protected Hashtable values = null;\r
+ protected IPMatcher ipmatcher = null;\r
+\r
+ public boolean equals(Object another) {\r
+ if (another instanceof AuthUserPrincipal) {\r
+ return toString().equals(another.toString());\r
+ } else {\r
+ return another.equals(this);\r
+ }\r
+ }\r
+\r
+ public String toString() {\r
+ if (password == null)\r
+ return name;\r
+ else\r
+ return name+":"+password;\r
+ }\r
+\r
+ public int hashCode() {\r
+ return toString().hashCode();\r
+ }\r
+\r
+ public String getName() {\r
+ return name;\r
+ }\r
+\r
+ public String getRealm() {\r
+ return realm;\r
+ }\r
+\r
+ public String getPassword() {\r
+ return password;\r
+ }\r
+\r
+ public void setValue(String name, Object value) {\r
+ values.put(name, value);\r
+ }\r
+\r
+ public Object getValue(String name) {\r
+ return values.get(name);\r
+ }\r
+\r
+ public boolean matchIP(InetAddress adr) {\r
+ return (ipmatcher.lookup(adr) == Boolean.TRUE);\r
+ }\r
+\r
+ public AuthUserPrincipal(AuthUser user, String realm) {\r
+ this.name = user.getName();\r
+ this.password = user.getPassword();\r
+ this.realm = realm;\r
+ this.ipmatcher = new IPMatcher();\r
+ this.values = new Hashtable();\r
+\r
+ short ips[][] = user.getIPTemplates();\r
+ if ( ips != null ) {\r
+ for (int i = 0 ; i < ips.length ; i++) \r
+ ipmatcher.add(ips[i], Boolean.TRUE);\r
+ }\r
+ }\r
+\r
+ \r
+}\r
+\r
+\r