KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > console > util > SERealmUserHelper


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

17
18 package org.apache.geronimo.console.util;
19
20 import java.util.Hashtable JavaDoc;
21
22 import org.apache.geronimo.kernel.Kernel;
23 import org.apache.geronimo.kernel.KernelRegistry;
24
25 public class SERealmUserHelper extends RealmHelper {
26
27     private static final String JavaDoc GET_USERS_FUNCTION = "getUsers";
28
29     private static final String JavaDoc ADD_USER_FUNCTION = "addUserPrincipal";
30
31     private static final String JavaDoc USER_EXISTS_FUNCTION = "userExists";
32
33     private static final String JavaDoc UPDATE_USER_FUNCTION = "updateUserPrincipal";
34
35     private static final String JavaDoc DELETE_USER_FUNCTION = "removeUserPrincipal";
36
37     private static final String JavaDoc GET_PASSWORD_FUNCTION = "getPassword";
38
39     private static final String JavaDoc[] STRING = { "java.lang.String" };
40
41     private static final String JavaDoc[] HASHTABLE = { "java.util.Hashtable" };
42
43     private static final Kernel kernel = KernelRegistry.getSingleKernel();
44
45     public static String JavaDoc[] getUsers() throws Exception JavaDoc {
46         return (String JavaDoc[]) invoke(ObjectNameConstants.SE_REALM_MBEAN_NAME, GET_USERS_FUNCTION);
47     }
48
49     private static void refresh() {
50         try {
51
52             kernel.stopGBean(ObjectNameConstants.SE_REALM_MBEAN_NAME);
53             kernel.startGBean(ObjectNameConstants.SE_REALM_MBEAN_NAME);
54 // kernel.stopGBean(ObjectNameConstants.SE_REALM_IMMUTABLE_MBEAN_NAME);
55
// kernel.startGBean(ObjectNameConstants.SE_REALM_IMMUTABLE_MBEAN_NAME);
56

57         } catch (Exception JavaDoc e) {
58         }
59     }
60
61     public static String JavaDoc getPassword(String JavaDoc username) throws Exception JavaDoc {
62         Object JavaDoc ret;
63         String JavaDoc[] arg = {username};
64         ret = invoke(ObjectNameConstants.SE_REALM_MBEAN_NAME, GET_PASSWORD_FUNCTION, arg, STRING);
65         return (ret != null) ? ret.toString() : "";
66     }
67
68     public static boolean userExists(String JavaDoc username) throws Exception JavaDoc {
69         Boolean JavaDoc ret;
70         String JavaDoc[] arg = {username};
71         ret = (Boolean JavaDoc) invoke(ObjectNameConstants.SE_REALM_MBEAN_NAME, USER_EXISTS_FUNCTION, arg, STRING);
72         return ret.booleanValue();
73     }
74
75     public static void addUser(String JavaDoc username, String JavaDoc password)
76             throws Exception JavaDoc {
77         Hashtable JavaDoc props = new Hashtable JavaDoc();
78         props.put("UserName", username);
79         props.put("Password", password);
80         Object JavaDoc[] args = {props};
81         invoke(ObjectNameConstants.SE_REALM_MBEAN_NAME, ADD_USER_FUNCTION, args, HASHTABLE);
82         refresh();
83     }
84
85     public static void updateUser(String JavaDoc username, String JavaDoc password)
86             throws Exception JavaDoc {
87         Hashtable JavaDoc props = new Hashtable JavaDoc();
88         props.put("UserName", username);
89         props.put("Password", password);
90         Object JavaDoc[] args = {props};
91         invoke(ObjectNameConstants.SE_REALM_MBEAN_NAME, UPDATE_USER_FUNCTION, args, HASHTABLE);
92         refresh();
93     }
94
95     public static void deleteUser(String JavaDoc username) throws Exception JavaDoc {
96         String JavaDoc[] args = {username};
97         invoke(ObjectNameConstants.SE_REALM_MBEAN_NAME, DELETE_USER_FUNCTION, args, STRING);
98         refresh();
99     }
100
101
102 }
Popular Tags