[lug] Off topic: java form-based authentication in a client program
bgiles at coyotesong.com
bgiles at coyotesong.com
Wed Aug 30 15:07:02 MDT 2006
Nope -- form-based authentication passes the username & password to the
j_security_check action. That action sets a JSESSIONID cookie that's used
to identify the client in subsequent visits.
Okay, I lie. There's also a mode where all of the URLs are rewritten to
include a JSESSIONID=XXXXXXXXXXXX, but it's undoubtably easier to deal
with cookies programmatically.
> On Wed, 30 Aug 2006, Michael J. Hammel wrote:
>
>> A browser-based login works just fine. But I'm having problems finding
>> information on how to programmatically login from the Java client.
>
> Hi Michael - I'm not sure this is what you want, but here's a java
> fragment that accesses a password-protected web site. It relies on
> another Base64Converter class that can be found on-line.
>
> Jim
>
> ---
>
> import java.awt.*;
> import java.io.*;
> import java.net.*;
>
> public class Install
> {
> public static void fetch(String address, String pw)
> throws MalformedURLException, IOException
> {
> String line;
> URL url = new URL(address);
> URLConnection uc = url.openConnection();
> String encoding = Base64Converter.encode("demo:" + pw );
> uc.setRequestProperty("Authorization", "Basic " + encoding);
> InputStream content = (InputStream)uc.getInputStream();
> BufferedReader in = new BufferedReader(new
> InputStreamReader(content));
> while ((line = in.readLine()) != null) { }
> }
> public static void main(String[] args)
> throws MalformedURLException, IOException
> {
> fetch( args[0], args[1]) ;
> }
> }
>
>
>
> --------------------------------------------------------------------------------
> Jim Buzbee "I was gratified to be able to
> jbuzbee at nyx.net answer promptly, and I did. I
> http://batbox.org said I didn't know." Mark Twain
>
> _______________________________________________
> Web Page: http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> Join us on IRC: lug.boulder.co.us port=6667 channel=#colug
>
More information about the LUG
mailing list