1. /*
  2. * @(#)file GroupImpl.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.util.Enumeration;
  14. import java.io.Serializable;
  15. import java.net.UnknownHostException;
  16. import java.security.Principal;
  17. import java.security.acl.Group;
  18. /**
  19. * This class is used to represent a subnet mask (a group of hosts
  20. * matching the same
  21. * IP mask).
  22. *
  23. * @version 4.9 12/19/03
  24. * @author Sun Microsystems, Inc
  25. */
  26. class GroupImpl extends PrincipalImpl implements Group, Serializable {
  27. /**
  28. * Constructs an empty group.
  29. * @exception UnknownHostException Not implemented
  30. */
  31. public GroupImpl () throws UnknownHostException {
  32. }
  33. /**
  34. * Constructs a group using the specified subnet mask.
  35. *
  36. * @param mask The subnet mask to use to build the group.
  37. * @exception UnknownHostException if the subnet mask cann't be built.
  38. */
  39. public GroupImpl (String mask) throws UnknownHostException {
  40. super(mask);
  41. }
  42. /**
  43. * Adds the specified member to the group.
  44. *
  45. * @param p the principal to add to this group.
  46. * @return true if the member was successfully added, false if the
  47. * principal was already a member.
  48. */
  49. public boolean addMember(Principal p) {
  50. // we don't need to add members because the ip address is a
  51. // subnet mask
  52. return true;
  53. }
  54. public int hashCode() {
  55. return super.hashCode();
  56. }
  57. /**
  58. * Compares this group to the specified object. Returns true if the object
  59. * passed in matches the group represented.
  60. *
  61. * @param p the object to compare with.
  62. * @return true if the object passed in matches the subnet mask,
  63. * false otherwise.
  64. */
  65. public boolean equals (Object p) {
  66. if (p instanceof PrincipalImpl || p instanceof GroupImpl){
  67. if ((super.hashCode() & p.hashCode()) == p.hashCode()) return true;
  68. else return false;
  69. } else {
  70. return false;
  71. }
  72. }
  73. /**
  74. * Returns true if the passed principal is a member of the group.
  75. *
  76. * @param p the principal whose membership is to be checked.
  77. * @return true if the principal is a member of this group, false otherwise.
  78. */
  79. public boolean isMember(Principal p) {
  80. if ((p.hashCode() & super.hashCode()) == p.hashCode()) return true;
  81. else return false;
  82. }
  83. /**
  84. * Returns an enumeration which contains the subnet mask.
  85. *
  86. * @return an enumeration which contains the subnet mask.
  87. */
  88. public Enumeration members(){
  89. Vector v = new Vector(1);
  90. v.addElement(this);
  91. return v.elements();
  92. }
  93. /**
  94. * Removes the specified member from the group. (Not implemented)
  95. *
  96. * @param p the principal to remove from this group.
  97. * @return allways return true.
  98. */
  99. public boolean removeMember(Principal p) {
  100. return true;
  101. }
  102. /**
  103. * Prints a string representation of this group.
  104. *
  105. * @return a string representation of this group.
  106. */
  107. public String toString() {
  108. return ("GroupImpl :"+super.getAddress().toString());
  109. }
  110. }