Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTTP Search + Authenticate

Status
Not open for further replies.

oscript

Programmer
Mar 25, 2003
63
GB
I am in the process of writing a Java/J2EE Application and from within it I would like to be able to call the Livelink Search XML API. Clearly just executing the URL ‘ for example will cause the login page to be displayed which is not what I want.

Can you explain how I might be able to authenticate as part of the http: get ? Perhaps using JAAS ?
 
A not so elegant solution would be to send the userid and password string along with your request something like
creating a generic userid/password combo.Make sure you set perms correctly because anybody who knows how to book mark a url can steal your userid/password and depending on what your setup is like can run amok.So this would be your auto login URL for user guest/tseug




What I have done is build the login URL string and put your
real func as part of the nextURL with web escapes .All the percent chars are Hex.Hope you understand

A better secure way would be to use LAPI? or even a new request handler(Oscript)


Everybody is ignorant, only on different subjects. - Will Rogers

appnair
 
Have you tried using an authentication system such as Directory Services or LDAP, this would allow you to be logged on automatically.
 
These answers are great BUT I would like to know how to get the security context so that I can seemlessly login to Livelink from within a J2EE application using Directory Services. Does anyone have an example of this - it must be a fairly common requirement !
 
Attached is my java code to grab the XML. Unfortunately it gets the HTML redirect page which is not realy what I want:

import java.io.*;
import java.net.*;

public class DownloadHTMLFile {
public static void main(String[] args) {
URL llURL = null;
try {
llURL = new URL(" System.out.println("protocol = " + llURL.getProtocol());
System.out.println("host = " + llURL.getHost());
System.out.println("filename = " + llURL.getFile());
System.out.println("port = " + llURL.getPort());
}catch(MalformedURLException e){
// Malformed URL
System.out.println("Error in given URL");
return;
}

try {
URLConnection connection = llURL.openConnection();


HttpURLConnection uc = (HttpURLConnection)connection;
HttpURLConnection.setFollowRedirects(true);


BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line = "";
while ((line = br.readLine()) != null)
System.out.println(line);
br.close();
}catch(UnknownHostException e){
System.out.println("Unknown Host");
return;
}catch(IOException e){
System.out.println("Error in opening URLConnection, Reading or Writing");
return;
}
}
}

The setfollowredirects does not give me what I want.

Anyone done this sort of thing before with either XML export or, better still, search XML API ?
 
From the looks of it the nexturl redirection is not fully escaped, you did:


When it should be:



For those who see the cut off url, the nexturl should be:

nextURL=%2Fllservlet%2Flivelink.exe%3Ffunc%3Dll%26objId%3D56267%26objAction%3Dxmlexport

Livelink needs the entire next url escaped. I would try this and post the results.
 
David,

I appreciate the quick response and the point about proper escaping. Unfortunately this doesn't give any different result.

I have now further developed the code and extract the cookie information but am trying to work out how to pass it back in. Here is the additional code:

import java.io.*;
import java.net.*;

public class DownloadHTMLFile {
public static void main(String[] args) {
URL llURL = null;
try {
//llURL = new URL(" llURL = new URL("
System.out.println("protocol = " + llURL.getProtocol());
System.out.println("host = " + llURL.getHost());
System.out.println("filename = " + llURL.getFile());
System.out.println("port = " + llURL.getPort());

}catch(MalformedURLException e){
// Malformed URL
System.out.println("Error in given URL");
return;
}

try {
URLConnection connection = llURL.openConnection();

System.out.println("\n******************");

int n=1;
boolean done = false;
while (!done){
String headerKey = connection.getHeaderField(n);
String headerVal = connection.getHeaderField(n);
if (headerKey!=null || headerVal!=null) {
System.out.println(headerKey+"="+headerVal);
} else {
done = true;
}
n++;
}

System.out.println("\n******************");

HttpURLConnection uc = (HttpURLConnection)connection;
HttpURLConnection.setFollowRedirects(true);


BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line = "";
while ((line = br.readLine()) != null)
System.out.println(line);
br.close();
}catch(UnknownHostException e){
System.out.println("Unknown Host");
return;
}catch(IOException e){
System.out.println("Error in opening URLConnection, Reading or Writing");
return;
}
}
}
 
In further looking at this, the main problem is you want to do something in one step that requires two. the first step is to do the ll.login and get the cookie from that and store it in the code. The next thing is then submit your url with setting the coookie property of the connection with the cookie from the login.

You are trying to mimic a browser and I think you need to do this like a browser.

I hope this helps.
 
David,

Thanks for your input - anyone who might want to do this (not sure why!) but here is the solution:

import java.io.*;
import java.net.*;

public class DownloadHTMLFile {
public static void main(String[] args) {
URL llURL = null;
try {
//llURL = new URL(" llURL = new URL("
System.out.println("\n***GENERAL INFO SECTION***");

System.out.println("protocol = " + llURL.getProtocol());
System.out.println("host = " + llURL.getHost());
System.out.println("filename = " + llURL.getFile());
System.out.println("port = " + llURL.getPort());

}catch(MalformedURLException e){
// Malformed URL
System.out.println("Error in given URL");
return;
}

try {
URLConnection connection = llURL.openConnection();

System.out.println("\n***HEADER INFO SECTION***");

int n=1;
boolean done = false;
while (!done){
String headerKey = connection.getHeaderFieldKey(n);
String headerVal = connection.getHeaderField(n);
if (headerKey!=null || headerVal!=null) {
System.out.println(headerKey+"="+headerVal + " " + n);
} else {
done = true;
}
n++;
}

System.out.println("\n***COOKIE INFO SECTION***");

String cookie = connection.getHeaderField("Set-Cookie");

// get the specific LL Cookie at element 6
String LLcookie = connection.getHeaderField(6);

// print out for posterity
System.out.println("Cookie: " + cookie);
System.out.println("LLCookie: " + LLcookie);

System.out.println("\n***HTML RESPONSE INFO SECTION***");

//llURL = new URL(" // //llURL = new URL(" llURL = new URL("
// open a second connection
URLConnection connection2 = llURL.openConnection();

// set the cookie in the response
connection2.setRequestProperty("Cookie",LLcookie);

// NOT USED - EARLY EXPERIMENT WITH setFollowRedirects
//HttpURLConnection uc = (HttpURLConnection)connection2;
//HttpURLConnection.setFollowRedirects(true);


BufferedReader br = new BufferedReader(new InputStreamReader(connection2.getInputStream()));
String line = "";
while ((line = br.readLine()) != null)
System.out.println(line);
br.close();

}catch(UnknownHostException e){
System.out.println("Unknown Host");
return;
}catch(IOException e){
System.out.println("Error in opening URLConnection, Reading or Writing");
return;
}
}
}

/*
From the looks of it the nexturl redirection is not fully escaped:


When it should be:



For those who see the cut off url, the nexturl should be:

nextURL=%2Fllservlet%2Flivelink.exe%3Ffunc%3Dll%26objId%3D56267%26objAction%3Dxmlexport

Livelink needs the entire next url escaped. I would try this and post the results.
*/
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top