How do you authenticate to an RTC server using LWP?
We just recently upgraded our servers to RHEL 7 and our perl scripts are no longer working. When I run the code below, I'm able to retrieve the root services document for our ccm server, but when I attempt to retrieve the catalog, I get a response telling me that authentication is required again. I run the same code on a different server that is still running RHEL 6 and the script runs perfectly. Why does this script no longer work?
!/usr/bin/perl
use Data::Dumper;
use LWP::UserAgent;
use HTTP::Request::Common;
use HTTP::Cookies;
use XML::Simple;
use MIME::Base64;
use URI::Escape;
*******
User Login Information
*******
my $username = 'username';
my $password = 'password';
*******
Define RTC URL
*******
my $rtc_url = "https://serverlocation:9443/ccm";
my $jts_url = "https://serverlocation:9443/jts";
my $catalog_header = 'oslc_cm:cmServiceProviders';
*******
Set Up User Agent
*******
my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0}, );
my $req = GET "$rtc_url/ccm/authenticated/j_security_check?j_username=$username&j_password=$password";
my $res = $ua->request($req);
*******
Get Root Services
*******
my $req = GET "$rtc_url/rootservices";
my $res = $ua->request($req);
my $content = $res->content;
my $xml = new XML::Simple;
my $root_services_data = $xml->XMLin($content);
*******
Get Project URLs
*******
my $catalog = $root_services_data->{$catalog_header}->{'rdf:resource'};
my $req = HTTP::Request->new("GET" => "$catalog");
$req->header('Accept', "application/rdf+xml");
$req->header('OSLC-Core-Version', "2.0");
my $res = $ua->request($req);
my $xml = new XML::Simple;
my $catalog_data = $xml->XMLin($res->content,ForceArray => ['oslc:serviceProvider']);
my $projects_hash;
foreach my $project (@{$catalog_data->{'oslc:ServiceProviderCatalog'}->{'oslc:serviceProvider'}})
{
my $str_project_name = $project->{'oslc:ServiceProvider'}->{'dcterms:title'}->{'content'};
my $str_project_details_url = $project->{'oslc:ServiceProvider'}->{'oslc:details'}->{'rdf:resource'};
$projects_hash{$str_project_name} = $str_project_details_url;
}
Comments
Shawn Carroll
Nov 05 '18, 1:27 p.m.Kevin Ramer
Nov 05 '18, 1:48 p.m.Shawn Carroll
Nov 05 '18, 1:56 p.m.Shawn Carroll
Nov 05 '18, 1:57 p.m.Shawn Carroll
Nov 05 '18, 1:57 p.m.Shawn Carroll
Nov 05 '18, 1:57 p.m.