KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > harmonise > UserConfigClient


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.harmonise;
20
21 import java.net.*;
22 import java.rmi.RemoteException JavaDoc;
23
24 import org.apache.axis.client.Call;
25 import org.apache.axis.client.Service;
26
27 import javax.xml.namespace.QName JavaDoc;
28 import javax.xml.rpc.ServiceException JavaDoc;
29
30 /**
31  * This class provides a client interface to the Harmonise user config webservice
32  *
33  * @author Michael Bell
34  * @version $Revision: 1.2 $
35  *
36  */

37 public class UserConfigClient {
38
39     public static final int CODE_SUCCESS = 200;
40     public static final int CODE_AUTHENTICATION_FAIL = 402;
41     public static final int CODE_INVALID_LENGTH = 403;
42     public static final int CODE_NO_ALPHA_CHAR = 404;
43     public static final int CODE_NO_NUM_CHAR = 405;
44     public static final int CODE_NO_CASE_MIX = 406;
45     public static final int CODE_INVALID_USER_STATE = 407;
46     public static final int CODE_PWD_REPEAT = 408;
47     public static final String JavaDoc SIMULACRA_WEBSERVICE_NAMESPACE_URI =
48         "http://www.openharmonise.org/";
49
50     /**
51      *
52      */

53     public UserConfigClient() {
54         super();
55     }
56
57     /**
58      * Makes SOAP request to change the password of the user with the user name
59      * <code>sChangeUserName</code> using the user with user name <code>sCurrUserName</code>
60      *
61      * @param endpoint
62      * @param sCurrUserName
63      * @param sCurrUserPwd
64      * @param sChangeUserName
65      * @param sChangeOldPwd
66      * @param sChangeNewPwd
67      * @return
68      * @throws java.rmi.RemoteException
69      * @throws ServiceException
70      */

71     public static int setPassword(
72         URL endpoint,
73         String JavaDoc sCurrUserName,
74         String JavaDoc sCurrUserPwd,
75         String JavaDoc sChangeUserName,
76         String JavaDoc sChangeNewPwd)
77         throws java.rmi.RemoteException JavaDoc, ServiceException JavaDoc {
78
79         Service service = new Service();
80         Call call = (Call) service.createCall();
81
82         call.setTargetEndpointAddress(endpoint);
83         call.setOperationName(
84             new QName JavaDoc(SIMULACRA_WEBSERVICE_NAMESPACE_URI, "setPassword"));
85
86         call.addParameter(
87             "sCurrUserName",
88             org.apache.axis.Constants.XSD_STRING,
89             javax.xml.rpc.ParameterMode.IN);
90         call.addParameter(
91             "sCurrUserPwd",
92             org.apache.axis.Constants.XSD_STRING,
93             javax.xml.rpc.ParameterMode.IN);
94
95         call.addParameter(
96             "sChangeUserName",
97             org.apache.axis.Constants.XSD_STRING,
98             javax.xml.rpc.ParameterMode.IN);
99
100         call.addParameter(
101             "sChangeNewPwd",
102             org.apache.axis.Constants.XSD_STRING,
103             javax.xml.rpc.ParameterMode.IN);
104
105         call.setReturnType(org.apache.axis.Constants.XSD_INTEGER);
106         call.setReturnClass(Integer JavaDoc.class);
107
108         Integer JavaDoc ret =
109             (Integer JavaDoc) call.invoke(
110                 new Object JavaDoc[] {
111                     sCurrUserName,
112                     sCurrUserPwd,
113                     sChangeUserName,
114                     sChangeNewPwd });
115
116         return ret.intValue();
117
118     }
119
120     /**
121      * Makes SOAP request to check whether the given password has expired for the user
122      * with user name <code>sUserName</code>
123      *
124      * @param endpoint
125      * @param sUserName
126      * @param sPwd
127      * @return
128      * @throws ServiceException
129      * @throws RemoteException
130      */

131     static public boolean hasPasswordExpired(
132         URL endpoint,
133         String JavaDoc sUserName,
134         String JavaDoc sPwd)
135         throws ServiceException JavaDoc, RemoteException JavaDoc {
136         Service service = new Service();
137         Call call = (Call) service.createCall();
138
139         call.setTargetEndpointAddress(endpoint);
140         call.setOperationName(
141             new QName JavaDoc(
142                 SIMULACRA_WEBSERVICE_NAMESPACE_URI,
143                 "hasPasswordExpired"));
144
145         call.addParameter(
146             "sUserName",
147             org.apache.axis.Constants.XSD_STRING,
148             javax.xml.rpc.ParameterMode.IN);
149         call.addParameter(
150             "sPwd",
151             org.apache.axis.Constants.XSD_STRING,
152             javax.xml.rpc.ParameterMode.IN);
153
154         call.setReturnType(org.apache.axis.Constants.XSD_BOOLEAN);
155         call.setReturnClass(Boolean JavaDoc.class);
156
157         Boolean JavaDoc ret = (Boolean JavaDoc) call.invoke(new Object JavaDoc[] { sUserName, sPwd });
158
159         return ret.booleanValue();
160     }
161
162     /**
163      * Makes SOAP request to check with the user with the given user name and password
164      * is a super user
165      *
166      * @param endpoint
167      * @param sUserName
168      * @param sPwd
169      * @return
170      * @throws ServiceException
171      * @throws RemoteException
172      */

173     static public boolean isSuperUser(
174         URL endpoint,
175         String JavaDoc sUserName,
176         String JavaDoc sPwd)
177         throws ServiceException JavaDoc, RemoteException JavaDoc {
178         Service service = new Service();
179         Call call = (Call) service.createCall();
180
181         call.setTargetEndpointAddress(endpoint);
182         call.setOperationName(
183             new QName JavaDoc(SIMULACRA_WEBSERVICE_NAMESPACE_URI, "isSuperUser"));
184
185         call.addParameter(
186             "sUserName",
187             org.apache.axis.Constants.XSD_STRING,
188             javax.xml.rpc.ParameterMode.IN);
189         call.addParameter(
190             "sPwd",
191             org.apache.axis.Constants.XSD_STRING,
192             javax.xml.rpc.ParameterMode.IN);
193
194         call.setReturnType(org.apache.axis.Constants.XSD_BOOLEAN);
195         call.setReturnClass(Boolean JavaDoc.class);
196
197         Boolean JavaDoc ret = (Boolean JavaDoc) call.invoke(new Object JavaDoc[] { sUserName, sPwd });
198
199         return ret.booleanValue();
200     }
201     
202     /**
203      * Makes SOAP request to check with the user with the given user name and password
204      * is a super user
205      *
206      * @param endpoint
207      * @param sUserName
208      * @param sPwd
209      * @return
210      * @throws ServiceException
211      * @throws RemoteException
212      */

213     static public boolean isSuperUser(
214         URL endpoint,
215         String JavaDoc sUserName,
216         String JavaDoc sPwd,
217         String JavaDoc sCheckUser)
218         throws ServiceException JavaDoc, RemoteException JavaDoc {
219         Service service = new Service();
220         Call call = (Call) service.createCall();
221
222         call.setTargetEndpointAddress(endpoint);
223         call.setOperationName(
224             new QName JavaDoc(SIMULACRA_WEBSERVICE_NAMESPACE_URI, "isSuperUser"));
225
226         call.addParameter(
227             "sUserName",
228             org.apache.axis.Constants.XSD_STRING,
229             javax.xml.rpc.ParameterMode.IN);
230         call.addParameter(
231             "sPwd",
232             org.apache.axis.Constants.XSD_STRING,
233             javax.xml.rpc.ParameterMode.IN);
234         call.addParameter(
235             "sCheckUser",
236             org.apache.axis.Constants.XSD_STRING,
237             javax.xml.rpc.ParameterMode.IN);
238
239         call.setReturnType(org.apache.axis.Constants.XSD_BOOLEAN);
240         call.setReturnClass(Boolean JavaDoc.class);
241
242         Boolean JavaDoc ret = (Boolean JavaDoc) call.invoke(new Object JavaDoc[] { sUserName, sPwd, sCheckUser });
243
244         return ret.booleanValue();
245     }
246     
247     /**
248      * Returns <code>true</code> if the user with the given user name is locked
249      * out of the system
250      *
251      * @param endpoint
252      * @param sUserName
253      * @return
254      * @throws ServiceException
255      * @throws RemoteException
256      */

257     static public boolean isUserLockedOut(
258         URL endpoint,
259         String JavaDoc sUserName)
260         throws ServiceException JavaDoc, RemoteException JavaDoc {
261         Service service = new Service();
262         Call call = (Call) service.createCall();
263
264         call.setTargetEndpointAddress(endpoint);
265         call.setOperationName(
266             new QName JavaDoc(SIMULACRA_WEBSERVICE_NAMESPACE_URI, "isUserLockedOut"));
267
268         call.addParameter(
269             "sUserName",
270             org.apache.axis.Constants.XSD_STRING,
271             javax.xml.rpc.ParameterMode.IN);
272         
273
274         call.setReturnType(org.apache.axis.Constants.XSD_BOOLEAN);
275         call.setReturnClass(Boolean JavaDoc.class);
276
277         Boolean JavaDoc ret = (Boolean JavaDoc) call.invoke(new Object JavaDoc[] { sUserName});
278
279         return ret.booleanValue();
280     }
281     
282
283
284     /**
285      * Makes SOAP request to set whether the user is a super user.
286      *
287      * @param endpoint
288      * @param sCurrUserName the user name of the user making the change
289      * @param sPwd the password of the user making the change
290      * @param sNewSuperUser the user name of the user to be changed
291      * @param bIsSuper <code>true</code> if the user to be changed is to be a super user, otherwise <code>false</code>
292      * @throws java.rmi.RemoteException if the current user is not allowed to make the change,
293      * there is a pending version of the user to be changed or a general
294      * error occurs
295      * @throws ServiceException
296      */

297     public static void setIsSuperUser(
298         URL endpoint,
299         String JavaDoc sCurrUserName,
300         String JavaDoc sPwd,
301         String JavaDoc sChangeUser,
302         boolean bIsSuper)
303         throws java.rmi.RemoteException JavaDoc, ServiceException JavaDoc {
304
305         Service service = new Service();
306         Call call = (Call) service.createCall();
307
308         call.setTargetEndpointAddress(endpoint);
309         call.setOperationName(
310             new QName JavaDoc(SIMULACRA_WEBSERVICE_NAMESPACE_URI, "setIsSuperUser"));
311
312         call.addParameter(
313             "sCurrUserName",
314             org.apache.axis.Constants.XSD_STRING,
315             javax.xml.rpc.ParameterMode.IN);
316         call.addParameter(
317             "sPwd",
318             org.apache.axis.Constants.XSD_STRING,
319             javax.xml.rpc.ParameterMode.IN);
320
321         call.addParameter(
322             "sChangeUser",
323             org.apache.axis.Constants.XSD_STRING,
324             javax.xml.rpc.ParameterMode.IN);
325
326         call.addParameter(
327             "bIsSuper",
328             org.apache.axis.Constants.XSD_BOOLEAN,
329             javax.xml.rpc.ParameterMode.IN);
330
331         call.setReturnType(org.apache.axis.Constants.XSD_INTEGER);
332
333         Integer JavaDoc ret =
334             (Integer JavaDoc) call.invoke(
335                 new Object JavaDoc[] {
336                     sCurrUserName,
337                     sPwd,
338                     sChangeUser,
339                     new Boolean JavaDoc(bIsSuper) });
340
341     }
342
343 }
344
Popular Tags