/* * @(#)file AclImpl.java * @(#)author Sun Microsystems, Inc. * @(#)version 4.11 * @(#)date 06/05/03 * * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * */ package com.sun.jmx.snmp.IPAcl; import java.security.Principal; import java.security.acl.Acl; import java.security.acl.AclEntry; import java.security.acl.NotOwnerException; import java.io.Serializable; import java.util.Vector; import java.util.Enumeration; /** * Represent an Access Control List (ACL) which is used to guard access to http adaptor. *
* It is a data structure with multiple ACL entries. Each ACL entry, of interface type * AclEntry, contains a set of permissions and a set of communities associated with a * particular principal. (A principal represents an entity such as a host or a group of host). * Additionally, each ACL entry is specified as being either positive or negative. * If positive, the permissions are to be granted to the associated principal. * If negative, the permissions are to be denied. * * @see java.security.acl.Acl * @version 4.11 12/19/03 * @author Sun Microsystems, Inc */ class AclImpl extends OwnerImpl implements Acl, Serializable { private Vector entryList = null; private String aclName = null; /** * Constructs the ACL with a specified owner * * @param owner owner of the ACL. * @param name name of this ACL. */ public AclImpl (PrincipalImpl owner, String name) { super(owner); entryList = new Vector(); aclName = name; } /** * Sets the name of this ACL. * * @param caller the principal invoking this method. It must be an owner * of this ACL. * @param name the name to be given to this ACL. * * @exception NotOwnerException if the caller principal is not an owner * of this ACL. * @see java.security.Principal */ public void setName(Principal caller, String name) throws NotOwnerException { if (!isOwner(caller)) throw new NotOwnerException(); aclName = name; } /** * Returns the name of this ACL. * * @return the name of this ACL. */ public String getName(){ return aclName; } /** * Adds an ACL entry to this ACL. An entry associates a principal (e.g., an individual or a group) * with a set of permissions. Each principal can have at most one positive ACL entry * (specifying permissions to be granted to the principal) and one negative ACL entry * (specifying permissions to be denied). If there is already an ACL entry * of the same type (negative or positive) already in the ACL, false is returned. * * @param caller the principal invoking this method. It must be an owner * of this ACL. * @param entry the ACL entry to be added to this ACL. * @return true on success, false if an entry of the same type (positive * or negative) for the same principal is already present in this ACL. * @exception NotOwnerException if the caller principal is not an owner of * this ACL. * @see java.security.Principal */ public boolean addEntry(Principal caller, AclEntry entry) throws NotOwnerException { if (!isOwner(caller)) throw new NotOwnerException(); if (entryList.contains(entry)) return false; /* for (Enumeration e = entryList.elements();e.hasMoreElements();){ AclEntry ent = (AclEntry) e.nextElement(); if (ent.getPrincipal().equals(entry.getPrincipal())) return false; } */ entryList.addElement(entry); return true; } /** * Removes an ACL entry from this ACL. * * @param caller the principal invoking this method. It must be an owner * of this ACL. * @param entry the ACL entry to be removed from this ACL. * @return true on success, false if the entry is not part of this ACL. * @exception NotOwnerException if the caller principal is not an owner * of this Acl. * @see java.security.Principal * @see java.security.acl.AclEntry */ public boolean removeEntry(Principal caller, AclEntry entry) throws NotOwnerException { if (!isOwner(caller)) throw new NotOwnerException(); return (entryList.removeElement(entry)); } /** * Removes all ACL entries from this ACL. * * @param caller the principal invoking this method. It must be an owner * of this ACL. * @exception NotOwnerException if the caller principal is not an owner of * this Acl. * @see java.security.Principal */ public void removeAll(Principal caller) throws NotOwnerException { if (!isOwner(caller)) throw new NotOwnerException(); entryList.removeAllElements(); } /** * Returns an enumeration for the set of allowed permissions for * the specified principal * (representing an entity such as an individual or a group). * This set of allowed permissions is calculated as follows: *