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

1.1     ! bmahe       1: // AuthUserPrincipal.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: 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:     
        !            85: }
        !            86: 

Webmaster