001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.harmonise;
020:
021: import java.net.*;
022: import java.rmi.RemoteException;
023:
024: import org.apache.axis.client.Call;
025: import org.apache.axis.client.Service;
026:
027: import javax.xml.namespace.QName;
028: import javax.xml.rpc.ServiceException;
029:
030: /**
031: * This class provides a client interface to the Harmonise user config webservice
032: *
033: * @author Michael Bell
034: * @version $Revision: 1.2 $
035: *
036: */
037: public class UserConfigClient {
038:
039: public static final int CODE_SUCCESS = 200;
040: public static final int CODE_AUTHENTICATION_FAIL = 402;
041: public static final int CODE_INVALID_LENGTH = 403;
042: public static final int CODE_NO_ALPHA_CHAR = 404;
043: public static final int CODE_NO_NUM_CHAR = 405;
044: public static final int CODE_NO_CASE_MIX = 406;
045: public static final int CODE_INVALID_USER_STATE = 407;
046: public static final int CODE_PWD_REPEAT = 408;
047: public static final String SIMULACRA_WEBSERVICE_NAMESPACE_URI = "http://www.openharmonise.org/";
048:
049: /**
050: *
051: */
052: public UserConfigClient() {
053: super ();
054: }
055:
056: /**
057: * Makes SOAP request to change the password of the user with the user name
058: * <code>sChangeUserName</code> using the user with user name <code>sCurrUserName</code>
059: *
060: * @param endpoint
061: * @param sCurrUserName
062: * @param sCurrUserPwd
063: * @param sChangeUserName
064: * @param sChangeOldPwd
065: * @param sChangeNewPwd
066: * @return
067: * @throws java.rmi.RemoteException
068: * @throws ServiceException
069: */
070: public static int setPassword(URL endpoint, String sCurrUserName,
071: String sCurrUserPwd, String sChangeUserName,
072: String sChangeNewPwd) throws java.rmi.RemoteException,
073: ServiceException {
074:
075: Service service = new Service();
076: Call call = (Call) service.createCall();
077:
078: call.setTargetEndpointAddress(endpoint);
079: call.setOperationName(new QName(
080: SIMULACRA_WEBSERVICE_NAMESPACE_URI, "setPassword"));
081:
082: call.addParameter("sCurrUserName",
083: org.apache.axis.Constants.XSD_STRING,
084: javax.xml.rpc.ParameterMode.IN);
085: call.addParameter("sCurrUserPwd",
086: org.apache.axis.Constants.XSD_STRING,
087: javax.xml.rpc.ParameterMode.IN);
088:
089: call.addParameter("sChangeUserName",
090: org.apache.axis.Constants.XSD_STRING,
091: javax.xml.rpc.ParameterMode.IN);
092:
093: call.addParameter("sChangeNewPwd",
094: org.apache.axis.Constants.XSD_STRING,
095: javax.xml.rpc.ParameterMode.IN);
096:
097: call.setReturnType(org.apache.axis.Constants.XSD_INTEGER);
098: call.setReturnClass(Integer.class);
099:
100: Integer ret = (Integer) call.invoke(new Object[] {
101: sCurrUserName, sCurrUserPwd, sChangeUserName,
102: sChangeNewPwd });
103:
104: return ret.intValue();
105:
106: }
107:
108: /**
109: * Makes SOAP request to check whether the given password has expired for the user
110: * with user name <code>sUserName</code>
111: *
112: * @param endpoint
113: * @param sUserName
114: * @param sPwd
115: * @return
116: * @throws ServiceException
117: * @throws RemoteException
118: */
119: static public boolean hasPasswordExpired(URL endpoint,
120: String sUserName, String sPwd) throws ServiceException,
121: RemoteException {
122: Service service = new Service();
123: Call call = (Call) service.createCall();
124:
125: call.setTargetEndpointAddress(endpoint);
126: call.setOperationName(new QName(
127: SIMULACRA_WEBSERVICE_NAMESPACE_URI,
128: "hasPasswordExpired"));
129:
130: call.addParameter("sUserName",
131: org.apache.axis.Constants.XSD_STRING,
132: javax.xml.rpc.ParameterMode.IN);
133: call.addParameter("sPwd", org.apache.axis.Constants.XSD_STRING,
134: javax.xml.rpc.ParameterMode.IN);
135:
136: call.setReturnType(org.apache.axis.Constants.XSD_BOOLEAN);
137: call.setReturnClass(Boolean.class);
138:
139: Boolean ret = (Boolean) call.invoke(new Object[] { sUserName,
140: sPwd });
141:
142: return ret.booleanValue();
143: }
144:
145: /**
146: * Makes SOAP request to check with the user with the given user name and password
147: * is a super user
148: *
149: * @param endpoint
150: * @param sUserName
151: * @param sPwd
152: * @return
153: * @throws ServiceException
154: * @throws RemoteException
155: */
156: static public boolean isSuperUser(URL endpoint, String sUserName,
157: String sPwd) throws ServiceException, RemoteException {
158: Service service = new Service();
159: Call call = (Call) service.createCall();
160:
161: call.setTargetEndpointAddress(endpoint);
162: call.setOperationName(new QName(
163: SIMULACRA_WEBSERVICE_NAMESPACE_URI, "isSuperUser"));
164:
165: call.addParameter("sUserName",
166: org.apache.axis.Constants.XSD_STRING,
167: javax.xml.rpc.ParameterMode.IN);
168: call.addParameter("sPwd", org.apache.axis.Constants.XSD_STRING,
169: javax.xml.rpc.ParameterMode.IN);
170:
171: call.setReturnType(org.apache.axis.Constants.XSD_BOOLEAN);
172: call.setReturnClass(Boolean.class);
173:
174: Boolean ret = (Boolean) call.invoke(new Object[] { sUserName,
175: sPwd });
176:
177: return ret.booleanValue();
178: }
179:
180: /**
181: * Makes SOAP request to check with the user with the given user name and password
182: * is a super user
183: *
184: * @param endpoint
185: * @param sUserName
186: * @param sPwd
187: * @return
188: * @throws ServiceException
189: * @throws RemoteException
190: */
191: static public boolean isSuperUser(URL endpoint, String sUserName,
192: String sPwd, String sCheckUser) throws ServiceException,
193: RemoteException {
194: Service service = new Service();
195: Call call = (Call) service.createCall();
196:
197: call.setTargetEndpointAddress(endpoint);
198: call.setOperationName(new QName(
199: SIMULACRA_WEBSERVICE_NAMESPACE_URI, "isSuperUser"));
200:
201: call.addParameter("sUserName",
202: org.apache.axis.Constants.XSD_STRING,
203: javax.xml.rpc.ParameterMode.IN);
204: call.addParameter("sPwd", org.apache.axis.Constants.XSD_STRING,
205: javax.xml.rpc.ParameterMode.IN);
206: call.addParameter("sCheckUser",
207: org.apache.axis.Constants.XSD_STRING,
208: javax.xml.rpc.ParameterMode.IN);
209:
210: call.setReturnType(org.apache.axis.Constants.XSD_BOOLEAN);
211: call.setReturnClass(Boolean.class);
212:
213: Boolean ret = (Boolean) call.invoke(new Object[] { sUserName,
214: sPwd, sCheckUser });
215:
216: return ret.booleanValue();
217: }
218:
219: /**
220: * Returns <code>true</code> if the user with the given user name is locked
221: * out of the system
222: *
223: * @param endpoint
224: * @param sUserName
225: * @return
226: * @throws ServiceException
227: * @throws RemoteException
228: */
229: static public boolean isUserLockedOut(URL endpoint, String sUserName)
230: throws ServiceException, RemoteException {
231: Service service = new Service();
232: Call call = (Call) service.createCall();
233:
234: call.setTargetEndpointAddress(endpoint);
235: call.setOperationName(new QName(
236: SIMULACRA_WEBSERVICE_NAMESPACE_URI, "isUserLockedOut"));
237:
238: call.addParameter("sUserName",
239: org.apache.axis.Constants.XSD_STRING,
240: javax.xml.rpc.ParameterMode.IN);
241:
242: call.setReturnType(org.apache.axis.Constants.XSD_BOOLEAN);
243: call.setReturnClass(Boolean.class);
244:
245: Boolean ret = (Boolean) call.invoke(new Object[] { sUserName });
246:
247: return ret.booleanValue();
248: }
249:
250: /**
251: * Makes SOAP request to set whether the user is a super user.
252: *
253: * @param endpoint
254: * @param sCurrUserName the user name of the user making the change
255: * @param sPwd the password of the user making the change
256: * @param sNewSuperUser the user name of the user to be changed
257: * @param bIsSuper <code>true</code> if the user to be changed is to be a super user, otherwise <code>false</code>
258: * @throws java.rmi.RemoteException if the current user is not allowed to make the change,
259: * there is a pending version of the user to be changed or a general
260: * error occurs
261: * @throws ServiceException
262: */
263: public static void setIsSuperUser(URL endpoint,
264: String sCurrUserName, String sPwd, String sChangeUser,
265: boolean bIsSuper) throws java.rmi.RemoteException,
266: ServiceException {
267:
268: Service service = new Service();
269: Call call = (Call) service.createCall();
270:
271: call.setTargetEndpointAddress(endpoint);
272: call.setOperationName(new QName(
273: SIMULACRA_WEBSERVICE_NAMESPACE_URI, "setIsSuperUser"));
274:
275: call.addParameter("sCurrUserName",
276: org.apache.axis.Constants.XSD_STRING,
277: javax.xml.rpc.ParameterMode.IN);
278: call.addParameter("sPwd", org.apache.axis.Constants.XSD_STRING,
279: javax.xml.rpc.ParameterMode.IN);
280:
281: call.addParameter("sChangeUser",
282: org.apache.axis.Constants.XSD_STRING,
283: javax.xml.rpc.ParameterMode.IN);
284:
285: call.addParameter("bIsSuper",
286: org.apache.axis.Constants.XSD_BOOLEAN,
287: javax.xml.rpc.ParameterMode.IN);
288:
289: call.setReturnType(org.apache.axis.Constants.XSD_INTEGER);
290:
291: Integer ret = (Integer) call
292: .invoke(new Object[] { sCurrUserName, sPwd,
293: sChangeUser, new Boolean(bIsSuper) });
294:
295: }
296:
297: }
|