Return-Path: Delivered-To: apmail-jakarta-jetspeed-dev-archive@www.apache.org Received: (qmail 99658 invoked from network); 2 Dec 2004 03:15:32 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 2 Dec 2004 03:15:32 -0000 Received: (qmail 97346 invoked by uid 500); 2 Dec 2004 03:15:29 -0000 Delivered-To: apmail-jakarta-jetspeed-dev-archive@jakarta.apache.org Received: (qmail 97308 invoked by uid 500); 2 Dec 2004 03:15:29 -0000 Mailing-List: contact jetspeed-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jetspeed Developers List" Reply-To: "Jetspeed Developers List" Delivered-To: mailing list jetspeed-dev@jakarta.apache.org Received: (qmail 97293 invoked by uid 500); 2 Dec 2004 03:15:29 -0000 Received: (qmail 97279 invoked by uid 500); 2 Dec 2004 03:15:29 -0000 Received: (qmail 97275 invoked by uid 99); 2 Dec 2004 03:15:29 -0000 X-ASF-Spam-Status: No, hits=-10.0 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Wed, 01 Dec 2004 19:15:28 -0800 Received: (qmail 99621 invoked by uid 1265); 2 Dec 2004 03:15:27 -0000 Date: 2 Dec 2004 03:15:27 -0000 Message-ID: <20041202031527.99620.qmail@minotaur.apache.org> From: taylor@apache.org To: jakarta-jetspeed-2-cvs@apache.org Subject: cvs commit: jakarta-jetspeed-2/components/sso/src/test/org/apache/jetspeed/sso TestBasicSSO.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N taylor 2004/12/01 19:15:27 Added: components/sso/src/test/org/apache/jetspeed/sso TestBasicSSO.java Log: test basic authentication (this test should be skipped) Revision Changes Path 1.1 jakarta-jetspeed-2/components/sso/src/test/org/apache/jetspeed/sso/TestBasicSSO.java Index: TestBasicSSO.java =================================================================== /* * Copyright 2000-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.jetspeed.sso; import java.io.InputStream; import org.apache.commons.httpclient.Cookie; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpConnection; import org.apache.commons.httpclient.HttpState; import org.apache.commons.httpclient.UsernamePasswordCredentials; import org.apache.commons.httpclient.auth.AuthScheme; import org.apache.commons.httpclient.auth.HttpAuthenticator; import org.apache.commons.httpclient.cookie.CookiePolicy; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.MultipartPostMethod; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; /** * TestBasicSSO * * @author David Sean Taylor * @version $Id: TestBasicSSO.java,v 1.1 2004/12/02 03:15:27 taylor Exp $ */ public class TestBasicSSO extends TestCase { public static Test suite() { return new TestSuite(TestBasicSSO.class); } public void testBasicSSO() throws Exception { System.out.println("Testing SSO"); connect("http://localhost:8080/demo/sso-basic", "tomcat", "tomcat"); } public void connect(String server, String username, String password) throws Exception { HttpClient client = new HttpClient(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password); StringBuffer authenticationHeader = new StringBuffer("BASIC"); authenticationHeader.append(" realm=\""); authenticationHeader.append("jetspeed"); authenticationHeader.append("\""); Header[] headers = { new Header("WWW-Authenticate", authenticationHeader.toString())}; AuthScheme scheme = null; client.getState().setCredentials(null, null, credentials); GetMethod get = new GetMethod(server); // post = new MultipartPostMethod(server); get.setDoAuthentication(true); try { scheme = HttpAuthenticator.selectAuthScheme(headers); HttpConnection conn = client.getHttpConnectionManager().getConnection(get.getHostConfiguration()); boolean authenticated = HttpAuthenticator.authenticate(scheme, get, conn, client.getState()); if (!authenticated) { throw new Exception("Failed to create authentication headers to HTTP Connection"); } int status = client.executeMethod(get); System.out.println("response = [" + get.getResponseBodyAsString() + "]"); Cookie[] cookies = client.getState().getCookies(); Cookie mycookie = null; // Display the cookies System.out.println("Present cookies: "); for (int i = 0; i < cookies.length; i++) { System.out.println(" - " + cookies[i].toExternalForm()); mycookie = cookies[i]; } // get.releaseConnection(); // client.endSession(); HttpState initialState = new HttpState(); initialState.addCookie(mycookie); // client.getParams().setCookiePolicy(CookiePolicy.RFC_2109); client = new HttpClient(); client.setState(initialState); get = new GetMethod(server); status = client.executeMethod(get); System.out.println("response = [" + get.getResponseBodyAsString() + "]"); cookies = client.getState().getCookies(); // Display the cookies System.out.println("Present cookies: "); for (int i = 0; i < cookies.length; i++) { System.out.println(" - " + cookies[i].toExternalForm()); } get.releaseConnection(); } catch (Throwable t) { throw new Exception("Unexpected exception in creating HTTP authentication headers", t); } } } --------------------------------------------------------------------- To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org