FileDocCategorySizeDatePackage
AclImpl.javaAPI DocAndroid 1.5 API8474Wed May 06 22:41:06 BST 2009org.apache.harmony.security.tests.support.acl

AclImpl

public class AclImpl extends OwnerImpl implements Acl
Additional class for verification Acl interface

Fields Summary
private Hashtable
allowedUsersTable
private Hashtable
allowedGroupsTable
private Hashtable
deniedUsersTable
private Hashtable
deniedGroupsTable
private String
aclName
private Vector
zeroSet
Constructors Summary
public AclImpl(Principal principal, String s)

        super(principal);
        allowedUsersTable = new Hashtable(23);
        allowedGroupsTable = new Hashtable(23);
        deniedUsersTable = new Hashtable(23);
        deniedGroupsTable = new Hashtable(23);
        aclName = null;
        zeroSet = new Vector(1, 1);
        try {
            setName(principal, s);
        } catch(Exception exception) { }
    
Methods Summary
public synchronized booleanaddEntry(java.security.Principal principal, AclEntry aclentry)

        if(!isOwner(principal)) throw new NotOwnerException();
        Hashtable hashtable = findTable(aclentry);
        Principal principal1 = aclentry.getPrincipal();
        if(hashtable.get(principal1) != null) {
            return false;
        } else {
            hashtable.put(principal1, aclentry);
            return true;
        }
    
public booleancheckPermission(java.security.Principal principal, Permission permission)

        for(Enumeration enumeration = getPermissions(principal); enumeration.hasMoreElements();) {
            Permission permission1 = (Permission)enumeration.nextElement();
            if(permission1.equals(permission))
                return true;
        }
        return false;
    
public synchronized java.util.Enumerationentries()

        return new AclEnumerator(this, allowedUsersTable, allowedGroupsTable, deniedUsersTable, deniedGroupsTable);
    
private java.util.HashtablefindTable(AclEntry aclentry)

        Hashtable hashtable = null;
        Principal principal = aclentry.getPrincipal();
        if(principal instanceof Group) {
            if(aclentry.isNegative())
                hashtable = deniedGroupsTable;
            else
                hashtable = allowedGroupsTable;
        } else
        if(aclentry.isNegative())
            hashtable = deniedUsersTable;
        else
            hashtable = allowedUsersTable;
        return hashtable;
    
private java.util.EnumerationgetGroupNegative(java.security.Principal principal)

        Enumeration enumeration = zeroSet.elements();
        Enumeration enumeration1 = deniedGroupsTable.keys();
        do {
            if(!enumeration1.hasMoreElements())
                break;
            Group group = (Group)enumeration1.nextElement();
            if(group.isMember(principal)) {
                AclEntry aclentry = (AclEntry)deniedGroupsTable.get(group);
                enumeration = union(aclentry.permissions(), enumeration);
            }
        } while(true);
        return enumeration;
    
private java.util.EnumerationgetGroupPositive(java.security.Principal principal)

        Enumeration enumeration = zeroSet.elements();
        Enumeration enumeration1 = allowedGroupsTable.keys();
        do {
            if(!enumeration1.hasMoreElements())
                break;
            Group group = (Group)enumeration1.nextElement();
            if(group.isMember(principal)) {
                AclEntry aclentry = (AclEntry)allowedGroupsTable.get(group);
                enumeration = union(aclentry.permissions(), enumeration);
            }
        } while(true);
        return enumeration;
    
private java.util.EnumerationgetIndividualNegative(java.security.Principal principal)

        Enumeration enumeration = zeroSet.elements();
        AclEntry aclentry = (AclEntry)deniedUsersTable.get(principal);
        if(aclentry != null)
            enumeration = aclentry.permissions();
        return enumeration;
    
private java.util.EnumerationgetIndividualPositive(java.security.Principal principal)

        Enumeration enumeration = zeroSet.elements();
        AclEntry aclentry = (AclEntry)allowedUsersTable.get(principal);
        if(aclentry != null)
            enumeration = aclentry.permissions();
        return enumeration;
    
public java.lang.StringgetName()

        return aclName;
    
public synchronized java.util.EnumerationgetPermissions(java.security.Principal principal)

        Enumeration enumeration2 = subtract(getGroupPositive(principal), getGroupNegative(principal));
        Enumeration enumeration3 = subtract(getGroupNegative(principal), getGroupPositive(principal));
        Enumeration enumeration = subtract(getIndividualPositive(principal), getIndividualNegative(principal));
        Enumeration enumeration1 = subtract(getIndividualNegative(principal), getIndividualPositive(principal));
        Enumeration enumeration4 = subtract(enumeration2, enumeration1);
        Enumeration enumeration5 = union(enumeration, enumeration4);
        enumeration = subtract(getIndividualPositive(principal), getIndividualNegative(principal));
        enumeration1 = subtract(getIndividualNegative(principal), getIndividualPositive(principal));
        enumeration4 = subtract(enumeration3, enumeration);
        Enumeration enumeration6 = union(enumeration1, enumeration4);
        return subtract(enumeration5, enumeration6);
    
public synchronized booleanremoveEntry(java.security.Principal principal, AclEntry aclentry)

        if(!isOwner(principal)) {
            throw new NotOwnerException();
        } else {
            Hashtable hashtable = findTable(aclentry);
            Principal principal1 = aclentry.getPrincipal();
            Object obj = hashtable.remove(principal1);
            return obj != null;
        }
    
public voidsetName(java.security.Principal principal, java.lang.String s)

        if(!isOwner(principal)) {
            throw new NotOwnerException();
        } else {
            aclName = s;
            return;
        }
    
private java.util.Enumerationsubtract(java.util.Enumeration enumeration, java.util.Enumeration enumeration1)

        Vector vector = new Vector(20, 20);
        for(; enumeration.hasMoreElements(); vector.addElement(enumeration.nextElement()));
        do {
            if(!enumeration1.hasMoreElements())
                break;
            Object obj = enumeration1.nextElement();
            if(vector.contains(obj))
                vector.removeElement(obj);
        } while(true);
        return vector.elements();
    
public java.lang.StringtoString()

        StringBuffer stringbuffer = new StringBuffer();
        for(Enumeration enumeration = entries(); enumeration.hasMoreElements(); stringbuffer.append("\n")) {
            AclEntry aclentry = (AclEntry)enumeration.nextElement();
            stringbuffer.append(aclentry.toString().trim());
        }
        return stringbuffer.toString();
    
private static java.util.Enumerationunion(java.util.Enumeration enumeration, java.util.Enumeration enumeration1)

        Vector vector = new Vector(20, 20);
        for(; enumeration.hasMoreElements(); vector.addElement(enumeration.nextElement()));
        do {
            if(!enumeration1.hasMoreElements())
                break;
            Object obj = enumeration1.nextElement();
            if(!vector.contains(obj))
                vector.addElement(obj);
        } while(true);
        return vector.elements();