-
Notifications
You must be signed in to change notification settings - Fork 8
/
AuthCasTest.pl
67 lines (54 loc) · 1.74 KB
/
AuthCasTest.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/perl
#
# Just a script I used when I was testing out CAS... if it helps, by all
# means use it. Set the casUrl below, and then set the service itself
# in place of http://www.foo.com.
#
# To use, call the program and enter a ticket that's valid for $casService
# below:
#
# % ./AuthCasTest.pl
# Login URL: https://localhost:8443/cas/login?TARGET=http://www.foo.com
# Logout URL: https://localhost:8443/cas/logout?service=http://www.foo.com
# AAFSsPYAkNKN6Mb0Q6Li8D8gawrtLIPuEh3v4JWafmP+FPpnAtt5g3jZ <-- YOU ENTER THIS
# Service ticket: AAFSsPYAkNKN6Mb0Q6Li8D8gawrtLIPuEh3v4JWafmP+FPpnAtt5g3jZ
# User authenticated as mazurek
# attr nickname = Drew
# attr name = Drew Mazurek
# attr id = mazurek
#
use strict;
use AuthCASSaml;
my $casUrl = "https://localhost:8443/cas";
my $casService = "http://www.foo.com";
my $cas = new AuthCASSaml(casUrl => $casUrl,
# CAFile => '/home/mazurek/unicon/ku/ssl/server.jks');
saml => 1
);
my $login_url = $cas->getServerLoginURL($casService);
print "Login URL: $login_url\n";
my $logout_url = $cas->getServerLogoutURL($casService);
print "Logout URL: $logout_url\n";
my $ST = <>;
chomp $ST;
print "Service ticket: $ST\n";
if($cas->{saml}) {
my %casResult = $cas->validateST($casService, $ST);
if(!$casResult{user}) {
print "invalid\n";
printf STDERR "Error: %s\n", &AuthCASSaml::get_errors();
} else {
print "User authenticated as $casResult{user}\n";
my $attrs = $casResult{attributes};
if($attrs) {
foreach my $key (keys %$attrs) {
print "attr $key = $attrs->{$key}\n";
}
} else {
print "no attributes\n";
}
}
} else {
my $user = $cas->validateST($casService, $ST);
print "User authenticated as $user\n";
}