puavo_authentication 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,13 +6,12 @@ module Puavo
6
6
 
7
7
  def self.current_user=(user)
8
8
  Thread.current["current_user"] = user
9
+ # Update owners list
10
+ Thread.current["owners"] = LdapOrganisation.current.owner
9
11
  end
10
12
 
11
13
  def self.organisation_owner?
12
- if Puavo::Authorization.current_user
13
- unless Thread.current["owners"]
14
- Thread.current["owners"] = LdapOrganisation.current.owner
15
- end
14
+ if Puavo::Authorization.current_user && Thread.current["owners"]
16
15
  return Thread.current["owners"].include?(Puavo::Authorization.current_user.dn)
17
16
  end
18
17
  return false
@@ -0,0 +1,97 @@
1
+ module PuavoAuthentication
2
+ module Controllers
3
+ module Helpers
4
+ def current_user
5
+ unless session[:dn].nil?
6
+ unless @current_user.nil?
7
+ return @current_user
8
+ else
9
+ begin
10
+ return @current_user = User.find(session[:dn]) # REST/OAuth?
11
+ rescue
12
+ logger.info "Session's user not found! User is removed from ldap server."
13
+ logger.info "session[:dn]: #{session[:dn]}"
14
+ # Delete ldap connection informations from session.
15
+ session.delete :password_plaintext
16
+ session.delete :dn
17
+ end
18
+ end
19
+ end
20
+ return nil
21
+ end
22
+
23
+ def login_required
24
+ case request.format
25
+ when !current_user && Mime::JSON
26
+ logger.debug "Using HTTP basic authentication"
27
+ password = ""
28
+
29
+ user = authenticate_with_http_basic do |login, password|
30
+ User.authenticate(login, password)
31
+ end
32
+ logger.debug "Basic Auth User: " + user.inspect
33
+ if user
34
+ session[:dn] = user.dn
35
+ session[:password_plaintext] = password
36
+ logger.debug "Logged in with http basic authentication"
37
+ else
38
+ request_http_basic_authentication
39
+ end
40
+ else
41
+ unless current_user
42
+ store_location
43
+ flash[:notice] = t('must_be_logged_in')
44
+ redirect_to login_path
45
+ return false
46
+ end
47
+ end
48
+ end
49
+
50
+ def store_location
51
+ session[:return_to] = request.request_uri
52
+ end
53
+
54
+ def redirect_back_or_default(default)
55
+ redirect_to(session[:return_to] || default)
56
+ session[:return_to] = nil
57
+ end
58
+
59
+ def ldap_setup_connection
60
+ host = ""
61
+ base = ""
62
+ default_ldap_configuration = ActiveLdap::Base.ensure_configuration
63
+ unless session[:organisation].nil?
64
+ host = session[:organisation].ldap_host
65
+ base = session[:organisation].ldap_base
66
+ end
67
+ if session[:dn]
68
+ dn = session[:dn]
69
+ password = session[:password_plaintext]
70
+ else
71
+ dn = default_ldap_configuration["bind_dn"]
72
+ password = default_ldap_configuration["password"]
73
+ end
74
+ logger.debug "Set host, bind_dn, base and password by user:"
75
+ logger.debug "host: #{host}"
76
+ 2 logger.debug "base: #{base}"
77
+ logger.debug "dn: #{session[:dn]}"
78
+ #logger.debug "password: #{session[:password_plaintext]}"
79
+ LdapBase.ldap_setup_connection(host, base, dn, password)
80
+ end
81
+
82
+ def remove_ldap_connection
83
+ ActiveLdap::Base.active_connections.keys.each do |connection_name|
84
+ ActiveLdap::Base.remove_connection(connection_name)
85
+ end
86
+ end
87
+
88
+ def organisation_owner?
89
+ Puavo::Authorization.organisation_owner?
90
+ end
91
+
92
+ def set_authorization_user
93
+ Puavo::Authorization.current_user = current_user if current_user
94
+ end
95
+ end
96
+ end
97
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puavo_authentication
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 10
10
- version: 0.0.10
9
+ - 11
10
+ version: 0.0.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jouni Korhonen
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-04 00:00:00 +02:00
18
+ date: 2011-02-08 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -40,6 +40,7 @@ files:
40
40
  - lib/puavo/authorization.rb
41
41
  - lib/puavo/connection.rb
42
42
  - lib/puavo_authentication.rb
43
+ - lib/puavo_authentication/controllers/#helpers.rb#
43
44
  - lib/puavo_authentication/controllers/helpers.rb
44
45
  - lib/tasks/puavo_ldap_auth.rake
45
46
  - lib/user_error.rb