Using Perl to Access the Lawson DME in LSF9 Environment
I wrote a previous article about using perl to query the Lawson DME for 8.0.3 environment. We just got the LSF9 environment (not apps), and to my surprise, the authentication is different between the two.
The authentication for Lawson DME in 8.0.3 environment uses http basic authentication.
The authentication for LSF9 environment uses Lawson's own server side authentication.
Obviously this means that the method of accessing the DME from perl needs to change. The perl code design has to change from using built in LWP credentials method of navigating through HTTP basic auth to simulating a login on the Lawson login page, capturing the cookie, and bringing it along with to make the request to the DME.
Here is the new code. The function takes 3 arguments, a URL, userame, and password. We only have a secure https address to access our DME, so that is why the Crypt::SSLeay library is needed.
###############
# gets the raw Lawson DME response from the server from a https secure site
# arguments:
# URL - full URL, is designed to use https URLs
# Username - Lawson portal username
# Password - Lawson portal password
###############
sub getLawsonDMEResponse($$$) {
use LWP::UserAgent;
use Crypt::SSLeay;
use HTML::Form;
my $url = shift;
my $username = shift;
my $password = shift;
my $ua = LWP::UserAgent->new;
$ua->cookie_jar( {} ); # cookies needed for login authentication
my $response = $ua->get($url);
if($response->is_success) {
# parse loginForm form and enter the values for the _ssoUser and _ssoPass field names
my @forms = HTML::Form->parse($response);
$forms[0]->value("_ssoUser",$username);
$forms[0]->value("_ssoPass",$password);
my $loginButton = $forms[0]->find_input("_ssoLogin");
$loginButton->disabled(0);
my $response2 = $ua->request($forms[0]->click("_ssoLogin"));
if($response2->is_success) {
# its OK, response 2 never succeeds, oh well, all we want is a cookie
# it will fail with a 302 moved
}
else {
# go ahead and call the URL we want
my $response3 = $ua->get($url);
if($response3->is_success) {
return $response3->content;
}
else {
print "URL request failed for url:$url\n";
}
}
}
else {
die "Problems getting through login screen\n";
}
}
- Topics:




