Annotation of java/classes/org/w3c/jigsaw/acl/AclPrincipal.java, revision 1.2
1.1 bmahe 1: // AclPrincipal.java
1.2 ! bmahe 2: // $Id: AclPrincipal.java,v 1.1 1999/04/23 14:06:46 bmahe Exp $
1.1 bmahe 3: // (c) COPYRIGHT MIT, INRIA and Keio, 1999.
4: // Please first read the full copyright statement in file COPYRIGHT.html
5:
6: package org.w3c.jigsaw.acl;
7:
8: import java.net.InetAddress;
9: 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: /**
1.2 ! bmahe 16: * @version $Revision: 1.1 $
1.1 bmahe 17: * @author Benoît Mahé (bmahe@w3.org)
18: */
19: public class AclPrincipal implements Principal {
20:
21: protected String name = null;
22: protected String password = null;
1.2 ! bmahe 23: protected String realm = null;
1.1 bmahe 24: protected Hashtable values = null;
25: protected IPMatcher ipmatcher = null;
26:
27: public boolean equals(Object another) {
28: if (another instanceof AclPrincipal) {
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:
1.2 ! bmahe 50: public String getRealm() {
! 51: return realm;
! 52: }
! 53:
1.1 bmahe 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:
1.2 ! bmahe 70: public AclPrincipal(AuthUser user, String realm) {
1.1 bmahe 71: this.name = user.getName();
72: this.password = user.getPassword();
1.2 ! bmahe 73: this.realm = realm;
1.1 bmahe 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:
85: }
86:
Webmaster