0N/A/*
2362N/A * Copyright (c) 1996, 2006, 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/Apackage sun.security.acl;
0N/A
0N/Aimport java.util.*;
0N/Aimport java.security.*;
0N/Aimport java.security.acl.*;
0N/A
0N/A/**
0N/A * Class implementing the Owner interface. The
0N/A * initial owner principal is configured as
0N/A * part of the constructor.
0N/A * @author Satish Dharmaraj
0N/A */
0N/Apublic class OwnerImpl implements Owner {
0N/A private Group ownerGroup;
0N/A
0N/A public OwnerImpl(Principal owner) {
0N/A ownerGroup = new GroupImpl("AclOwners");
0N/A ownerGroup.addMember(owner);
0N/A }
0N/A
0N/A /**
0N/A * Adds an owner. Owners can modify ACL contents and can disassociate
0N/A * ACLs from the objects they protect in the AclConfig interface.
0N/A * The caller principal must be a part of the owners list of the ACL in
0N/A * order to invoke this method. The initial owner is configured
0N/A * at ACL construction time.
0N/A * @param caller the principal who is invoking this method.
0N/A * @param owner The owner that should be added to the owners list.
0N/A * @return true if success, false if already an owner.
0N/A * @exception NotOwnerException if the caller principal is not on
0N/A * the owners list of the Acl.
0N/A */
0N/A public synchronized boolean addOwner(Principal caller, Principal owner)
0N/A throws NotOwnerException
0N/A {
0N/A if (!isOwner(caller))
0N/A throw new NotOwnerException();
0N/A
0N/A ownerGroup.addMember(owner);
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * Delete owner. If this is the last owner in the ACL, an exception is
0N/A * raised.
0N/A * The caller principal must be a part of the owners list of the ACL in
0N/A * order to invoke this method.
0N/A * @param caller the principal who is invoking this method.
0N/A * @param owner The owner to be removed from the owners list.
0N/A * @return true if the owner is removed, false if the owner is not part
0N/A * of the owners list.
0N/A * @exception NotOwnerException if the caller principal is not on
0N/A * the owners list of the Acl.
0N/A * @exception LastOwnerException if there is only one owner left in the group, then
0N/A * deleteOwner would leave the ACL owner-less. This exception is raised in such a case.
0N/A */
0N/A public synchronized boolean deleteOwner(Principal caller, Principal owner)
0N/A throws NotOwnerException, LastOwnerException
0N/A {
0N/A if (!isOwner(caller))
0N/A throw new NotOwnerException();
0N/A
0N/A Enumeration<? extends Principal> e = ownerGroup.members();
0N/A //
0N/A // check if there is atleast 2 members left.
0N/A //
0N/A Object o = e.nextElement();
0N/A if (e.hasMoreElements())
0N/A return ownerGroup.removeMember(owner);
0N/A else
0N/A throw new LastOwnerException();
0N/A
0N/A }
0N/A
0N/A /**
0N/A * returns if the given principal belongs to the owner list.
0N/A * @param owner The owner to check if part of the owners list
0N/A * @return true if the passed principal is in the owner list, false if not.
0N/A */
0N/A public synchronized boolean isOwner(Principal owner) {
0N/A return ownerGroup.isMember(owner);
0N/A }
0N/A}