The Artima Developer Community
Sponsored Link

Java Answers Forum
Servlets and dominoserver authentication

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
subha

Posts: 3
Nickname: neithilath
Registered: Oct, 2002

Servlets and dominoserver authentication Posted: Oct 30, 2002 9:19 PM
Reply to this message Reply
Advertisement
There is a login program which delivers a cookie.With this cookie I have to get the authentication done so that servlet can be called.


The OS which i am using is windows NT(in which the domino server is running, and for which i am in need of the authentication, in which my servlet file-i am in need of - is available) and the Linux server.(in which the apache server is running and the file, which does the authentication process is available.)

I am herewith sending the file(dologin.pm), which does the authentication work, which is a perl file.
Also, i am sending the file which apeals or tries to get the authentication by use of the above said file.



doLogin program:should return a cookie which inturn should get the authentication done from the server.Can you suggest a way to get this done



package SSO::dologin;
use strict;
use Apache::Constants qw(:common);
use Apache::Constants qw(:methods);
use Apache::Constants qw(:response);

use SSO::LDAP;
use SSO::UserProfile;
use SSO::Server;
use SSO::Cookie;
use SSO::Cache;
use SSO::Hash;

sub handler {

my $r = shift;


my %inputvals=$r->content;
my $username=$inputvals{'username'};
my $password=$inputvals{'password'};


if((not defined $username) || (not defined $password)) {
$r->log_reason("UserName/Password Not given ",$r->filename);
return FORBIDDEN;
}

my $userprofile = SSO::UserProfile->new();
$userprofile->UserName($username);
$userprofile->Password($password);



my $ldapserver = SSO::Server->new();
my $ldapIP = $r->dir_config("LDAPServer");
my $ldapport = $r->dir_config("LDAPServerPort");

#If the ldap IP and Port are not given return error
if(not defined $ldapIP) {
$r->log_reason("Environment Variable LDAPServer is not Set",$r->filename);
return SERVER_ERROR;
}

$ldapserver->IP($ldapIP);
$ldapserver->Port($ldapport);
my $ldap=SSO::LDAP->new();
my $authstatus=$ldap->AuthenticateUser($ldapserver,$userprofile);
if(!$authstatus) {
$r->log_reason(" Unable to Authenticate UserName/Password",$r->filename);
return FORBIDDEN;
}

# Check the user status
if(!$userprofile->UserStatus) {
$r->log_reason(" User Status : Disabled ",$r->filename);
return FORBIDDEN;
}

# Generate Hash key (SessionId) for the User
my $theexpduration = $r->dir_config("SessionExpiryDur");

#If the expiry duration is not given return error
if(not defined $theexpduration) {
$r->log_reason("Environment Variable SessionExpiryDur is not Set",$r->filename);
return SERVER_ERROR;
}
$userprofile->SessionExpiryDur($theexpduration);


my $hash=SSO::Hash->new;
my $sessionid=$hash->generateSessionId($userprofile,$r);


if ((not defined $sessionid) || ($sessionid eq "")) {
$r->log_reason("SessionID not generated ",$r->filename);
return SERVER_ERROR;
}


my $multilogin = $r->dir_config("MultiLogin");
my $cache=SSO::Cache->new();
if((not defined $multilogin) || ($multilogin == 0 )) {
# If the user already present in cache remove him
$cache->removeUserByUserName($userprofile->UserName);
}


$cache->addUser($userprofile);


my $cook=SSO::Cookie->new();
$cook->setCookie_ErrHeader("SSOAuthSessionID",$userprofile->SessionId,$r) ;


my $homepage = $r->dir_config("UsersHomePage");

my @form = ("/forms/","dologin","dologout","index.html");
foreach(@form){
if(($r->header_in('referer') =~/$_/i)) {
$homepage = $r->dir_config("UsersHomePage");
last if 1 ;
}
else {
$homepage = $r->header_in('referer');
}
}

if(not defined $homepage) {
$r->log_reason("Environment Variable UsersHomePage is not Set",$r->filename);
return SERVER_ERROR;
}

$r->headers_out->add(Location => $homepage);
$r->headers_out->add(referer=> $r->header_in('referer'));
$r->status(REDIRECT);
$r->send_http_header();
return OK;
}


authentication done by the following program:


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

public class authen
{
public static void main(String args[]) throws Exception
{
URL theurl = new URL("http://192.168.10.10/dologin");
HttpURLConnection hurl = (HttpURLConnection)(theurl.openConnection());
hurl.setRequestMethod("POST");
hurl.setDoInput(true);
hurl.setDoOutput(true);
hurl.setUseCaches(false);
hurl.setFollowRedirects(true);
// String cookie = hurl.getHeaderField("Set-Cookie");

hurl.setRequestProperty("Accept","application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*");
hurl.setRequestProperty("Accept-Language","en-us");
hurl.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
hurl.setRequestProperty("Accept-Encoding","gzip, deflate");
hurl.setRequestProperty("User-Agent"," Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
hurl.setRequestProperty("Connection","Keep-Alive");

String idpassword = "username=sakthivel&password=12345";
hurl.connect();

OutputStream o= hurl.getOutputStream();
byte[] by= idpassword.getBytes();
o.write(by);
o.flush();
o.close();


int ic=0;
String key="";
while (true)
{
key = hurl.getHeaderFieldKey (ic);

if(key == null)
{
break;
}
if(key!=null)
{
String value = hurl.getHeaderField (ic++);
System.out.println(key + " - " + value);
}
}
hurl.disconnect();
}
}

Topic: core java interview questions Previous Topic   Next Topic Topic: RMI Callback

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use