J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | |
| 27 | package com.sun.jmx.snmp.IPAcl; |
| 28 | |
| 29 | |
| 30 | |
| 31 | import java.util.Vector; |
| 32 | import java.util.Enumeration; |
| 33 | import java.io.Serializable; |
| 34 | import java.net.UnknownHostException; |
| 35 | |
| 36 | |
| 37 | import java.security.Principal; |
| 38 | import java.security.acl.Group; |
| 39 | |
| 40 | |
| 41 | /** |
| 42 | * This class is used to represent a subnet mask (a group of hosts |
| 43 | * matching the same |
| 44 | * IP mask). |
| 45 | * |
| 46 | */ |
| 47 | |
| 48 | class GroupImpl extends PrincipalImpl implements Group, Serializable { |
| 49 | private static final long serialVersionUID = -7777387035032541168L; |
| 50 | |
| 51 | /** |
| 52 | * Constructs an empty group. |
| 53 | * @exception UnknownHostException Not implemented |
| 54 | */ |
| 55 | public GroupImpl () throws UnknownHostException { |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Constructs a group using the specified subnet mask. |
| 60 | * |
| 61 | * @param mask The subnet mask to use to build the group. |
| 62 | * @exception UnknownHostException if the subnet mask cann't be built. |
| 63 | */ |
| 64 | public GroupImpl (String mask) throws UnknownHostException { |
| 65 | super(mask); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Adds the specified member to the group. |
| 70 | * |
| 71 | * @param p the principal to add to this group. |
| 72 | * @return true if the member was successfully added, false if the |
| 73 | * principal was already a member. |
| 74 | */ |
| 75 | public boolean addMember(Principal p) { |
| 76 | // we don't need to add members because the ip address is a |
| 77 | // subnet mask |
| 78 | return true; |
| 79 | } |
| 80 | |
| 81 | public int hashCode() { |
| 82 | return super.hashCode(); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Compares this group to the specified object. Returns true if the object |
| 87 | * passed in matches the group represented. |
| 88 | * |
| 89 | * @param p the object to compare with. |
| 90 | * @return true if the object passed in matches the subnet mask, |
| 91 | * false otherwise. |
| 92 | */ |
| 93 | public boolean equals (Object p) { |
| 94 | if (p instanceof PrincipalImpl || p instanceof GroupImpl){ |
| 95 | if ((super.hashCode() & p.hashCode()) == p.hashCode()) return true; |
| 96 | else return false; |
| 97 | } else { |
| 98 | return false; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Returns true if the passed principal is a member of the group. |
| 104 | * |
| 105 | * @param p the principal whose membership is to be checked. |
| 106 | * @return true if the principal is a member of this group, false otherwise. |
| 107 | */ |
| 108 | public boolean isMember(Principal p) { |
| 109 | if ((p.hashCode() & super.hashCode()) == p.hashCode()) return true; |
| 110 | else return false; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Returns an enumeration which contains the subnet mask. |
| 115 | * |
| 116 | * @return an enumeration which contains the subnet mask. |
| 117 | */ |
| 118 | public Enumeration<? extends Principal> members(){ |
| 119 | Vector<Principal> v = new Vector<Principal>(1); |
| 120 | v.addElement(this); |
| 121 | return v.elements(); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Removes the specified member from the group. (Not implemented) |
| 126 | * |
| 127 | * @param p the principal to remove from this group. |
| 128 | * @return allways return true. |
| 129 | */ |
| 130 | public boolean removeMember(Principal p) { |
| 131 | return true; |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Prints a string representation of this group. |
| 136 | * |
| 137 | * @return a string representation of this group. |
| 138 | */ |
| 139 | public String toString() { |
| 140 | return ("GroupImpl :"+super.getAddress().toString()); |
| 141 | } |
| 142 | } |