line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# XDI::SPIT.pm |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# $Id: SPIT.pm,v 1.3 2004/08/03 21:05:36 eekim Exp $ |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Copyright (c) Blue Oxen Associates 2004. All rights reserved. |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# See COPYING for licensing terms. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package XDI::SPIT; |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
33213
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
79
|
|
12
|
1
|
|
|
1
|
|
1034
|
use HTTP::Request; |
|
1
|
|
|
|
|
40238
|
|
|
1
|
|
|
|
|
32
|
|
13
|
1
|
|
|
1
|
|
1012
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
31437
|
|
|
1
|
|
|
|
|
38
|
|
14
|
1
|
|
|
1
|
|
23
|
use URI::Escape; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
88
|
|
15
|
1
|
|
|
1
|
|
524
|
use XRI; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use XRI::Descriptor; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '1.11'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
### constructor |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
23
|
|
|
|
|
|
|
bless {}, shift; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
### methods |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub resolveBroker { |
29
|
|
|
|
|
|
|
my $self = shift; |
30
|
|
|
|
|
|
|
my $iname = shift; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $xri = XRI->new($iname); |
33
|
|
|
|
|
|
|
my $xml; |
34
|
|
|
|
|
|
|
eval { |
35
|
|
|
|
|
|
|
$xml = $xri->resolveToAuthorityXML; |
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
if ($@ || !$xml) { |
38
|
|
|
|
|
|
|
return 0; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
else { |
41
|
|
|
|
|
|
|
my $xriDescriptor = XRI::Descriptor->new($xml); |
42
|
|
|
|
|
|
|
my @localAccess = $xriDescriptor->getLocalAccess; |
43
|
|
|
|
|
|
|
my $idBroker = ${$localAccess[0]->uris}[0]; |
44
|
|
|
|
|
|
|
my $inumber = $xriDescriptor->getMappings->[0]; |
45
|
|
|
|
|
|
|
return $idBroker, $inumber; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub getAuthUrl { |
50
|
|
|
|
|
|
|
my $self = shift; |
51
|
|
|
|
|
|
|
my ($idBroker, $iname, $returnUrl) = @_; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# FIXME: Use inumber instead? |
54
|
|
|
|
|
|
|
return "$idBroker?xri_cmd=auth&xri_iname=" . uri_escape($iname) . |
55
|
|
|
|
|
|
|
'&xri_rtn=' . uri_escape($returnUrl); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub validateSession { |
59
|
|
|
|
|
|
|
my $self = shift; |
60
|
|
|
|
|
|
|
my ($idBroker, $iname, $xsid) = @_; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
return &_xriCmd($idBroker, $iname, $xsid, "verify"); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub logout { |
66
|
|
|
|
|
|
|
my $self = shift; |
67
|
|
|
|
|
|
|
my ($idBroker, $iname, $xsid) = @_; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
return &_xriCmd($idBroker, $iname, $xsid, "logout"); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
### private methods |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _xriCmd { |
75
|
|
|
|
|
|
|
my ($idBroker, $iname, $xsid, $cmd) = @_; |
76
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
77
|
|
|
|
|
|
|
$ua->agent("Identity Commons SPIT/$VERSION"); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $request = HTTP::Request->new(GET=>"$idBroker?xri_cmd=$cmd&xri_iname=" |
80
|
|
|
|
|
|
|
. uri_escape($iname) . |
81
|
|
|
|
|
|
|
'&xri_xsid=' . uri_escape($xsid)); |
82
|
|
|
|
|
|
|
my $response = $ua->request($request); |
83
|
|
|
|
|
|
|
if ($response->is_success) { |
84
|
|
|
|
|
|
|
($response->content =~ /true/) ? return 1 : return 0; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
else { # FIXME: should parse status code |
87
|
|
|
|
|
|
|
return 0; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
__END__ |