#!/usr/bin/perl # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. use CGI qw/:standard/; use WSO2::WSF; use XML::LibXML; my $q = new CGI; my $WSFC_HOME='/opt/wso2/wsf_c/'; # if for some bizarre inexplicable reason, user tries to login for the second time redirect his arse # back to the home page # if ( cookie('icanhazlogin') eq "gudkitteh" ) { # print redirect( -uri => 'http://localhost', -status => 302 ); # } # # # get the endpoitn from the configuration service sub get_endpoint { $config_endpoint = $q->cookie('endpoint'); $input_xml = < PERL_CLIENT XML my $client = new WSO2::WSF::WSClient( { 'to' => $config_endpoint, 'log_file' => '/tmp/stocktrader.log', 'log_level' => 4, 'wsfc_home' => $WSFC_HOME } ); my $response_msg = $client->request( { 'payload' => $input_xml } ); my $response_str = $response_msg->{str}; my $response_parser = XML::LibXML->new(); $response_xml = $response_parser->parse_string($response_str); my $xpc = XML::LibXML::XPathContext->new($response_xml); $xpc->registerNs('ns'=> 'http://wso2.org/interop/stocktrader/xsd'); $bs = $xpc->findvalue('//ns:BS'); return $bs; } # username and password is given my $username = $q->param('USERNAME'); my $password = $q->param('PASSWORD'); # stores the response XML my $response; # if the response XML is good and a cookie is not set, we use this to set one my $cookie; if ( defined($username) && defined($password) ) { my $login_request =< ${username} ${password} EOF my $tmp_endpoint = get_endpoint(); my $client = new WSO2::WSF::WSClient( { 'to' => $tmp_endpoint, 'log_file' => '/tmp/stocktrader.log', 'log_level' => 4, 'wsfc_home' => $WSFC_HOME } ); $response = $client->request( { 'payload' => $login_request } ); $response_str = $response->{str}; # $resposne = < # # 1 # 6 # 0 # 2008-07-18T16:06:35.42 # 2008-05-21T16:01:44.063 # 100000.00 # 200000.00 # uid:0 # # #XML my $parser = XML::LibXML->new(); $xml = $parser->parse_string($response_str); # profileID will be set for valid users my $xpc = XML::LibXML::XPathContext->new($xml); $xpc->registerNs('ns'=> 'http://trade.samples.websphere.ibm.com'); my $pid = $xpc->findvalue('//ns:profileID'); if ( $pid) { # credentials are good, setting the fricking cookie $cookie = cookie( -name => 'username', -value => $pid ); } } if ( defined $cookie ) { print $q->header( -cookie => $cookie); print ""; exit(0); } else { print $q->header(); } my $html_begin =< WSF/Perl StockTrader Welcome

Login

EOF print $html_begin; print $login_form; print $html_end;