Annotation of java/classes/org/w3c/jigsaw/acl/AuthUserPrincipal.java, revision 1.4
1.1 bmahe 1: // AuthUserPrincipal.java
1.4 ! ylafon 2: // $Id: AuthUserPrincipal.java,v 1.3 2012/06/16 15:48:44 ylafon 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;
1.4 ! ylafon 9: import java.util.HashMap;
! 10: import java.util.Map;
1.1 bmahe 11: import org.w3c.jigsaw.auth.AuthUser;
12: import org.w3c.jigsaw.auth.IPMatcher;
13:
14: /**
1.3 ylafon 15: * @author Benoît Mahé (bmahe@w3.org)
1.4 ! ylafon 16: * @version $Revision: 1.3 $
1.1 bmahe 17: */
18: public class AuthUserPrincipal implements AclPrincipal {
1.2 ylafon 19:
1.3 ylafon 20: protected String name = null;
21: protected String password = null;
22: protected String realm = null;
1.4 ! ylafon 23: protected Map<String,Object> values = null;
1.1 bmahe 24: protected IPMatcher ipmatcher = null;
25:
26: public boolean equals(Object another) {
1.3 ylafon 27: if (another instanceof AuthUserPrincipal) {
28: return toString().equals(another.toString());
29: } else {
30: return another.equals(this);
31: }
1.1 bmahe 32: }
33:
34: public String toString() {
1.3 ylafon 35: if (password == null)
36: return name;
37: else
38: return name + ":" + password;
1.1 bmahe 39: }
40:
41: public int hashCode() {
1.3 ylafon 42: return toString().hashCode();
1.1 bmahe 43: }
44:
45: public String getName() {
1.3 ylafon 46: return name;
1.1 bmahe 47: }
48:
49: public String getRealm() {
1.3 ylafon 50: return realm;
1.1 bmahe 51: }
52:
53: public String getPassword() {
1.3 ylafon 54: return password;
1.1 bmahe 55: }
56:
57: public void setValue(String name, Object value) {
1.3 ylafon 58: values.put(name, value);
1.1 bmahe 59: }
60:
61: public Object getValue(String name) {
1.3 ylafon 62: return values.get(name);
1.1 bmahe 63: }
64:
65: public boolean matchIP(InetAddress adr) {
1.3 ylafon 66: return (ipmatcher.lookup(adr) == Boolean.TRUE);
1.1 bmahe 67: }
68:
69: public AuthUserPrincipal(AuthUser user, String realm) {
1.3 ylafon 70: this.name = user.getName();
71: this.password = user.getPassword();
72: this.realm = realm;
73: this.ipmatcher = new IPMatcher();
1.4 ! ylafon 74: this.values = new HashMap<String,Object>();
1.3 ylafon 75:
76: short ips[][] = user.getIPTemplates();
77: if (ips != null) {
78: for (short[] ip : ips) {
79: ipmatcher.add(ip, Boolean.TRUE);
80: }
81: }
1.1 bmahe 82: }
83:
1.3 ylafon 84:
1.1 bmahe 85: }
1.2 ylafon 86:
1.1 bmahe 87:
Webmaster