1 [[!tag patch wishlist]]
3 ikiwiki should support [Central Authentication
4 Service](http://www.ja-sig.org/products/cas/) authentication in order to use
5 this <acronym title='Single Sign On'>SSO</acronym> mechanism very popular in
6 universities web services.
8 I have already written a first draft plugin supporting that authentication
9 mechanism. It works for me with my university CAS service. I did not try it
10 with other CAS server but it do not see any reason why it should not work.
12 What is the best way to submit it to you (just in case it can help my patch
17 > Inline here is ok; git-am by mail is ok; a git repo I can pull from also
20 > This looks pretty acceptable as-is, but you need to put a copyright and
21 > license statement at the top. I have a few questions that I'll insert
22 > inline with the patch below. --[[Joey]]
24 ------------------------------------------------------------------------------
25 diff --git a/IkiWiki/Plugin/cas.pm b/IkiWiki/Plugin/cas.pm
27 index 0000000..ea189df
29 +++ b/IkiWiki/Plugin/cas.pm
32 +# JaSIG CAS support by Bruno Beaufils <bruno@boulgour.com>
33 +package IkiWiki::Plugin::cas;
38 +use AuthCAS; # http://search.cpan.org/~osalaun/AuthCAS-1.3.1/
40 > In ikiwiki we generally deman-load perl modules only when they're used.
41 > This avoids loading expensive modules when the CGI isn't doing
42 > authentication. Can you do that with AuthCAS? Something like this before
43 > the use of it: `eval q{use AuthCAS}; error $@ if $@`
47 + hook(type => "getopt", id => "cas", call => \&getopt);
48 + hook(type => "auth", id => "cas", call => \&auth);
49 + hook(type => "formbuilder_setup", id => "cas", call => \&formbuilder_setup);
52 > Could you please use tabs for indentation of program flow?
54 +# FIXME: We should check_config to ensure that :
55 +# * cas_url and ca_file are present
59 +# * no other auth plugin are present (at least passwordauth and openid)
61 > Why would you want to make other auth plugins not work? Could a site not
62 > legitimatly chose to use this and another auth method?
65 + eval q{use Getopt::Long};
67 + Getopt::Long::Configure('pass_through');
68 + GetOptions("cas_url=s" => \$config{cas_url});
69 + GetOptions("ca_file=s" => \$config{ca_file});
76 + my $cas = new AuthCAS(casUrl => $config{'cas'}{'cas_url'},
77 + CAFile => $config{'cas'}{'ca_file'});
79 + my $service = $config{'cgiurl'};
80 + my $ticket = $q->param('ticket');
82 + unless (defined($ticket)) {
83 + $service .= "?$ENV{QUERY_STRING}";
84 + my $login_url = $cas->getServerLoginURL($service);
85 + debug("CAS: asking a Service Ticket for service $service");
86 + IkiWiki::redirect($q, $login_url);
89 + $service = $service . "?$ENV{QUERY_STRING}";
90 + $service =~ s/\&ticket=$ticket//;
91 + my $user = $cas->validateST($service, $ticket);
92 + if (defined $user) {
93 + debug("CAS: validating a Service Ticket ($ticket) for service $service");
94 + $session->param(name=>$user);
95 + $session->param(CASservice=>$service);
96 + IkiWiki::cgi_savesession($session);
98 + error("CAS failure: ".&AuthCAS::get_errors());
103 +# I use formbuilder_setup and not formbuilder type in order to bypass the
104 +# Logout processing done in IkiWiki::CGI::cgi_prefs()
105 +sub formbuilder_setup (@) {
108 + my $form=$params{form};
109 + my $session=$params{session};
110 + my $cgi=$params{cgi};
111 + my $buttons=$params{buttons};
113 + my $cas = new AuthCAS(casUrl => $config{'cas'}{'cas_url'},
114 + CAFile => $config{'cas'}{'ca_file'});
116 + if ($form->title eq "preferences") {
118 + if (! defined $form->field(name => "name")) {
119 + $form->field(name => "CAS ID",
121 + value => $session->param("name"),
124 + fieldset => "login");
127 + # Force a logout if asked
128 + if ($form->submitted && $form->submitted eq 'Logout')
130 + debug("CAS: asking to remove the Ticket Grant Cookie");
131 + IkiWiki::redirect($cgi, $cas->getServerLogoutURL($config{'url'}));
132 + $session->delete();
139 diff --git a/doc/plugins/cas.mdwn b/doc/plugins/cas.mdwn
141 index 0000000..2f2f53e
143 +++ b/doc/plugins/cas.mdwn
145 +[[ template id=plugin name=cas core=0 author="[[bbb]]"]]
148 +This plugin allows users to use authentication offered by a
149 +[JaSIG](http://www.ja-sig.org) [<acronym title='Central Authentication
150 +Service'>CAS</acronym>](http://www.ja-sig.org/products/cas/) server to log
153 +The plugin needs the [[!cpan AuthCAS-1.3.1]] perl module.
155 > Does it really need that specific version? I think you should lose the
159 +This plugin has two mandatory configuration option. You **must** set `--cas_url`
160 +to the url of a server offering CAS 2.0 authentication. You must also set the
161 +`--ca_file` to an absolute path to the file containing CA certificates used by
162 +the server (generally, aka under Debian, fixing that value to
163 +`/etc/ssl/certs/ca-certificates.crt` is sufficient).
165 > It would be good to add commented-out examples of these to
166 > ikiwiki.setup as well.
168 +This plugin is not enabled by default. It can not be used with other
169 +authentication plugin, such as [[passwordauth]] or [[openid]].
171 ------------------------------------------------------------------------------