Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/security/acl/OwnerImpl.java
38830 views
/*1* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.security.acl;2627import java.util.*;28import java.security.*;29import java.security.acl.*;3031/**32* Class implementing the Owner interface. The33* initial owner principal is configured as34* part of the constructor.35* @author Satish Dharmaraj36*/37public class OwnerImpl implements Owner {38private Group ownerGroup;3940public OwnerImpl(Principal owner) {41ownerGroup = new GroupImpl("AclOwners");42ownerGroup.addMember(owner);43}4445/**46* Adds an owner. Owners can modify ACL contents and can disassociate47* ACLs from the objects they protect in the AclConfig interface.48* The caller principal must be a part of the owners list of the ACL in49* order to invoke this method. The initial owner is configured50* at ACL construction time.51* @param caller the principal who is invoking this method.52* @param owner The owner that should be added to the owners list.53* @return true if success, false if already an owner.54* @exception NotOwnerException if the caller principal is not on55* the owners list of the Acl.56*/57public synchronized boolean addOwner(Principal caller, Principal owner)58throws NotOwnerException59{60if (!isOwner(caller))61throw new NotOwnerException();6263ownerGroup.addMember(owner);64return false;65}6667/**68* Delete owner. If this is the last owner in the ACL, an exception is69* raised.70* The caller principal must be a part of the owners list of the ACL in71* order to invoke this method.72* @param caller the principal who is invoking this method.73* @param owner The owner to be removed from the owners list.74* @return true if the owner is removed, false if the owner is not part75* of the owners list.76* @exception NotOwnerException if the caller principal is not on77* the owners list of the Acl.78* @exception LastOwnerException if there is only one owner left in the group, then79* deleteOwner would leave the ACL owner-less. This exception is raised in such a case.80*/81public synchronized boolean deleteOwner(Principal caller, Principal owner)82throws NotOwnerException, LastOwnerException83{84if (!isOwner(caller))85throw new NotOwnerException();8687Enumeration<? extends Principal> e = ownerGroup.members();88//89// check if there is atleast 2 members left.90//91Object o = e.nextElement();92if (e.hasMoreElements())93return ownerGroup.removeMember(owner);94else95throw new LastOwnerException();9697}9899/**100* returns if the given principal belongs to the owner list.101* @param owner The owner to check if part of the owners list102* @return true if the passed principal is in the owner list, false if not.103*/104public synchronized boolean isOwner(Principal owner) {105return ownerGroup.isMember(owner);106}107}108109110