8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * opensso/legal/CDDLv1.0.txt
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * at opensso/legal/CDDLv1.0.txt.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: CLILogin.java,v 1.2 2008/06/25 05:41:27 qcheng Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
2265cfe8ee36d40dc946cde472ecd12c61f856b2Peter Major * Portions Copyrighted 2011-2014 ForgeRock AS
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.iplanet.am.util;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.io.BufferedReader;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.io.IOException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.io.InputStreamReader;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.io.PrintWriter;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.net.HttpURLConnection;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.net.ProtocolException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.net.URL;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Map;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.sso.SSOException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.sso.SSOToken;
2265cfe8ee36d40dc946cde472ecd12c61f856b2Peter Majorimport com.sun.identity.common.HttpURLConnectionManager;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class CLILogin {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String host = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String domain = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String userId = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String passwd = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String gotoUrl = "console";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String protocol = "http";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String cookie = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String cookieValue = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SSOToken ssotoken = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Later more constructors can be added, as per requirements.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public CLILogin(String host, String domain, String userId, String passwd) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.host = host;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.domain = domain;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.userId = userId;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.passwd = passwd;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Retunrs true if logged in, else returns false. It is just a convenience
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // method to check the login status.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public boolean isLoggedIn() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return isSessionValid();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Returns the SessionId associated with this Session
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getSessionId() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return cookieValue;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Return the SSOToken associated with this login object
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public SSOToken getToken() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return ssotoken;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Returns true if the session associated with CLILogin object is valid,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // else returns false
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public boolean isSessionValid() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return validateSession(cookieValue);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Returns the output of accessing a URL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getURL(URL url) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String str = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster str = urlAccess(url, cookie, true);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception e) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("Exception in getURL");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return str;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Returns the cookies associated with the login. Will be implemented later
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Map getCookies() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // logout the user
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void logout() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (ssotoken != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster com.iplanet.sso.SSOProvider manager =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster new com.iplanet.sso.providers.dpro.SSOProviderImpl();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster manager.destroyToken(ssotoken);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster cookieValue = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ssotoken = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster cookie = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (SSOException e) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println(e.getMessage());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Returns true if login is successful else false.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public boolean login() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (host == null || domain == null || userId == null || passwd == null)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean loggedin = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // URL url = new URL(protocol + "://"+ host + "/login/LDAP");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster URL url = new URL(protocol + "://" + host + "/login/LDAP?goto="
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + gotoUrl);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster cookie = getCookie(url);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int index = cookie.indexOf("=");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int index1 = cookie.indexOf(";");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster cookieValue = cookie.substring(index + 1, index1);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (cookieValue == null)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("Cookie = " + cookie);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("CookieVal = " + cookieValue);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // authenticate user using LDAP module through POST
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster url = new URL(protocol + "://" + host + "/login/LDAP");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster authenticate(url, cookie, userId, passwd);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("===== validate session after authenticate ===");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // check if really logged in or not
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster cookieValue = convertCookie(cookieValue);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster loggedin = isSessionValid();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception ex) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ex.printStackTrace();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (!loggedin)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster logout();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return loggedin;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Returns true if the session associated with CLILogin object is valid,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // else returns false
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private boolean validateSession(String cookieValue) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (cookieValue == null)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster com.iplanet.sso.SSOProvider manager =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster new com.iplanet.sso.providers.dpro.SSOProviderImpl();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ssotoken = manager.createSSOToken(cookieValue);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (manager.isValidToken(ssotoken)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("Valid session for "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + ssotoken.getProperty("Principal"));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return true;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("Invalid session");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (SSOException e) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println(e.getMessage());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String getCookie(URL url) throws IOException {
2265cfe8ee36d40dc946cde472ecd12c61f856b2Peter Major HttpURLConnection connection = HttpURLConnectionManager.getConnection(url);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Get the iPlanetDirectoryPro cookie from the header, strip off
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // the cookie name, domain, and path to get the value, it must be
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // included in the next post to the auth server, the cookie anme
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // should be taken from the platform.conf
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String cookie = connection.getHeaderField("Set-cookie");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (cookie == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("No cookies in HTTP request, server down ?"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + url);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster connection.disconnect();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return cookie;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static void authenticate(URL url, String cookie, String userName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String passWord) throws IOException, ProtocolException {
2265cfe8ee36d40dc946cde472ecd12c61f856b2Peter Major HttpURLConnection connection = HttpURLConnectionManager.getConnection(url);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster connection.setDoOutput(true);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster connection.setRequestMethod("POST");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster connection.setRequestProperty("Cookie", cookie);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // don't follow redirects since we don't care about them
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // and the auth will do a final redirect after successful
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // authentication. Instead we will just check the session
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // to see if auth suceeded.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster HttpURLConnection.setFollowRedirects(false);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster PrintWriter out = new PrintWriter(connection.getOutputStream());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster out.print("TOKEN0=" + userName + "&TOKEN1=" + passWord);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster out.close();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Must get the input stream in order to complete the post even
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // though we don't care about the response.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster new BufferedReader(new InputStreamReader(connection.getInputStream()));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String urlAccess(URL url, String cookie, boolean print)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws IOException, ProtocolException {
2265cfe8ee36d40dc946cde472ecd12c61f856b2Peter Major HttpURLConnection connection = HttpURLConnectionManager.getConnection(url);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster connection.setDoOutput(true);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster connection.setRequestMethod("GET");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster connection.setRequestProperty("Cookie", cookie);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String strOutput = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // read output from server
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster BufferedReader in = new BufferedReader(new InputStreamReader(connection
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster .getInputStream()));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (print) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster StringBuilder in_buf = new StringBuilder();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int len;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster char[] buf = new char[1024];
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while ((len = in.read(buf, 0, buf.length)) != -1) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster in_buf.append(buf, 0, len);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster strOutput = in_buf.toString();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.print(strOutput);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return strOutput;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String convertCookie(String cookie) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // System.out.println("cookie=" + cookie);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while (true) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int temp = cookie.indexOf("%25");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (temp == -1) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return cookie;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String newCookie = cookie.substring(0, temp) + "%"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + cookie.substring(temp + 3);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // System.out.println("cookie=" + newCookie);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster cookie = newCookie;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}