shibboleth-rails 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -15,14 +15,18 @@ module Shibboleth::Rails
|
|
15
15
|
def current_user
|
16
16
|
return @current_user if defined?(@current_user)
|
17
17
|
@current_user = if session[:simulate_id].present?
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
User.find(session[:simulate_id])
|
19
|
+
elsif authenticated?
|
20
|
+
User.find_or_create_from_shibboleth(shibboleth)
|
21
|
+
end
|
22
22
|
end
|
23
23
|
|
24
24
|
def require_shibboleth
|
25
|
-
|
25
|
+
if current_user
|
26
|
+
current_user.update_usage_stats(request, :login => session['new'])
|
27
|
+
session.delete('new')
|
28
|
+
else
|
29
|
+
session['new'] = true
|
26
30
|
if Rails.env.production?
|
27
31
|
base = request.protocol + request.host
|
28
32
|
requested_url = base + request.request_uri
|
@@ -1,15 +1,48 @@
|
|
1
1
|
module Shibboleth::Rails
|
2
2
|
|
3
3
|
module ModelAdditions
|
4
|
-
def
|
5
|
-
|
4
|
+
def authenticated_by_shibboleth
|
5
|
+
extend ClassMethods
|
6
|
+
include InstanceMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def find_or_create_from_shibboleth(identity)
|
11
|
+
user = find_or_create_by_emplid(identity)
|
6
12
|
|
7
|
-
|
8
|
-
|
9
|
-
|
13
|
+
# names change due to marriage, etc.
|
14
|
+
# update_attribute is a NOOP if not different
|
15
|
+
user.update_attribute(:name_n, identity[:name_n])
|
10
16
|
|
11
|
-
|
17
|
+
user
|
18
|
+
end
|
12
19
|
end
|
13
|
-
end
|
14
20
|
|
21
|
+
module InstanceMethods
|
22
|
+
def update_usage_stats(request, args = {})
|
23
|
+
if args[:login]
|
24
|
+
if self.respond_to?(:login_count)
|
25
|
+
self.login_count ||= 0
|
26
|
+
self.login_count += 1
|
27
|
+
end
|
28
|
+
|
29
|
+
if self.respond_to?(:current_login_at)
|
30
|
+
self.last_login_at = self.current_login_at if self.respond_to?(:last_login_at)
|
31
|
+
self.current_login_at = Time.now
|
32
|
+
end
|
33
|
+
|
34
|
+
if self.respond_to?(:current_login_ip)
|
35
|
+
self.last_login_ip = self.current_login_ip if self.respond_to?(:last_login_ip)
|
36
|
+
self.current_login_ip = request.remote_ip
|
37
|
+
end
|
38
|
+
end
|
39
|
+
self.last_request_at = Time.now if self.respond_to?(:last_request_at)
|
40
|
+
|
41
|
+
save
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
15
46
|
end
|
47
|
+
|
48
|
+
::ActiveRecord::Base.send :extend, Shibboleth::Rails::ModelAdditions
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shibboleth-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- mikegee
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-08-
|
18
|
+
date: 2011-08-29 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rails
|