/** * Creates a HTTP Domino login POST String. * * @author Johan Känngård, http://dev.kanngard.net * @param host the ip or DNS name of the server. * @param username the Domino user name. * @param password the Domino password * @return a String containing the Domino login POST. */ private String getLoginRequest( String host, String username, String password) { String formData = getFormData( new String[] {"UserName", "Password"}, new String[] {username, password}); return "POST /?Login HTTP/1.1\n" + "Host: " + host + "\n" + "Content-Type: application/x-www-form-urlencoded\n" + "Content-Length: " + formData.length() + "\n" + "\n" + formData + "\n"; } /** * Creates a GET String for restricted areas in Domino. * * @author Johan Känngård, http://dev.kanngard.net * @param host the ip or DNS name of the server. * @param url the url on the server to visit, with the * restricted contents * @param domCookie the DomAuthSessId cookie that was sent * to the client when logging in. * @return the GET String for restricted areas in Domino. */ private String getRestrictedRequest( String host, String url, String domCookie) { return "GET " + url + " HTTP/1.1\n" + "Host: " + host + "\n" + "Cookie: DomAuthSessId=" + domCookie + "\n"; } /** * Creates the GET String for logging out of Domino. * * @author Johan Känngård, http://dev.kanngard.net * @param host the ip address or DNS name of the server. * @param domCookie the DomAuthSessId cookie that was sent * to the client when logging in. * @return the GET String to end the Domino session. */ private String getLogoutRequest(String host, String domCookie) { return getRestrictedRequest(host, "/?Logout", domCookie); } /** * URL-encodes the form data in the specified Hashtable and * returns a String that can be used as the query part in * an URL / HTTP GET or HTTP POST. * * @author Johan Känngård, http://dev.kanngard.net * @param keys an array of Strings with the keys. * @param values an array of Strings with the values. * @return an URL-encoded String with the key / value pairs * in x-www-form-urlencoded format. */ private String getFormData(String[] keys, String[] values) { StringBuffer formData = new StringBuffer(); for (int i = 0; i < keys.length; i++) { formData.append(URLEncoder.encode(keys[i]) + "=" + URLEncoder.encode(values[i]) + "&"); } return formData.toString().substring(0, formData.length() - 1); } /** * Searches a String for the DomAuthSessId cookie and returns * the value of it. * * @param response the server response to search the cookie in. * @return the value of the cookie DomAuthSessId or null if no cookie * was found. */ private String getSessionCookie(String response) { String cookieName = "DomAuthSessId="; int index = response.indexOf(cookieName); if (index == -1) { return null; } index = index + cookieName.length(); return response.substring(index, index + 32); }