KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jonasadmin > test > util > JonasAdminAuth


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2005 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * 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,v 1.1 2005/05/25 10:51:47 kemlerp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jonasadmin.test.util;
27
28 import com.meterware.httpunit.WebConversation;
29 import com.meterware.httpunit.WebForm;
30 import com.meterware.httpunit.WebResponse;
31
32 /**
33  * JonasAdmin authentification
34  * @author kemlerp
35  *
36  */

37 public class JonasAdminAuth {
38
39     /**
40      * Constructor
41      *
42      */

43     private JonasAdminAuth() {
44         super();
45     }
46     /**
47      * Authenticate with a valid login/password
48      * @param wc Web Conversation to use
49      * @param url url to use
50      * @return the response
51      * @throws Exception if an error occurs
52      */

53     public static WebResponse doValidAuth(WebConversation wc, String JavaDoc url) throws Exception JavaDoc {
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 JavaDoc url, String JavaDoc login, String JavaDoc password) throws Exception JavaDoc {
67         WebResponse wr = wc.getResponse(url);
68         WebForm[] webForms = wr.getForms();
69         WebForm webForm = webForms[0];
70
71         webForm.setParameter("j_username", login);
72         webForm.setParameter("j_password", password);
73         return webForm.submit();
74     }
75 }
76
Popular Tags