Class: Anubis::Sso::Client::ApplicationController
- Inherits:
-
Core::ApplicationController
- Object
- Core::ApplicationController
- Anubis::Sso::Client::ApplicationController
show all
- Defined in:
- app/controllers/anoubis/sso/client/application_controller.rb
Instance Method Summary
collapse
Instance Method Details
#authentication ⇒ Object
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
68
69
70
71
|
# File 'app/controllers/anoubis/sso/client/application_controller.rb', line 25
def authentication
if !self.token
self.error_exit({ error: I18n.t('errors.authentication_required') })
return false
end
session = self.redis.get(self.redis_prefix + 'session:' + self.token)
if !session
session = self.get_session_from_sso_server self.token
else
session = JSON.parse(session,{ symbolize_names: true })
end
if !session
self.error_exit({ error: I18n.t('errors.authentication_required') })
return false
end
if session[:update].to_datetime + 300.seconds < Time.now
session = self.get_session_from_sso_server self.token
end
if !session
self.redis.del self.redis_prefix + 'session:' + self.token
self.error_exit({ error: I18n.t('errors.authentication_required') })
return false
end
if session[:time].to_datetime + session[:timeout].to_f / 86400 < Time.now
self.redis.del self.redis_prefix + 'session:' + self.token
self.error_exit({ error: I18n.t('errors.authentication_required') })
return false
end
session[:time] = Time.now
self.redis.set(self.redis_prefix + 'session:' + self.token, session.to_json, ex: session[:timeout])
begin
self.current_user = self.user_model.new(self.user_model.load_cache(self.redis, session[:uuid]))
rescue
self.current_user = nil
end
true
end
|
#get_session_from_sso_server(session) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'app/controllers/anoubis/sso/client/application_controller.rb', line 73
def get_session_from_sso_server(session)
begin
ses_data = JSON.parse(RestClient.get(self.sso_server + 'api/1/login/' + session + '?sso_system=' + self.sso_system_uuid + '&secret_key=' + self.sso_system_secret + '&locale=' + self.locale), { symbolize_names: true })
rescue
return nil
end
return nil if ses_data[:result] != 0
user_data = self.get_user_data_by_uuid ses_data[:uuid], ses_data, true
return {
uuid: user_data.uuid,
login: ses_data[:login_time],
time: Time.now,
timeout: user_data.timeout,
update: Time.now
}
end
|
#get_user_data_by_uuid(uuid, sso_data = nil, force = false) ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'app/controllers/anoubis/sso/client/application_controller.rb', line 100
def get_user_data_by_uuid(uuid, sso_data = nil, force = false)
unless force
begin
user_data = self.user_model.new(JSON.parse(self.redis.get(self.redis_prefix + 'user:' + uuid), { symbolize_names: true }))
rescue
user_data = nil
end
end
unless user_data
user_data = self.user_model.find_or_create_by(uuid: uuid)
user_data.save_cache(sso_data) if user_data
end
user_data
end
|
Return access status for current user
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'app/controllers/anoubis/sso/client/application_controller.rb', line 120
def (controller, exit = true)
= 'not'
if self.current_user
if self.current_user.
if self.current_user..key? controller.to_s.to_sym
= self.current_user.[controller.to_s.to_sym]
end
end
end
if == 'not'
self.error_exit({ error: I18n.t('errors.access_not_allowed') }) if exit
return false
end
self.writer = true if == 'write'
true
end
|
#sso_server ⇒ Object
3
4
5
|
# File 'app/controllers/anoubis/sso/client/application_controller.rb', line 3
def sso_server
Rails.configuration.sso_server
end
|
#sso_system_secret ⇒ Object
11
12
13
|
# File 'app/controllers/anoubis/sso/client/application_controller.rb', line 11
def sso_system_secret
Rails.configuration.sso_system_secret
end
|
#sso_system_uuid ⇒ Object
7
8
9
|
# File 'app/controllers/anoubis/sso/client/application_controller.rb', line 7
def sso_system_uuid
Rails.configuration.sso_system_uuid
end
|
#user_model ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'app/controllers/anoubis/sso/client/application_controller.rb', line 15
def user_model
begin
model = Rails.configuration.user_model.classify.constantize
rescue
model = Anubis::Sso::Server::User
end
model
end
|