01: /**
02: * JOnAS: Java(TM) Open Application Server
03: * Copyright (C) 2005 Bull S.A.
04: * Contact: jonas-team@objectweb.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or 1any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19: * USA
20: *
21: * --------------------------------------------------------------------------
22: * $Id: JonasAdminAuth.java 6821 2005-05-25 10:51:47Z kemlerp $
23: * --------------------------------------------------------------------------
24: */package org.objectweb.jonas.jonasadmin.test.util;
25:
26: import com.meterware.httpunit.WebConversation;
27: import com.meterware.httpunit.WebForm;
28: import com.meterware.httpunit.WebResponse;
29:
30: /**
31: * JonasAdmin authentification
32: * @author kemlerp
33: *
34: */
35: public class JonasAdminAuth {
36:
37: /**
38: * Constructor
39: *
40: */
41: private JonasAdminAuth() {
42: super ();
43: }
44:
45: /**
46: * Authenticate with a valid login/password
47: * @param wc Web Conversation to use
48: * @param url url to use
49: * @return the response
50: * @throws Exception if an error occurs
51: */
52: public static WebResponse doValidAuth(WebConversation wc, String url)
53: throws Exception {
54: return doAuth(wc, url, "jonas", "jonas");
55: }
56:
57: /**
58: * Authenticate with the specified login/password
59: * @param wc Web Conversation to use
60: * @param url url to use
61: * @param login login to use
62: * @param password password to use
63: * @return the response after authentication
64: * @throws Exception if an error occurs
65: */
66: public static WebResponse doAuth(WebConversation wc, String url,
67: String login, String password) throws Exception {
68: WebResponse wr = wc.getResponse(url);
69: WebForm[] webForms = wr.getForms();
70: WebForm webForm = webForms[0];
71:
72: webForm.setParameter("j_username", login);
73: webForm.setParameter("j_password", password);
74: return webForm.submit();
75: }
76: }
|