Annotation of java/classes/org/w3c/jigsaw/acl/AclRealm.java, revision 1.3

1.1       bmahe       1: // AclRealm.java
1.3     ! bmahe       2: // $Id: AclRealm.java,v 1.2 1999/04/22 14:10:17 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.security.Principal;
                      9: import java.security.acl.AclEntry;
                     10: import java.security.acl.LastOwnerException;
                     11: import java.security.acl.NotOwnerException;
                     12: import java.security.acl.Permission;
1.3     ! bmahe      13: import java.util.Enumeration;
        !            14: import java.util.Vector;
1.1       bmahe      15: 
1.3     ! bmahe      16: import org.w3c.jigsaw.auth.AuthRealm;
        !            17: import org.w3c.jigsaw.auth.AuthUser;
        !            18: import org.w3c.jigsaw.auth.IPMatcher;
        !            19: import org.w3c.jigsaw.auth.RealmsCatalog;
        !            20: import org.w3c.jigsaw.http.httpd;
        !            21: 
        !            22: import org.w3c.tools.resources.FramedResource;
        !            23: import org.w3c.tools.resources.InvalidResourceException;
        !            24: import org.w3c.tools.resources.ResourceReference;
        !            25: import org.w3c.tools.resources.Attribute;
        !            26: import org.w3c.tools.resources.AttributeRegistry;
        !            27: import org.w3c.tools.resources.StringAttribute;
        !            28: import org.w3c.tools.resources.StringArrayAttribute;
1.1       bmahe      29: 
                     30: /**
1.3     ! bmahe      31:  * @version $Revision: 1.2 $
1.1       bmahe      32:  * @author  Benoît Mahé (bmahe@w3.org)
                     33:  */
                     34: public class AclRealm extends JAcl {
1.3     ! bmahe      35:     /**
        !            36:      * Attribute index - The methods protected by the filter.
        !            37:      */
        !            38:     protected static int ATTR_METHODS = -1 ;
1.2       bmahe      39:     /**
                     40:      * Attribute index - The realm name for this ACL.
                     41:      */
                     42:     protected static int ATTR_REALM = -1;
                     43:     
1.3     ! bmahe      44:     static {
        !            45:        Attribute a   = null ;
        !            46:        Class     c = null ;
        !            47:        try {
        !            48:            c = Class.forName("org.w3c.jigsaw.acl.AclRealm");
        !            49:        } catch (Exception ex) {
        !            50:            ex.printStackTrace() ;
        !            51:            System.exit(1) ;
        !            52:        }
        !            53:        // The protected methods
        !            54:        a = new StringArrayAttribute("methods"
        !            55:                                     , null
        !            56:                                     , Attribute.EDITABLE) ;
        !            57:        ATTR_METHODS = AttributeRegistry.registerAttribute(c, a) ;
        !            58:        // The realm name (to be resolved by the RealmFactory).
        !            59:        a = new StringAttribute("realm"
        !            60:                                , null
        !            61:                                , Attribute.EDITABLE|Attribute.MANDATORY);
        !            62:        ATTR_REALM = AttributeRegistry.registerAttribute(c, a) ;
        !            63:     }
        !            64: 
        !            65:     /**
        !            66:      * The IPMatcher to match IP templates to user records.
        !            67:      */
        !            68:     protected IPMatcher ipmatcher = null ;
        !            69:     /**
        !            70:      * The catalog of realms that make our scope.
        !            71:      */
        !            72:     protected RealmsCatalog catalog = null ;
        !            73:     /**
        !            74:      * Our associated realm.
        !            75:      */
        !            76:     protected ResourceReference rr_realm = null ;
        !            77:     /**
        !            78:      * The nam of the realm we cache in <code>realm</code>.
        !            79:      */
        !            80:     protected String loaded_realm = null ;
        !            81: 
        !            82:     protected Vector positiveEntrySet = null;
        !            83: 
        !            84:     protected Vector negativeEntrySet = null;
        !            85: 
        !            86:     /**
        !            87:      * Get the list of methods that this filter protect
        !            88:      * @return An array of String giving the name of the protected methods,
        !            89:      *    or <strong>null</strong>, in wich case <em>all</em> methods are
        !            90:      *    to be protected.
        !            91:      */
        !            92:     public String[] getMethods() {
        !            93:        return (String[]) getValue(ATTR_METHODS, null) ;
        !            94:     }
        !            95:     
        !            96:     /**
        !            97:      * Get the realm of this filter.
        !            98:      */
        !            99:     public String getRealm() {
        !           100:        return (String) getValue(ATTR_REALM, null) ;
        !           101:     }
        !           102: 
        !           103:     /**
        !           104:      * Get a pointer to our realm, and initialize our ipmatcher.
        !           105:      */
        !           106:     protected synchronized void buildPermissions() {
        !           107:        // Get our catalog:
        !           108:        if ( catalog == null ) {
        !           109:            httpd server = (httpd) 
        !           110:                ((FramedResource) getTargetResource()).getServer() ;
        !           111:            catalog = server.getRealmsCatalog() ;
        !           112:        }
        !           113:        // Check that our realm name is valid:
        !           114:        String name = getRealm() ;
        !           115:        if ( name == null )
        !           116:            return ;
        !           117:        if ((rr_realm != null) && name.equals(loaded_realm)) 
        !           118:            return ;
        !           119:        // Load the realm and create the ipmtacher object
        !           120:        rr_realm = catalog.loadRealm(name) ;
        !           121:        if (rr_realm != null) {
        !           122:            try {
        !           123:                AuthRealm realm = (AuthRealm) rr_realm.lock();
        !           124:                Enumeration enum = realm.enumerateUserNames() ;
        !           125:                while (enum.hasMoreElements()) {
        !           126:                    String   uname = (String) enum.nextElement() ;
        !           127:                    ResourceReference rr_user = realm.loadUser(uname) ;
        !           128:                    try {
        !           129:                        AuthUser user  = (AuthUser) rr_user.lock();
        !           130:                        createEntries(user);
        !           131:                    } catch (InvalidResourceException ex) {
        !           132:                        System.out.println("Invalid user reference : "+uname);
        !           133:                    } finally {
        !           134:                        rr_user.unlock();
        !           135:                    }
        !           136:                }
        !           137:            } catch (InvalidResourceException ex) {
        !           138: 
        !           139:            } finally {
        !           140:                rr_realm.unlock();
        !           141:            }
        !           142:        }
        !           143:     }
        !           144: 
        !           145:     protected void createEntries(AuthUser user) {
        !           146:        AclPrincipal aclp = new AclPrincipal(user);
        !           147:        //@@@ FIXME @@@
        !           148:     }
1.1       bmahe     149: 
                    150:     public boolean addOwner(Principal caller, Principal owner) 
                    151:        throws NotOwnerException
                    152:     {
                    153:        return false;
                    154:     }
                    155: 
                    156:     public boolean deleteOwner(Principal caller, Principal owner)
                    157:        throws NotOwnerException, LastOwnerException
                    158:     {
                    159:        return false;
                    160:     }
                    161: 
                    162:     public boolean isOwner(Principal owner) {
                    163:        return false;
                    164:     }
                    165: 
                    166:     public void setName(Principal caller, String name) 
                    167:        throws NotOwnerException
                    168:     {
1.3     ! bmahe     169:        throw new NotOwnerException();
1.1       bmahe     170:     }
                    171: 
                    172:     public String getName() {
1.3     ! bmahe     173:        return getRealm();
1.1       bmahe     174:     }
                    175: 
                    176:     public boolean addEntry(Principal caller, AclEntry entry) 
                    177:        throws NotOwnerException
                    178:     {
                    179:        return false;
                    180:     }
                    181: 
                    182:     public boolean removeEntry(Principal caller, AclEntry entry) 
                    183:        throws NotOwnerException
                    184:     {
                    185:        return false;
                    186:     }
                    187: 
                    188:     public Enumeration getPermissions(Principal user) {
                    189:        return null;
                    190:     }
                    191:     
                    192:     public Enumeration entries() {
                    193:        return null;
                    194:     }
                    195: 
                    196:     public boolean checkPermission(Principal principal, Permission permission)
                    197:     {
1.3     ! bmahe     198:        String methods[] = getMethods();
        !           199:        boolean methodprotected = false;
        !           200:        if (methods != null) {
        !           201:            for (int i = 0 ; i < methods.length ; i++) {
        !           202:                if (permission.equals(methods[i]))
        !           203:                    methodprotected = true;
        !           204:            }
        !           205:        } else {
        !           206:            methodprotected = true;
        !           207:        }
        !           208:        if (! methodprotected)
        !           209:            return true;
        !           210:        return userAllowed(principal);
        !           211:     }
        !           212: 
        !           213:     protected boolean userAllowed(Principal principal) {
        !           214:        return false;
1.1       bmahe     215:     }
                    216: 
                    217:     public String toString() {
1.3     ! bmahe     218:        return getName();
        !           219:     }
        !           220: 
        !           221:     /**
        !           222:      * Initialize the Acl.
        !           223:      */
        !           224:     public void initialize(Object values[]) {
        !           225:        super.initialize(values) ;
        !           226:        positiveEntrySet = new Vector(10);
        !           227:        negativeEntrySet = new Vector(10);
        !           228:        buildPermissions();
        !           229:        
1.1       bmahe     230:     }
                    231: 
                    232: }

Webmaster