KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webapp > admin > users > UserUtils


1 /*
2  * Copyright 2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17
18 package org.apache.webapp.admin.users;
19
20
21 import java.util.Arrays JavaDoc;
22 import javax.management.MBeanServer JavaDoc;
23 import javax.management.ObjectName JavaDoc;
24
25
26 /**
27  * <p>Shared utility methods for the user database administration module.</p>
28  *
29  * @author Craig R. McClanahan
30  * @version $Revision: 1.2 $ $Date: 2004/02/27 14:59:05 $
31  * @since 4.1
32  */

33
34 public class UserUtils {
35
36
37     // --------------------------------------------------------- Public Methods
38

39
40     /**
41      * Construct and return a GroupsForm identifying all currently defined
42      * groups in the specified user database.
43      *
44      * @param mserver MBeanServer to be consulted
45      * @param databaseName MBean Name of the user database to be consulted
46      *
47      * @exception Exception if an error occurs
48      */

49     public static GroupsForm getGroupsForm(MBeanServer JavaDoc mserver,
50                                            String JavaDoc databaseName)
51         throws Exception JavaDoc {
52
53         ObjectName JavaDoc dname = new ObjectName JavaDoc(databaseName);
54         String JavaDoc results[] =
55             (String JavaDoc[]) mserver.getAttribute(dname, "groups");
56         if (results == null) {
57             results = new String JavaDoc[0];
58         }
59         Arrays.sort(results);
60
61         GroupsForm groupsForm = new GroupsForm();
62         groupsForm.setDatabaseName(databaseName);
63         groupsForm.setGroups(results);
64         return (groupsForm);
65
66     }
67
68
69     /**
70      * Construct and return a RolesForm identifying all currently defined
71      * roles in the specified user database.
72      *
73      * @param mserver MBeanServer to be consulted
74      * @param databaseName MBean Name of the user database to be consulted
75      *
76      * @exception Exception if an error occurs
77      */

78     public static RolesForm getRolesForm(MBeanServer JavaDoc mserver,
79                                            String JavaDoc databaseName)
80         throws Exception JavaDoc {
81
82         ObjectName JavaDoc dname = new ObjectName JavaDoc(databaseName);
83         String JavaDoc results[] =
84             (String JavaDoc[]) mserver.getAttribute(dname, "roles");
85         if (results == null) {
86             results = new String JavaDoc[0];
87         }
88         Arrays.sort(results);
89
90         RolesForm rolesForm = new RolesForm();
91         rolesForm.setDatabaseName(databaseName);
92         rolesForm.setRoles(results);
93         return (rolesForm);
94
95     }
96
97
98     /**
99      * Construct and return a UsersForm identifying all currently defined
100      * users in the specified user database.
101      *
102      * @param mserver MBeanServer to be consulted
103      * @param databaseName MBean Name of the user database to be consulted
104      *
105      * @exception Exception if an error occurs
106      */

107     public static UsersForm getUsersForm(MBeanServer JavaDoc mserver,
108                                            String JavaDoc databaseName)
109         throws Exception JavaDoc {
110
111         ObjectName JavaDoc dname = new ObjectName JavaDoc(databaseName);
112         String JavaDoc results[] =
113             (String JavaDoc[]) mserver.getAttribute(dname, "users");
114         if (results == null) {
115             results = new String JavaDoc[0];
116         }
117         Arrays.sort(results);
118
119         UsersForm usersForm = new UsersForm();
120         usersForm.setDatabaseName(databaseName);
121         usersForm.setUsers(results);
122         return (usersForm);
123
124     }
125
126
127 }
128
Popular Tags