InfoCenter Home > 5.2.2.2.8: The getGroupsForUser and getUsersForGroup methodsThe getGroupsForUser returns a list of the names of the groups to which the named user belongs, and the getUsersForGroup method returns a list of the user names in a group. These methods must return lists of names, not UIDs or GIDs. WebSphere Application Server expects the methods to throw the EntryNotFoundException exception if the specified user or group name is not found in the registry and to throw the CustomRegistryException exception for any other conditions. Figure 12 shows the implementation of the getGroupsForUser method for the example registry. Unlike the other user methods, which return information about users from the user-information file, this method iterates over the group-information file, collecting the name of every group that lists the named user as a member. The group-information file stores each member list as a set of names, and the user-information file stores each group list as a list of GIDs. By using the group-information file, the method can create the list of user names directly. If the method had been implemented by iterating over the user-information file, the method would have to call the getGroupSecurityName method on each GID to construct the list of group names. In the event of an exception, the method calls the isValidUser method, described in Figure 7, to verify that the user name appears in the registry. If it does not, the method throws the EntryNotFoundException exception. If the user name is valid, the CustomRegistryException exception is thrown. The getGroupSecurityName method does similar work on the group-information file. public List getGroupsForUser(String userName) throws CustomRegistryException, EntryNotFoundException { String s; List grpsForUser = new ArrayList(); BufferedReader in = null; try { in = fileOpen(GROUPFILENAME); while ((s=in.readLine())!=null) { if (!s.startsWith("#")) { StringTokenizer st = new StringTokenizer(s, ":"); for (int i=0; i<2; i++) st.nextToken(); String subs = st.nextToken(); StringTokenizer st1 = new StringTokenizer(subs, ","); while (st1.hasMoreTokens()) { if((st1.nextToken()).equals(userName)) { int index = s.indexOf(":"); grpsForUser.add(s.substring(0,index)); } } } } } catch (Exception ex) { if (!isValidUser(userName)) { throw new EntryNotFoundException(userName); } throw new CustomRegistryException(ex.getMessage()); } finally { fileClose(in); } return grpsForUser; } public List getUsersForGroup(String userName) throws CustomRegistryException, EntryNotFoundException { String s; List usrsForGroup = new ArrayList(); BufferedReader in = null; try { in = fileOpen(GROUPFILENAME); ... } catch (Exception ex) { ... } finally { ... } return usrsForGroup; } |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|