0N/A/*
2362N/A * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A
0N/Apackage com.sun.jmx.snmp.IPAcl;
0N/A
0N/A
0N/A
0N/Aimport java.security.acl.Permission;
0N/Aimport java.util.Vector;
0N/Aimport java.util.Enumeration;
0N/Aimport java.io.Serializable;
0N/Aimport java.net.UnknownHostException;
0N/A
0N/Aimport java.security.Principal;
0N/Aimport java.security.acl.AclEntry;
0N/A
0N/A
0N/A/**
0N/A * Represent one entry in the Access Control List (ACL).
0N/A * This ACL entry object contains a permission associated with a particular principal.
0N/A * (A principal represents an entity such as an individual machine or a group).
0N/A *
0N/A * @see java.security.acl.AclEntry
0N/A */
0N/A
0N/Aclass AclEntryImpl implements AclEntry, Serializable {
0N/A private static final long serialVersionUID = -5047185131260073216L;
0N/A
0N/A private AclEntryImpl (AclEntryImpl i) throws UnknownHostException {
0N/A setPrincipal(i.getPrincipal());
0N/A permList = new Vector<Permission>();
0N/A commList = new Vector<String>();
0N/A
0N/A for (Enumeration<String> en = i.communities(); en.hasMoreElements();){
0N/A addCommunity(en.nextElement());
0N/A }
0N/A
0N/A for (Enumeration<Permission> en = i.permissions(); en.hasMoreElements();){
0N/A addPermission(en.nextElement());
0N/A }
0N/A if (i.isNegative()) setNegativePermissions();
0N/A }
0N/A
0N/A /**
0N/A * Contructs an empty ACL entry.
0N/A */
0N/A public AclEntryImpl (){
0N/A princ = null;
0N/A permList = new Vector<Permission>();
0N/A commList = new Vector<String>();
0N/A }
0N/A
0N/A /**
0N/A * Constructs an ACL entry with a specified principal.
0N/A *
0N/A * @param p the principal to be set for this entry.
0N/A */
0N/A public AclEntryImpl (Principal p) throws UnknownHostException {
0N/A princ = p;
0N/A permList = new Vector<Permission>();
0N/A commList = new Vector<String>();
0N/A }
0N/A
0N/A /**
0N/A * Clones this ACL entry.
0N/A *
0N/A * @return a clone of this ACL entry.
0N/A */
0N/A public Object clone() {
0N/A AclEntryImpl i;
0N/A try {
0N/A i = new AclEntryImpl(this);
0N/A }catch (UnknownHostException e) {
0N/A i = null;
0N/A }
0N/A return (Object) i;
0N/A }
0N/A
0N/A /**
0N/A * Returns true if this is a negative ACL entry (one denying the associated principal
0N/A * the set of permissions in the entry), false otherwise.
0N/A *
0N/A * @return true if this is a negative ACL entry, false if it's not.
0N/A */
0N/A public boolean isNegative(){
0N/A return neg;
0N/A }
0N/A
0N/A /**
0N/A * Adds the specified permission to this ACL entry. Note: An entry can
0N/A * have multiple permissions.
0N/A *
0N/A * @param perm the permission to be associated with the principal in this
0N/A * entry
0N/A * @return true if the permission is removed, false if the permission was
0N/A * not part of this entry's permission set.
0N/A *
0N/A */
0N/A public boolean addPermission(java.security.acl.Permission perm){
0N/A if (permList.contains(perm)) return false;
0N/A permList.addElement(perm);
0N/A return true;
0N/A }
0N/A
0N/A /**
0N/A * Removes the specified permission from this ACL entry.
0N/A *
0N/A * @param perm the permission to be removed from this entry.
0N/A * @return true if the permission is removed, false if the permission
0N/A * was not part of this entry's permission set.
0N/A */
0N/A public boolean removePermission(java.security.acl.Permission perm){
0N/A if (!permList.contains(perm)) return false;
0N/A permList.removeElement(perm);
0N/A return true;
0N/A }
0N/A
0N/A /**
0N/A * Checks if the specified permission is part of the permission set in
0N/A * this entry.
0N/A *
0N/A * @param perm the permission to be checked for.
0N/A * @return true if the permission is part of the permission set in this
0N/A * entry, false otherwise.
0N/A */
0N/A
0N/A public boolean checkPermission(java.security.acl.Permission perm){
0N/A return (permList.contains(perm));
0N/A }
0N/A
0N/A /**
0N/A * Returns an enumeration of the permissions in this ACL entry.
0N/A *
0N/A * @return an enumeration of the permissions in this ACL entry.
0N/A */
0N/A public Enumeration<Permission> permissions(){
0N/A return permList.elements();
0N/A }
0N/A
0N/A /**
0N/A * Sets this ACL entry to be a negative one. That is, the associated principal
0N/A * (e.g., a user or a group) will be denied the permission set specified in the
0N/A * entry. Note: ACL entries are by default positive. An entry becomes a negative
0N/A * entry only if this setNegativePermissions method is called on it.
0N/A *
0N/A * Not Implemented.
0N/A */
0N/A public void setNegativePermissions(){
0N/A neg = true;
0N/A }
0N/A
0N/A /**
0N/A * Returns the principal for which permissions are granted or denied by this ACL
0N/A * entry. Returns null if there is no principal set for this entry yet.
0N/A *
0N/A * @return the principal associated with this entry.
0N/A */
0N/A public Principal getPrincipal(){
0N/A return princ;
0N/A }
0N/A
0N/A /**
0N/A * Specifies the principal for which permissions are granted or denied by
0N/A * this ACL entry. If a principal was already set for this ACL entry,
0N/A * false is returned, otherwise true is returned.
0N/A *
0N/A * @param p the principal to be set for this entry.
0N/A * @return true if the principal is set, false if there was already a
0N/A * principal set for this entry.
0N/A */
0N/A public boolean setPrincipal(Principal p) {
0N/A if (princ != null )
0N/A return false;
0N/A princ = p;
0N/A return true;
0N/A }
0N/A
0N/A /**
0N/A * Returns a string representation of the contents of this ACL entry.
0N/A *
0N/A * @return a string representation of the contents.
0N/A */
0N/A public String toString(){
0N/A return "AclEntry:"+princ.toString();
0N/A }
0N/A
0N/A /**
0N/A * Returns an enumeration of the communities in this ACL entry.
0N/A *
0N/A * @return an enumeration of the communities in this ACL entry.
0N/A */
0N/A public Enumeration<String> communities(){
0N/A return commList.elements();
0N/A }
0N/A
0N/A /**
0N/A * Adds the specified community to this ACL entry. Note: An entry can
0N/A * have multiple communities.
0N/A *
0N/A * @param comm the community to be associated with the principal
0N/A * in this entry.
0N/A * @return true if the community was added, false if the community was
0N/A * already part of this entry's community set.
0N/A */
0N/A public boolean addCommunity(String comm){
0N/A if (commList.contains(comm)) return false;
0N/A commList.addElement(comm);
0N/A return true;
0N/A }
0N/A
0N/A /**
0N/A * Removes the specified community from this ACL entry.
0N/A *
0N/A * @param comm the community to be removed from this entry.
0N/A * @return true if the community is removed, false if the community was
0N/A * not part of this entry's community set.
0N/A */
0N/A public boolean removeCommunity(String comm){
0N/A if (!commList.contains(comm)) return false;
0N/A commList.removeElement(comm);
0N/A return true;
0N/A }
0N/A
0N/A /**
0N/A * Checks if the specified community is part of the community set in this
0N/A * entry.
0N/A *
0N/A * @param comm the community to be checked for.
0N/A * @return true if the community is part of the community set in this
0N/A * entry, false otherwise.
0N/A */
0N/A public boolean checkCommunity(String comm){
0N/A return (commList.contains(comm));
0N/A }
0N/A
0N/A private Principal princ = null;
0N/A private boolean neg = false;
0N/A private Vector<Permission> permList = null;
0N/A private Vector<String> commList = null;
0N/A}