Permalink
Browse files

Setting a temporary_current_user based on SSL certificates

  • Loading branch information...
1 parent 2cce759 commit 982ec666219b33c8799cfac609f43c8f38aa5a47 @nelhage committed Mar 25, 2007
Showing with 51 additions and 0 deletions.
  1. +38 −0 lib/AuthMitEdu/CurrentUser.pm
  2. +11 −0 lib/AuthMitEdu/Dispatcher.pm
  3. +2 −0 lib/AuthMitEdu/Model/User.pm
View
38 lib/AuthMitEdu/CurrentUser.pm
@@ -0,0 +1,38 @@
+use warnings;
+use strict;
+
+
+package AuthMitEdu::CurrentUser;
+
+use base qw/Jifty::CurrentUser/;
+
+=head2 new PARAMHASH
+
+Instantiate a new current user object, loading the user by paramhash:
+
+ my $item = AuthMitEdu::Model::Item->new( AuthMitEdu::CurrentUser->new(email => 'user@site'));
+
+if you give the param
+ _bootstrap => 1
+
+your object will be marked as a bootstrap user. You can use that to do an endrun around acls.
+
+=cut
+
+
+
+sub _init {
+ my $self = shift;
+ my %args = (@_);
+
+ if (delete $args{'_bootstrap'} ) {
+ $self->is_bootstrap_user(1);
+ } elsif (keys %args) {
+ $self->user_object(AuthMitEdu::Model::User->new(current_user => $self));
+ $self->user_object->load_by_cols(%args);
+ }
+ $self->SUPER::_init(%args);
+}
+
+
+1;
View
11 lib/AuthMitEdu/Dispatcher.pm
@@ -2,6 +2,17 @@ package AuthMitEdu::Dispatcher;
use Jifty::Dispatcher -base;
+before '*' => run {
+ if(!Jifty->web->current_user->id) {
+ my $user = AuthMitEdu::Model::User->remote_user;
+ if($user) {
+ warn "Doing a login";
+ Jifty->web->temporary_current_user(
+ AuthMitEdu::CurrentUser->new(username => $user->username));
+ }
+ }
+};
+
on qr{^/([a-zA-Z][a-zA-Z_0-9]+)$} => run {
set user => $1;
show '/endpoint';
View
2 lib/AuthMitEdu/Model/User.pm
@@ -36,6 +36,8 @@ sub is_trusted {
return 0;
}
+sub name {return shift->username;}
+
sub current_user_can {1};
1;

0 comments on commit 982ec66

Please sign in to comment.