1. /*
  2. * @(#)file OwnerImpl.java
  3. * @(#)author Sun Microsystems, Inc.
  4. * @(#)version 4.9
  5. * @(#)date 04/09/15
  6. *
  7. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  8. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  9. *
  10. */
  11. package com.sun.jmx.snmp.IPAcl;
  12. import java.util.Vector;
  13. import java.io.Serializable;
  14. import java.security.Principal;
  15. import java.security.acl.Owner;
  16. import java.security.acl.LastOwnerException;
  17. import java.security.acl.NotOwnerException;
  18. /**
  19. * Owner of Access Control Lists (ACLs).
  20. * The initial owner Principal should be specified as an
  21. * argument to the constructor of the class AclImpl.
  22. *
  23. * @see java.security.acl.Owner
  24. * @version 4.9 12/19/03
  25. * @author Sun Microsystems, Inc
  26. */
  27. class OwnerImpl implements Owner, Serializable {
  28. private Vector ownerList = null;
  29. /**
  30. * Constructs an empty list of owner.
  31. */
  32. public OwnerImpl (){
  33. ownerList = new Vector();
  34. }
  35. /**
  36. * Constructs a list of owner with the specified principal as first element.
  37. *
  38. * @param owner the principal added to the owner list.
  39. */
  40. public OwnerImpl (PrincipalImpl owner){
  41. ownerList = new Vector();
  42. ownerList.addElement(owner);
  43. }
  44. /**
  45. * Adds an owner. Only owners can modify ACL contents. The caller principal
  46. * must be an owner of the ACL in order to invoke this method. That is, only
  47. * an owner can add another owner. The initial owner is configured at
  48. * ACL construction time.
  49. *
  50. * @param caller the principal invoking this method.
  51. * It must be an owner of the ACL.
  52. * @param owner the owner that should be added to the list of owners.
  53. * @return true if successful, false if owner is already an owner.
  54. * @exception NotOwnerException if the caller principal is not an owner
  55. * of the ACL.
  56. */
  57. public boolean addOwner(Principal caller, Principal owner)
  58. throws NotOwnerException {
  59. if (!ownerList.contains(caller))
  60. throw new NotOwnerException();
  61. if (ownerList.contains(owner)) {
  62. return false;
  63. } else {
  64. ownerList.addElement(owner);
  65. return true;
  66. }
  67. }
  68. /**
  69. * Deletes an owner. If this is the last owner in the ACL, an exception is raised.
  70. *<P>
  71. * The caller principal must be an owner of the ACL in order to invoke this method.
  72. *
  73. * @param caller the principal invoking this method. It must be an owner
  74. * of the ACL.
  75. * @param owner the owner to be removed from the list of owners.
  76. * @return true if successful, false if owner is already an owner.
  77. * @exception NotOwnerException if the caller principal is not an owner
  78. * of the ACL.
  79. * @exception LastOwnerException if there is only one owner left, so that
  80. * deleteOwner would leave the ACL owner-less.
  81. */
  82. public boolean deleteOwner(Principal caller, Principal owner)
  83. throws NotOwnerException,LastOwnerException {
  84. if (!ownerList.contains(caller))
  85. throw new NotOwnerException();
  86. if (!ownerList.contains(owner)){
  87. return false;
  88. } else {
  89. if (ownerList.size() == 1)
  90. throw new LastOwnerException();
  91. ownerList.removeElement(owner);
  92. return true;
  93. }
  94. }
  95. /**
  96. * Returns true if the given principal is an owner of the ACL.
  97. *
  98. * @param owner the principal to be checked to determine whether or
  99. * not it is an owner.
  100. * @return true if the given principal is an owner of the ACL.
  101. */
  102. public boolean isOwner(Principal owner){
  103. return ownerList.contains(owner);
  104. }
  105. }