Annotation of java/classes/org/w3c/jigsaw/acl/AclPrincipal.java, revision 1.1

1.1     ! bmahe       1: // AclPrincipal.java
        !             2: // $Id$
        !             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: /**
        !            16:  * @version $Revision$
        !            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;
        !            23:     protected Hashtable values    = null;
        !            24:     protected IPMatcher ipmatcher = null;
        !            25: 
        !            26:     public boolean equals(Object another) {
        !            27:        if (another instanceof AclPrincipal) {
        !            28:            return toString().equals(another.toString());
        !            29:        } else {
        !            30:            return another.equals(this);
        !            31:        }
        !            32:     }
        !            33: 
        !            34:     public String toString() {
        !            35:        if (password == null)
        !            36:            return name;
        !            37:        else
        !            38:            return name+":"+password;
        !            39:     }
        !            40: 
        !            41:     public int hashCode() {
        !            42:        return toString().hashCode();
        !            43:     }
        !            44: 
        !            45:     public String getName() {
        !            46:        return name;
        !            47:     }
        !            48: 
        !            49:     public String getPassword() {
        !            50:        return password;
        !            51:     }
        !            52: 
        !            53:     public void setValue(String name, Object value) {
        !            54:        values.put(name, value);
        !            55:     }
        !            56: 
        !            57:     public Object getValue(String name) {
        !            58:        return values.get(name);
        !            59:     }
        !            60: 
        !            61:     public boolean matchIP(InetAddress adr) {
        !            62:        return (ipmatcher.lookup(adr) == Boolean.TRUE);
        !            63:     }
        !            64: 
        !            65:     public AclPrincipal(String name, String password) {
        !            66:        this.name      = name;
        !            67:        this.password  = password;
        !            68:        this.ipmatcher = new IPMatcher();
        !            69:        this.values    = new Hashtable();
        !            70:     }
        !            71: 
        !            72:     public AclPrincipal(AuthUser user) {
        !            73:        this.name      = user.getName();
        !            74:        this.password  = user.getPassword();
        !            75:        this.ipmatcher = new IPMatcher();
        !            76:        this.values    = new Hashtable();
        !            77: 
        !            78:        short ips[][]  = user.getIPTemplates();
        !            79:        if ( ips != null ) {
        !            80:            for (int i = 0 ; i < ips.length ; i++) 
        !            81:                ipmatcher.add(ips[i], Boolean.TRUE);
        !            82:        }
        !            83:     }
        !            84: 
        !            85:     
        !            86: }
        !            87: 

Webmaster