2 * @(#)Group.java 1.0 6/29/2001
4 * Copyright (c) 2001 International Business Machines Corp.
7 * This software has been released under the terms of the IBM Public
8 * License. For details, see the LICENSE file in the top-level source
9 * directory or online at http://www.openafs.org/dl/license10.html
11 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
12 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
13 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
14 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
15 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
16 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
17 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
18 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
19 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
20 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 package org
.openafs
.jafs
;
26 import java
.util
.Vector
;
27 import java
.util
.Enumeration
;
28 import java
.util
.ArrayList
;
29 import java
.io
.Serializable
;
32 * An abstract representation of an AFS group. It holds information about
33 * the group, such as what groups it owns.<BR><BR>
35 * Constructing an instance of a <code>Group</code> does not mean an actual
36 * AFS group is created in a cell -- usually a <code>Group</code>
37 * object is a representation of an already existing AFS group. If,
38 * however, the <code>Group</code> is constructed with the name of a
39 * group that does not exist in the cell represented by the provided
40 * <code>Cell</code>, a new group with that name can be
41 * created in that cell by calling the {@link #create(String, int)} or
42 * {@link #create(String)} method. If such a group does already exist when
43 * one of these methods is called, an exception will be thrown.<BR><BR>
45 * Each <code>Group</code> object has its own individual set of
46 * <code>Group</code>s that it owns and <code>User</code>s that belong
47 * to it. These represents the properties and attributes
48 * of an actual AFS group.
51 * <!--Information on how member values are set-->
53 * Associated with an AFS group are many attributes, such as whether or not
54 * who is allowed to list the members of this group. The <code>Group</code>
55 * class has many "set" methods to indicate values for these attributes (i.e.
56 * {@link #setListMembership(int)}. However, in order for these values to be
57 * written to the actual AFS group, the {@link #flushInfo()} method needs to
58 * be called. This writes all user attributes set through this API to AFS.
59 * This is done to minimize calls through JNI.<BR><BR>
61 * <!--Example of how to use class-->
62 * The following is a simple example of how to construct and use a
63 * <code>Group</code> object. It lists the name and owner of a specified
67 * import org.openafs.jafs.Cell;
68 * import org.openafs.jafs.AFSException;
69 * import org.openafs.jafs.Partition;
70 * import org.openafs.jafs.Group;
76 * private Group group;
78 * public static void main(String[] args) throws Exception
80 * String username = arg[0];
81 * String password = arg[1];
82 * String cellName = arg[2];
83 * String groupName = arg[3];
85 * token = new Token(username, password, cellName);
86 * cell = new Cell(token);
87 * group = new Group(groupName, cell);
89 * System.out.println("Owner of group " + group.getName() + " is "
90 * + group.getOwnerName());
98 public class Group
implements PTSEntry
, Serializable
, Comparable
101 * Only the owner of the group has access
103 public static final int GROUP_OWNER_ACCESS
= 0;
105 * Members of the group have access
107 public static final int GROUP_GROUP_ACCESS
= 1;
109 * Any user has access
111 public static final int GROUP_ANYUSER_ACCESS
= 2;
114 protected long cellHandle
;
115 protected String name
;
117 protected int membershipCount
;
118 protected int nameUID
;
119 protected int ownerUID
;
120 protected int creatorUID
;
122 protected String owner
;
123 protected String creator
;
126 * who is allowed to execute PTS examine for this group. Valid values are:
128 * <li>{@link #GROUP_OWNER_ACCESS} -- only the owner has permission</li>
129 * <li>{@link #GROUP_GROUP_ACCESS}
130 * -- only members of the group have permission</li>
131 * <li>{@link #GROUP_ANYUSER_ACCESS} -- any user has permission</li></ul>
133 protected int listStatus
;
135 * who is allowed to execute PTS examine for this group. Valid values are:
137 * <li>{@link #GROUP_OWNER_ACCESS} -- only the owner has permission</li>
138 * <li>{@link #GROUP_GROUP_ACCESS}
139 * -- only members of the group have permission</li>
140 * <li>{@link #GROUP_ANYUSER_ACCESS} -- any user has permission</li></ul>
142 protected int listGroupsOwned
;
144 * who is allowed to execute PTS listowned for this group. Valid values are:
146 * <li>{@link #GROUP_OWNER_ACCESS} -- only the owner has permission</li>
147 * <li>{@link #GROUP_GROUP_ACCESS}
148 * -- only members of the group have permission</li>
149 * <li>{@link #GROUP_ANYUSER_ACCESS} -- any user has permission</li></ul>
151 protected int listMembership
;
153 * who is allowed to execute PTS adduser for this group. Valid values are:
155 * <li>{@link #GROUP_OWNER_ACCESS} -- only the owner has permission</li>
156 * <li>{@link #GROUP_GROUP_ACCESS}
157 * -- only members of the group have permission</li>
158 * <li>{@link #GROUP_ANYUSER_ACCESS} -- any user has permission</li></ul>
160 protected int listAdd
;
162 * who is allowed to execute PTS removeuser for this group. Valid
165 * <li>{@link #GROUP_OWNER_ACCESS} -- only the owner has permission</li>
166 * <li>{@link #GROUP_GROUP_ACCESS}
167 * -- only members of the group have permission</li>
168 * <li>{@link #GROUP_ANYUSER_ACCESS} -- any user has permission</li></ul>
170 protected int listDelete
;
172 protected ArrayList members
;
173 protected ArrayList memberNames
;
174 protected ArrayList groupsOwned
;
175 protected ArrayList groupsOwnedNames
;
178 * Whether or not the information fields of this group have been filled.
180 protected boolean cachedInfo
;
183 * Constructs a new <code>Group</code> object instance given the name
184 * of the AFS group and the AFS cell, represented by
185 * <CODE>cell</CODE>, to which it belongs. This does not actually
186 * create a new AFS group, it just represents one.
187 * If <code>name</code> is not an actual AFS group, exceptions
188 * will be thrown during subsequent method invocations on this
189 * object, unless the {@link #create(String, int)} or {@link #create(String)}
190 * method is explicitly called to create it.
192 * @param name the name of the group to represent
193 * @param cell the cell to which the group belongs.
194 * @exception AFSException If an error occurs in the native code
196 public Group( String name
, Cell cell
) throws AFSException
200 cellHandle
= cell
.getCellHandle();
205 groupsOwnedNames
= null;
210 * Constructs a new <code>Group</code> object instance given the name
211 * of the AFS group and the AFS cell, represented by
212 * <CODE>cell</CODE>, to which it belongs. This does not actually
213 * create a new AFS group, it just represents one.
214 * If <code>name</code> is not an actual AFS group, exceptions
215 * will be thrown during subsequent method invocations on this
216 * object, unless the {@link #create(String, int)} or {@link #create(String)}
217 * method is explicitly called to create it. Note that if the process
218 * doesn't exist and <code>preloadAllMembers</code> is true, an exception
221 * <P> This constructor is ideal for point-in-time representation and
222 * transient applications. It ensures all data member values are set and
223 * available without calling back to the filesystem at the first request
224 * for them. Use the {@link #refresh()} method to address any coherency
227 * @param name the name of the group to represent
228 * @param cell the cell to which the group belongs.
229 * @param preloadAllMembers true will ensure all object members are
230 * set upon construction;
231 * otherwise members will be set upon access,
232 * which is the default behavior.
233 * @exception AFSException If an error occurs in the native code
236 public Group( String name
, Cell cell
, boolean preloadAllMembers
)
240 if (preloadAllMembers
) refresh(true);
244 * Creates a blank <code>Group</code> given the cell to which the group
245 * belongs. Other methods cvan then be used to fill the fields of this
248 * @exception AFSException If an error occurs in the native code
249 * @param cell the cell to which the group belongs.
251 Group( Cell cell
) throws AFSException
256 /*-------------------------------------------------------------------------*/
259 * Creates the PTS entry for a new group in this cell. Automatically assigns
262 * @param ownerName the owner of this group
264 public void create( String ownerName
) throws AFSException
266 this.create( ownerName
, 0 );
270 * Creates the PTS entry for a new group in this cell.
272 * @param ownerName the owner of this group
273 * @param gid the group id to assign to the new group
274 * @exception AFSException If an error occurs in the native code
276 public void create( String ownerName
, int gid
) throws AFSException
278 Group
.create( cell
.getCellHandle(), name
, ownerName
, gid
);
282 * Deletes the PTS entry for a group in this cell. Deletes this group
283 * from the membership list of the user that belonged to it, but does not
284 * delete the groups owned by this group. Also nullifies the Java object.
286 * @exception AFSException If an error occurs in the native code
288 public void delete() throws AFSException
290 Group
.delete( cell
.getCellHandle(), name
);
299 groupsOwnedNames
= null;
302 } catch( Throwable t
) {
303 throw new AFSException( t
.getMessage() );
308 * Flushes the current information of this <code>Group</code> object to disk.
309 * This will update the information of the actual AFS group to match the
310 * settings that have been modified in this <code>Group</code> object.
311 * This function must be called before any changes made to the information
312 * fields of this group will be seen by the AFS system.
314 * @exception AFSException If an error occurs in the native code
316 public void flushInfo() throws AFSException
318 Group
.setGroupInfo( cell
.getCellHandle(), name
, this );
322 * Add the specified member to this group.
324 * @param userName the <code>User</code> object to add
325 * @exception AFSException If an error occurs in the native code
327 public void addMember( User theUser
) throws AFSException
329 String userName
= theUser
.getName();
331 Group
.addMember( cell
.getCellHandle(), name
, userName
);
334 if( memberNames
!= null ) {
335 memberNames
.add( userName
);
337 if( members
!= null ) {
338 members
.add( new User( userName
, cell
) );
343 * Remove the specified member from this group.
344 * @param userName the <code>User</code> object to remove
345 * @exception AFSException If an error occurs in the native code
347 public void removeMember( User theUser
) throws AFSException
349 String userName
= theUser
.getName();
350 Group
.removeMember( cell
.getCellHandle(), name
, userName
);
353 if( memberNames
!= null ) {
354 memberNames
.remove( memberNames
.indexOf(userName
) );
355 memberNames
.trimToSize();
357 if( members
!= null && members
.indexOf(theUser
) > -1) {
358 members
.remove( members
.indexOf(theUser
) );
359 members
.trimToSize();
364 * Change the owner of this group.
366 * @param ownerName the new owner <code>User</code> object
367 * @exception AFSException If an error occurs in the native code
369 public void changeOwner( User theOwner
) throws AFSException
371 String ownerName
= theOwner
.getName();
373 Group
.changeOwner( cell
.getCellHandle(), name
, ownerName
);
381 * Change the owner of this group.
383 * @param ownerName the new owner <code>Group</code> object
384 * @exception AFSException If an error occurs in the native code
386 public void changeOwner( Group theOwner
) throws AFSException
388 String ownerName
= theOwner
.getName();
389 Group
.changeOwner( cell
.getCellHandle(), name
, ownerName
);
396 * Change the name of this group.
398 * @param newName the new name for this group
399 * @exception AFSException If an error occurs in the native code
401 public void rename( String newName
) throws AFSException
403 Group
.rename( cell
.getCellHandle(), name
, newName
);
408 * Refreshes the properties of this Group object instance with values from
409 * the AFS group it represents. All properties that have been initialized
410 * and/or accessed will be renewed according to the values of the AFS group
411 * this <code>Group</code> object instance represents.
413 * <P>Since in most environments administrative changes can be administered
414 * from an AFS command-line program or an alternate GUI application, this
415 * method provides a means to refresh the Java object representation and
416 * thereby ascertain any possible modifications that may have been made
417 * from such alternate administrative programs. Using this method before
418 * an associated instance accessor will ensure the highest level of
419 * representative accuracy, accommodating changes made external to the
420 * Java application space. If administrative changes to the underlying AFS
421 * system are only allowed via this API, then the use of this method is
424 * @exception AFSException If an error occurs in the native code
426 public void refresh() throws AFSException
432 * Refreshes the properties of this Group object instance with values from
433 * the AFS group it represents. If <CODE>all</CODE> is <CODE>true</CODE>
434 * then <U>all</U> of the properties of this Group object instance will be
435 * set, or renewed, according to the values of the AFS group it represents,
436 * disregarding any previously set properties.
438 * <P> Thus, if <CODE>all</CODE> is <CODE>false</CODE> then properties that
439 * are currently set will be refreshed and properties that are not set will
440 * remain uninitialized. See {@link #refresh()} for more information.
442 * @param all if true set or renew all object properties; otherwise renew
444 * @exception AFSException If an error occurs in the native code
447 protected void refresh(boolean all
) throws AFSException
449 if( all
|| cachedInfo
) {
452 if( all
|| groupsOwned
!= null ) {
453 refreshGroupsOwned();
455 if( all
|| groupsOwnedNames
!= null ) {
456 refreshGroupsOwnedNames();
458 if( all
|| members
!= null ) {
461 if( all
|| memberNames
!= null ) {
462 refreshMemberNames();
467 * Refreshes the information fields of this <code>Group</code> to reflect
468 * the current state of the AFS group. Does not refresh the members that
469 * belong to the group, nor the groups the group owns.
471 * @exception AFSException If an error occurs in the native code
473 protected void refreshInfo() throws AFSException
476 Group
.getGroupInfo( cell
.getCellHandle(), name
, this );
480 * Refreshes the current information about the <code>User</code> objects
481 * belonging to this group. Does not refresh the information fields of
482 * the group or groups owned.
484 * @exception AFSException If an error occurs in the native code
486 protected void refreshMembers() throws AFSException
490 long iterationID
= Group
.getGroupMembersBegin( cell
.getCellHandle(), name
);
492 members
= new ArrayList();
494 currUser
= new User( cell
);
495 while( Group
.getGroupMembersNext( cellHandle
, iterationID
, currUser
)
497 members
.add( currUser
);
498 currUser
= new User( cell
);
501 Group
.getGroupMembersDone( iterationID
);
505 * Refreshes the current information about the names of members belonging
506 * to this group. Does not refresh the information fields of the group
509 * @exception AFSException If an error occurs in the native code
511 protected void refreshMemberNames() throws AFSException
514 long iterationID
= Group
.getGroupMembersBegin( cell
.getCellHandle(), name
);
516 memberNames
= new ArrayList();
518 while( ( currName
= Group
.getGroupMembersNextString( iterationID
) )
520 memberNames
.add( currName
);
522 Group
.getGroupMembersDone( iterationID
);
526 * Refreshes the current information about the <code>Group</code> objects the
527 * group owns. Does not refresh the information fields of the group or
530 * @exception AFSException If an error occurs in the native code
532 protected void refreshGroupsOwned() throws AFSException
536 long iterationID
= User
.getGroupsOwnedBegin( cell
.getCellHandle(), name
);
538 groupsOwned
= new ArrayList();
540 currGroup
= new Group( cell
);
541 while( User
.getGroupsOwnedNext( cellHandle
, iterationID
, currGroup
)
543 groupsOwned
.add( currGroup
);
544 currGroup
= new Group( cell
);
547 User
.getGroupsOwnedDone( iterationID
);
551 * Refreshes the current information about the names of groups the group
552 * owns. Does not refresh the information fields of the group or members.
554 * @exception AFSException If an error occurs in the native code
556 protected void refreshGroupsOwnedNames() throws AFSException
560 long iterationID
= User
.getGroupsOwnedBegin( cell
.getCellHandle(), name
);
562 groupsOwnedNames
= new ArrayList();
563 while( ( currName
= User
.getGroupsOwnedNextString( iterationID
) )
565 groupsOwnedNames
.add( currName
);
567 User
.getGroupsOwnedDone( iterationID
);
571 * Adds an access control list entry for some AFS directory for this group.
573 * @param directory the full path of the place in the AFS file system
574 * for which to add an entry
575 * @param read whether or not to allow read access to this user
576 * @param write whether or not to allow write access to this user
577 * @param lookup whether or not to allow lookup access to this user
578 * @param delete whether or not to allow deletion access to this user
579 * @param insert whether or not to allow insertion access to this user
580 * @param lock whether or not to allow lock access to this user
581 * @param admin whether or not to allow admin access to this user
582 * @exception AFSException If an error occurs in the native code
583 public void setACL( String directory, boolean read, boolean write, boolean lookup, boolean delete, boolean insert, boolean lock, boolean admin )
586 Cell.setACL( directory, name, read, write, lookup, delete, insert, lock, admin );
590 ////////////////////// accessors: ///////////////
593 * Returns the name of this group.
595 * @return the name of this group
597 public String
getName()
603 * Returns the numeric AFS id of this group.
605 * @return the AFS id of this group
606 * @exception AFSException If an error occurs in the native code
608 public int getUID() throws AFSException
617 * Returns the Cell this group belongs to.
619 * @return the Cell this group belongs to
621 public Cell
getCell()
627 * Returns an array of the <code>User</code> object members of this group.
629 * @return an array of the members of this group
630 * @exception AFSException If an error occurs in the native code
632 public User
[] getMembers() throws AFSException
634 if( members
== null ) {
637 return (User
[]) members
.toArray( new User
[members
.size()] );
641 * Returns an array of the member names of this group.
643 * @return an array of the member names of this group
644 * @exception AFSException If an error occurs in the native code
646 public String
[] getMemberNames() throws AFSException
648 if( memberNames
== null ) {
649 refreshMemberNames();
651 return (String
[]) memberNames
.toArray( new String
[memberNames
.size()] );
655 * Returns an array of the <code>Group</code> objects this group owns.
657 * @return an array of the <code>Groups</code> this group owns
658 * @exception AFSException If an error occurs in the native code
660 public Group
[] getGroupsOwned() throws AFSException
662 if( groupsOwned
== null ) {
663 refreshGroupsOwned();
665 return (Group
[]) groupsOwned
.toArray( new Group
[groupsOwned
.size()] );
669 * Returns an array of the group names this group owns.
670 * Contains <code>String</code> objects.
672 * @return an array of the group names this group owns
673 * @exception AFSException If an error occurs in the native code
675 public String
[] getGroupsOwnedNames() throws AFSException
677 if( groupsOwnedNames
== null ) {
678 refreshGroupsOwnedNames();
681 groupsOwnedNames
.toArray(new String
[groupsOwnedNames
.size()] );
685 * Returns the number of members of this group.
687 * @return the membership count
688 * @exception AFSException If an error occurs in the native code
690 public int getMembershipCount() throws AFSException
695 return membershipCount
;
699 * PTS: Returns the owner of this group in the form of a {@link PTSEntry}.
701 * <P>The returning object could be either a {@link User} or {@link Group};
702 * to determine what type of object the {@link PTSEntry} represents,
703 * call the {@link PTSEntry#getType()} method.
705 * @return the owner of this group
706 * @exception AFSException If an error occurs in the native code
708 * @see PTSEntry#getType()
711 public PTSEntry
getOwner() throws AFSException
713 if (!cachedInfo
) refreshInfo();
714 if (owner
== null) return null;
716 return new User(owner
, cell
);
718 return new Group(owner
, cell
);
723 * PTS: Returns the creator of this group in the form of a {@link PTSEntry}.
725 * <P>The returning object could be either a {@link User} or {@link Group};
726 * to determine what type of object the {@link PTSEntry} represents,
727 * call the {@link PTSEntry#getType()} method.
729 * @return the creator of this group
730 * @exception AFSException If an error occurs in the native code
732 * @see PTSEntry#getType()
735 public PTSEntry
getCreator() throws AFSException
737 if (!cachedInfo
) refreshInfo();
738 if (creator
== null) return null;
739 if (creatorUID
> 0) {
740 return new User(creator
, cell
);
742 return new Group(creator
, cell
);
747 * Returns the type of {@link PTSEntry} this object represents.
749 * <P>This method will always return {@link PTSEntry#PTS_GROUP}.
751 * @return the type of PTSEntry this object represents
752 (will always return {@link PTSEntry#PTS_GROUP})
754 * @see PTSEntry#getType()
756 public short getType()
758 return PTSEntry
.PTS_GROUP
;
762 * Returns who can list the status (pts examine) of this group.
765 * <li><code>{@link #GROUP_OWNER_ACCESS}</code>
766 * -- only the owner has permission</li>
767 * <li><code>{@link #GROUP_GROUP_ACCESS}</code>
768 * -- only members of the group have permission</li>
769 * <li><code>{@link #GROUP_ANYUSER_ACCESS}</code>
770 * -- any user has permission</li>
773 * @return the status listing permission
774 * @exception AFSException If an error occurs in the native code
776 public int getListStatus() throws AFSException
778 if( !cachedInfo
) refreshInfo();
783 * Returns who can list the groups owned (pts listowned) by this group.
786 * <li><code>{@link #GROUP_OWNER_ACCESS}</code>
787 * -- only the owner has permission</li>
788 * <li><code>{@link #GROUP_GROUP_ACCESS}</code>
789 * -- only members of the group have permission</li>
790 * <li><code>{@link #GROUP_ANYUSER_ACCESS}</code>
791 * -- any user has permission</li>
794 * @return the groups owned listing permission
795 * @exception AFSException If an error occurs in the native code
797 public int getListGroupsOwned() throws AFSException
799 if( !cachedInfo
) refreshInfo();
800 return listGroupsOwned
;
804 * Returns who can list the users (pts membership) that belong to this group.
807 * <li><code>{@link #GROUP_OWNER_ACCESS}</code>
808 * -- only the owner has permission</li>
809 * <li><code>{@link #GROUP_GROUP_ACCESS}</code>
810 * -- only members of the group have permission</li>
811 * <li><code>{@link #GROUP_ANYUSER_ACCESS}</code>
812 * -- any user has permission</li>
815 * @return the membership listing permission
816 * @exception AFSException If an error occurs in the native code
818 public int getListMembership() throws AFSException
820 if( !cachedInfo
) refreshInfo();
821 return listMembership
;
825 * Returns who can add members (pts adduser) to this group.
828 * <li><code>{@link #GROUP_OWNER_ACCESS}</code>
829 * -- only the owner has permission</li>
830 * <li><code>{@link #GROUP_GROUP_ACCESS}</code>
831 * -- only members of the group have permission</li>
832 * <li><code>{@link #GROUP_ANYUSER_ACCESS}</code>
833 * -- any user has permission</li>
836 * @return the member adding permission
837 * @exception AFSException If an error occurs in the native code
839 public int getListAdd() throws AFSException
841 if( !cachedInfo
) refreshInfo();
846 * Returns who can delete members (pts removemember) from this group.
849 * <li><code>{@link #GROUP_OWNER_ACCESS}</code>
850 * -- only the owner has permission</li>
851 * <li><code>{@link #GROUP_GROUP_ACCESS}</code>
852 * -- only members of the group have permission</li>
853 * <li><code>{@link #GROUP_ANYUSER_ACCESS}</code>
854 * -- any user has permission</li>
857 * @return the member deleting permission
858 * @exception AFSException If an error occurs in the native code
860 public int getListDelete() throws AFSException
862 if( !cachedInfo
) refreshInfo();
866 /////////////////// mutators: //////////////////////
869 * Sets who can list the status (pts examine) of this group.
872 * <li><code>{@link #GROUP_OWNER_ACCESS}</code>
873 * -- only the owner has permission</li>
874 * <li><code>{@link #GROUP_GROUP_ACCESS}</code>
875 * -- only members of the group have permission</li>
876 * <li><code>{@link #GROUP_ANYUSER_ACCESS}</code>
877 * -- any user has permission</li>
880 * @param value the value of the new list membership permission
881 * @exception AFSException if an error occurs in the native code
882 * @exception IllegalArgumentException if an invalud argument is provided
884 public void setListStatus( int value
) throws AFSException
886 if( (value
!= Group
.GROUP_OWNER_ACCESS
) &&
887 (value
!= Group
.GROUP_GROUP_ACCESS
) &&
888 (value
!= Group
.GROUP_ANYUSER_ACCESS
) ) {
889 throw new IllegalArgumentException( "Cannot set listStatus to "
897 * Sets who can list the groups owned (pts listowned) by this group.
900 * <li><code>{@link #GROUP_OWNER_ACCESS}</code>
901 * -- only the owner has permission</li>
902 * <li><code>{@link #GROUP_GROUP_ACCESS}</code>
903 * -- only members of the group have permission</li>
904 * <li><code>{@link #GROUP_ANYUSER_ACCESS}</code>
905 * -- any user has permission</li>
908 * @param value the value of the new list membership permission
909 * @exception AFSException if an error occurs in the native code
910 * @exception IllegalArgumentException if an invalud argument is provided
912 public void setListGroupsOwned( int value
) throws AFSException
914 if( (value
!= Group
.GROUP_OWNER_ACCESS
) &&
915 (value
!= Group
.GROUP_GROUP_ACCESS
) &&
916 (value
!= Group
.GROUP_ANYUSER_ACCESS
) ) {
917 throw new IllegalArgumentException( "Cannot set listGroupsOwned to "
920 listGroupsOwned
= value
;
925 * Sets who can list the users (pts membership) that belong to this group.
928 * <li><code>{@link #GROUP_OWNER_ACCESS}</code>
929 * -- only the owner has permission</li>
930 * <li><code>{@link #GROUP_GROUP_ACCESS}</code>
931 * -- only members of the group have permission</li>
932 * <li><code>{@link #GROUP_ANYUSER_ACCESS}</code>
933 * -- any user has permission</li>
936 * @param value the value of the new list membership permission
937 * @exception AFSException if an error occurs in the native code
938 * @exception IllegalArgumentException if an invalud argument is provided
940 public void setListMembership( int value
) throws AFSException
942 if( (value
!= Group
.GROUP_OWNER_ACCESS
) &&
943 (value
!= Group
.GROUP_GROUP_ACCESS
) &&
944 (value
!= Group
.GROUP_ANYUSER_ACCESS
) ) {
945 throw new IllegalArgumentException( "Cannot set listMembership to "
948 listMembership
= value
;
953 * Sets who can add members (pts adduser) to this group.
956 * <li><code>{@link #GROUP_OWNER_ACCESS}</code>
957 * -- only the owner has permission</li>
958 * <li><code>{@link #GROUP_GROUP_ACCESS}</code>
959 * -- only members of the group have permission</li>
960 * <li><code>{@link #GROUP_ANYUSER_ACCESS}</code>
961 * -- any user has permission</li>
964 * @param value the value of the new list membership permission
965 * @exception AFSException if an invalid value is provided
967 public void setListAdd( int value
) throws AFSException
969 if( (value
!= Group
.GROUP_OWNER_ACCESS
) &&
970 (value
!= Group
.GROUP_GROUP_ACCESS
) &&
971 (value
!= Group
.GROUP_ANYUSER_ACCESS
) ) {
972 throw new IllegalArgumentException( "Cannot set listAdd to " + value
);
979 * Sets who can delete members (pts removemember) from this group.
982 * <li><code>{@link #GROUP_OWNER_ACCESS}</code>
983 * -- only the owner has permission</li>
984 * <li><code>{@link #GROUP_GROUP_ACCESS}</code>
985 * -- only members of the group have permission</li>
986 * <li><code>{@link #GROUP_ANYUSER_ACCESS}</code>
987 * -- any user has permission</li>
990 * @param value the value of the new list membership permission
991 * @exception AFSException if an invalid value is provided
993 public void setListDelete( int value
) throws AFSException
995 if( (value
!= Group
.GROUP_OWNER_ACCESS
) &&
996 (value
!= Group
.GROUP_GROUP_ACCESS
) &&
997 (value
!= Group
.GROUP_ANYUSER_ACCESS
) ) {
998 throw new IllegalArgumentException( "Cannot set listDelete to "
1005 /////////////// information methods ////////////////////
1008 * Returns a <code>String</code> representation of this <code>Group</code>.
1009 * Contains the information fields and members.
1011 * @return a <code>String</code> representation of the <code>Group</code>
1013 public String
getInfo()
1017 r
= "Group: " + getName() + ", uid: " + getUID() + "\n";
1018 r
+= "\towner: " + getOwner().getName() + ", uid: " + getOwner().getUID() + "\n";
1019 r
+= "\tcreator: " + getCreator().getName() + ", uid: "
1020 + getCreator().getUID() + "\n";
1021 r
+= "\tMembership count: " + getMembershipCount() + "\n";
1022 r
+= "\tList status: " + getListStatus() + "\n";
1023 r
+= "\tList groups owned: " + getListGroupsOwned() + "\n";
1024 r
+= "\tList membership: " + getListMembership() + "\n";
1025 r
+= "\tAdd members: " + getListAdd() + "\n";
1026 r
+= "\tDelete members: " + getListDelete() + "\n";
1028 r
+= "\tGroup members: \n";
1029 String names
[] = getMemberNames();
1030 for( int i
= 0; i
< names
.length
; i
++ ) {
1031 r
+= "\t\t" + names
[i
] + "\n";
1034 r
+= "\tOwns groups: \n";
1035 names
= getGroupsOwnedNames();
1036 for( int i
= 0; i
< names
.length
; i
++ ) {
1037 r
+= "\t\t" + names
[i
] + "\n";
1040 } catch ( AFSException e
) {
1041 return e
.toString();
1045 /////////////// custom override methods ////////////////////
1048 * Compares two Group objects respective to their names and does not
1049 * factor any other attribute. Alphabetic case is significant in
1052 * @param group The Group object to be compared to this Group instance
1054 * @return Zero if the argument is equal to this Group's name, a
1055 * value less than zero if this Group's name is
1056 * lexicographically less than the argument, or a value greater
1057 * than zero if this Group's name is lexicographically
1058 * greater than the argument
1060 public int compareTo(Group group
)
1062 return this.getName().compareTo(group
.getName());
1066 * Comparable interface method.
1068 * @see #compareTo(Group)
1070 public int compareTo(Object obj
)
1072 return compareTo((Group
)obj
);
1076 * Tests whether two <code>Group</code> objects are equal, based on their
1079 * @param otherGroup the Group to test
1080 * @return whether the specifed Group is the same as this Group
1082 public boolean equals( Group otherGroup
)
1084 return name
.equals( otherGroup
.getName() );
1088 * Returns the name of this <CODE>Group</CODE>
1090 * @return the name of this <CODE>Group</CODE>
1092 public String
toString()
1097 /////////////// native methods ////////////////////
1100 * Creates the PTS entry for a new group. Pass in 0 for the uid if PTS is to
1101 * automatically assign the group id.
1103 * @param cellHandle the handle of the cell to which the group belongs
1104 * @see Cell#getCellHandle
1105 * @param groupName the name of the group to create
1106 * @param ownerName the owner of this group
1107 * @param gid the group id to assign to the group (0 to have one
1108 * automatically assigned)
1109 * @exception AFSException If an error occurs in the native code
1111 protected static native void create( long cellHandle
, String groupName
,
1112 String ownerName
, int gid
)
1113 throws AFSException
;
1116 * Deletes the PTS entry for a group. Deletes this group from the
1117 * membership list of the users that belonged to it, but does not delete
1118 * the groups owned by this group.
1120 * @param cellHandle the handle of the cell to which the group belongs
1121 * @see Cell#getCellHandle
1122 * @param groupName the name of the group to delete
1123 * @exception AFSException If an error occurs in the native code
1125 protected static native void delete( long cellHandle
, String groupName
)
1126 throws AFSException
;
1129 * Fills in the information fields of the provided <code>Group</code>.
1130 * Fills in values based on the current PTS information of the group.
1132 * @param cellHandle the handle of the cell to which the group belongs
1133 * @see Cell#getCellHandle
1134 * @param name the name of the group for which to get the information
1135 * @param group the <code>Group</code> object in which to fill in the
1138 * @exception AFSException If an error occurs in the native code
1140 protected static native void getGroupInfo( long cellHandle
, String name
,
1142 throws AFSException
;
1145 * Sets the information values of this AFS group to be the parameter values.
1147 * @param cellHandle the handle of the cell to which the user belongs
1148 * @see Cell#getCellHandle
1149 * @param name the name of the user for which to set the information
1150 * @param theGroup the group object containing the desired information
1151 * @exception AFSException If an error occurs in the native code
1153 protected static native void setGroupInfo( long cellHandle
, String name
,
1155 throws AFSException
;
1158 * Begin the process of getting the users that belong to the group. Returns
1159 * an iteration ID to be used by subsequent calls to
1160 * <code>getGroupMembersNext</code> and <code>getGroupMembersDone</code>.
1162 * @param cellHandle the handle of the cell to which the group belongs
1163 * @see Cell#getCellHandle
1164 * @param name the name of the group for which to get the members
1165 * @return an iteration ID
1166 * @exception AFSException If an error occurs in the native code
1168 protected static native long getGroupMembersBegin( long cellHandle
,
1170 throws AFSException
;
1173 * Returns the next members that belongs to the group. Returns
1174 * <code>null</code> if there are no more members.
1176 * @param iterationId the iteration ID of this iteration
1177 * @see getGroupMembersBegin
1178 * @return the name of the next member
1179 * @exception AFSException If an error occurs in the native code
1181 protected static native String
getGroupMembersNextString( long iterationId
)
1182 throws AFSException
;
1185 * Fills the next user object belonging to that group. Returns 0 if there
1186 * are no more users, != 0 otherwise.
1188 * @param cellHandle the handle of the cell to which the users belong
1189 * @see Cell#getCellHandle
1190 * @param iterationId the iteration ID of this iteration
1191 * @see getGroupMembersBegin
1192 * @param theUser a User object to be populated with the values of the
1194 * @return 0 if there are no more users, != 0 otherwise
1195 * @exception AFSException If an error occurs in the native code
1197 protected static native int getGroupMembersNext( long cellHandle
,
1200 throws AFSException
;
1203 * Signals that the iteration is complete and will not be accessed anymore.
1205 * @param iterationId the iteration ID of this iteration
1206 * @see getGroupMembersBegin
1207 * @exception AFSException If an error occurs in the native code
1209 protected static native void getGroupMembersDone( long iterationId
)
1210 throws AFSException
;
1213 * Adds a user to the specified group.
1215 * @param cellHandle the handle of the cell to which the group belongs
1216 * @see Cell#getCellHandle
1217 * @param groupName the name of the group to which to add a member
1218 * @param userName the name of the user to add
1219 * @exception AFSException If an error occurs in the native code
1221 protected static native void addMember( long cellHandle
, String groupName
,
1223 throws AFSException
;
1226 * Removes a user from the specified group.
1228 * @param cellHandle the handle of the cell to which the group belongs
1229 * @see Cell#getCellHandle
1230 * @param groupName the name of the group from which to remove a
1232 * @param userName the name of the user to remove
1233 * @exception AFSException If an error occurs in the native code
1235 protected static native void removeMember( long cellHandle
, String groupName
,
1237 throws AFSException
;
1240 * Change the owner of the specified group.
1242 * @param cellHandle the handle of the cell to which the group belongs
1243 * @see Cell#getCellHandle
1244 * @param groupName the name of the group of which to change the
1246 * @param ownerName the name of the new owner
1247 * @exception AFSException If an error occurs in the native code
1249 protected static native void changeOwner( long cellHandle
, String groupName
,
1251 throws AFSException
;
1254 * Change the name of the specified group.
1256 * @param cellHandle the handle of the cell to which the group belongs
1257 * @see Cell#getCellHandle
1258 * @param oldGroupName the old name of the group
1259 * @param newGroupName the new name for the group
1260 * @exception AFSException If an error occurs in the native code
1262 protected static native void rename( long cellHandle
, String oldGroupName
,
1263 String newGroupName
)
1264 throws AFSException
;
1267 * Reclaims all memory being saved by the group portion of the native
1269 * This method should be called when no more <code>Groups</code> are expected
1272 protected static native void reclaimGroupMemory();