01: // AuthUserPrincipal.java
02: // $Id: AuthUserPrincipal.java,v 1.2 2000/08/16 21:37:33 ylafon Exp $
03: // (c) COPYRIGHT MIT, INRIA and Keio, 1999.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.jigsaw.acl;
07:
08: import java.net.InetAddress;
09: import java.security.Principal;
10: import java.util.Hashtable;
11:
12: import org.w3c.jigsaw.auth.AuthUser;
13: import org.w3c.jigsaw.auth.IPMatcher;
14:
15: /**
16: * @version $Revision: 1.2 $
17: * @author Benoît Mahé (bmahe@w3.org)
18: */
19: public class AuthUserPrincipal implements AclPrincipal {
20:
21: protected String name = null;
22: protected String password = null;
23: protected String realm = null;
24: protected Hashtable values = null;
25: protected IPMatcher ipmatcher = null;
26:
27: public boolean equals(Object another) {
28: if (another instanceof AuthUserPrincipal) {
29: return toString().equals(another.toString());
30: } else {
31: return another.equals(this );
32: }
33: }
34:
35: public String toString() {
36: if (password == null)
37: return name;
38: else
39: return name + ":" + password;
40: }
41:
42: public int hashCode() {
43: return toString().hashCode();
44: }
45:
46: public String getName() {
47: return name;
48: }
49:
50: public String getRealm() {
51: return realm;
52: }
53:
54: public String getPassword() {
55: return password;
56: }
57:
58: public void setValue(String name, Object value) {
59: values.put(name, value);
60: }
61:
62: public Object getValue(String name) {
63: return values.get(name);
64: }
65:
66: public boolean matchIP(InetAddress adr) {
67: return (ipmatcher.lookup(adr) == Boolean.TRUE);
68: }
69:
70: public AuthUserPrincipal(AuthUser user, String realm) {
71: this .name = user.getName();
72: this .password = user.getPassword();
73: this .realm = realm;
74: this .ipmatcher = new IPMatcher();
75: this .values = new Hashtable();
76:
77: short ips[][] = user.getIPTemplates();
78: if (ips != null) {
79: for (int i = 0; i < ips.length; i++)
80: ipmatcher.add(ips[i], Boolean.TRUE);
81: }
82: }
83:
84: }
|