anoubis 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +38 -0
- data/app/controllers/anoubis/application_controller.rb +78 -0
- data/app/controllers/anoubis/core/application_controller.rb +343 -0
- data/app/controllers/anoubis/core/data/actions.rb +962 -0
- data/app/controllers/anoubis/core/data/callbacks.rb +68 -0
- data/app/controllers/anoubis/core/data/convert.rb +407 -0
- data/app/controllers/anoubis/core/data/defaults.rb +217 -0
- data/app/controllers/anoubis/core/data/get.rb +531 -0
- data/app/controllers/anoubis/core/data/load.rb +89 -0
- data/app/controllers/anoubis/core/data/set.rb +49 -0
- data/app/controllers/anoubis/core/data/setup.rb +104 -0
- data/app/controllers/anoubis/core/data_controller.rb +28 -0
- data/app/controllers/anoubis/core/index/actions.rb +53 -0
- data/app/controllers/anoubis/core/index/callbacks.rb +23 -0
- data/app/controllers/anoubis/core/index_controller.rb +36 -0
- data/app/controllers/anoubis/etc/base.rb +52 -0
- data/app/controllers/anoubis/etc/data.rb +89 -0
- data/app/controllers/anoubis/etc/field.rb +468 -0
- data/app/controllers/anoubis/etc/field_options.rb +83 -0
- data/app/controllers/anoubis/etc/field_order.rb +51 -0
- data/app/controllers/anoubis/etc/filter.rb +251 -0
- data/app/controllers/anoubis/etc/menu.rb +101 -0
- data/app/controllers/anoubis/etc/model.rb +67 -0
- data/app/controllers/anoubis/etc/tab_item.rb +91 -0
- data/app/controllers/anoubis/etc.rb +8 -0
- data/app/controllers/anoubis/export.rb +47 -0
- data/app/controllers/anoubis/output/autocomplete.rb +30 -0
- data/app/controllers/anoubis/output/basic.rb +86 -0
- data/app/controllers/anoubis/output/data.rb +101 -0
- data/app/controllers/anoubis/output/delete.rb +41 -0
- data/app/controllers/anoubis/output/edit.rb +55 -0
- data/app/controllers/anoubis/output/frame.rb +227 -0
- data/app/controllers/anoubis/output/login.rb +71 -0
- data/app/controllers/anoubis/output/menu.rb +220 -0
- data/app/controllers/anoubis/output/update.rb +43 -0
- data/app/controllers/anoubis/sso/client/application_controller.rb +139 -0
- data/app/controllers/anoubis/sso/client/data/actions.rb +5 -0
- data/app/controllers/anoubis/sso/client/data/callbacks.rb +5 -0
- data/app/controllers/anoubis/sso/client/data/convert.rb +5 -0
- data/app/controllers/anoubis/sso/client/data/defaults.rb +5 -0
- data/app/controllers/anoubis/sso/client/data/get.rb +5 -0
- data/app/controllers/anoubis/sso/client/data/load.rb +26 -0
- data/app/controllers/anoubis/sso/client/data/set.rb +5 -0
- data/app/controllers/anoubis/sso/client/data/setup.rb +5 -0
- data/app/controllers/anoubis/sso/client/data_controller.rb +21 -0
- data/app/controllers/anoubis/sso/client/index/actions.rb +79 -0
- data/app/controllers/anoubis/sso/client/index/callbacks.rb +13 -0
- data/app/controllers/anoubis/sso/client/index_controller.rb +18 -0
- data/app/controllers/anoubis/sso/server/application_controller.rb +49 -0
- data/app/controllers/anoubis/sso/server/login_controller.rb +342 -0
- data/app/controllers/anoubis/sso/server/user_controller.rb +142 -0
- data/app/controllers/anoubis/tenant/application_controller.rb +54 -0
- data/app/controllers/anoubis/tenant/data/actions.rb +11 -0
- data/app/controllers/anoubis/tenant/data/callbacks.rb +11 -0
- data/app/controllers/anoubis/tenant/data/convert.rb +11 -0
- data/app/controllers/anoubis/tenant/data/defaults.rb +11 -0
- data/app/controllers/anoubis/tenant/data/get.rb +11 -0
- data/app/controllers/anoubis/tenant/data/load.rb +52 -0
- data/app/controllers/anoubis/tenant/data/set.rb +11 -0
- data/app/controllers/anoubis/tenant/data/setup.rb +11 -0
- data/app/controllers/anoubis/tenant/data_controller.rb +28 -0
- data/app/controllers/anoubis/tenant/index/actions.rb +191 -0
- data/app/controllers/anoubis/tenant/index/callbacks.rb +11 -0
- data/app/controllers/anoubis/tenant/index_controller.rb +38 -0
- data/app/controllers/anoubis/tenants_controller.rb +7 -0
- data/app/controllers/anoubis/users_controller.rb +7 -0
- data/app/jobs/anoubis/application_job.rb +6 -0
- data/app/mailers/anoubis/application_mailer.rb +8 -0
- data/app/models/anoubis/application_record.rb +45 -0
- data/app/models/anoubis/core/application_record.rb +250 -0
- data/app/models/anoubis/core/locales.rb +27 -0
- data/app/models/anoubis/sso/client/application_record.rb +3 -0
- data/app/models/anoubis/sso/client/group.rb +19 -0
- data/app/models/anoubis/sso/client/group_menu.rb +109 -0
- data/app/models/anoubis/sso/client/menu.rb +145 -0
- data/app/models/anoubis/sso/client/user.rb +81 -0
- data/app/models/anoubis/sso/client/user_group.rb +32 -0
- data/app/models/anoubis/sso/server/system.rb +36 -0
- data/app/models/anoubis/sso/server/user.rb +79 -0
- data/app/models/anoubis/tenant/application_record.rb +41 -0
- data/app/models/anoubis/tenant/group.rb +95 -0
- data/app/models/anoubis/tenant/group_locale.rb +19 -0
- data/app/models/anoubis/tenant/group_menu.rb +84 -0
- data/app/models/anoubis/tenant/menu.rb +156 -0
- data/app/models/anoubis/tenant/menu_locale.rb +27 -0
- data/app/models/anoubis/tenant/system.rb +127 -0
- data/app/models/anoubis/tenant/system_locale.rb +19 -0
- data/app/models/anoubis/tenant/system_menu.rb +51 -0
- data/app/models/anoubis/tenant/tenant.rb +107 -0
- data/app/models/anoubis/tenant/tenant_system.rb +19 -0
- data/app/models/anoubis/tenant/user.rb +225 -0
- data/app/models/anoubis/tenant/user_group.rb +32 -0
- data/app/services/anoubis/core_service.rb +16 -0
- data/app/services/anoubis/session_service.rb +17 -0
- data/app/validators/presence_in_tenant_validator.rb +20 -0
- data/config/initializers/mime_type.rb +1 -0
- data/config/locales/en.yml +120 -0
- data/config/locales/ru.yml +245 -0
- data/config/routes.rb +74 -0
- data/db/migrate/20181018085843_create_tenants.rb +13 -0
- data/db/migrate/20181018111217_create_systems.rb +10 -0
- data/db/migrate/20181018111713_create_tenant_systems.rb +11 -0
- data/db/migrate/20181018111925_create_groups.rb +13 -0
- data/db/migrate/20181018112151_create_users.rb +25 -0
- data/db/migrate/20181018115737_add_title_to_users.rb +10 -0
- data/db/migrate/20181022060211_create_menus.rb +18 -0
- data/db/migrate/20181115055245_create_group_menus.rb +12 -0
- data/db/migrate/20181115060830_create_system_menus.rb +11 -0
- data/db/migrate/20181122062131_create_user_groups.rb +11 -0
- data/db/migrate/20181221060727_create_menu_locales.rb +14 -0
- data/db/migrate/20181225062303_create_system_locales.rb +11 -0
- data/db/migrate/20181225062339_create_group_locales.rb +11 -0
- data/db/seeds.rb +268 -0
- data/lib/anoubis/engine.rb +13 -0
- data/lib/anoubis/version.rb +5 -0
- data/lib/anoubis.rb +213 -0
- data/lib/tasks/anubis_tasks.rake +10 -0
- data/lib/tasks/sessions/clear_sessions.rake +10 -0
- data/spec/anubis_spec.rb +5 -0
- data/spec/controllers/anoubis/index_controller_spec.rb +77 -0
- data/spec/dummy/Rakefile +3 -0
- data/spec/dummy/app/assets/config/manifest.js +2 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/jobs/application_job.rb +2 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +33 -0
- data/spec/dummy/bin/update +28 -0
- data/spec/dummy/config/application.rb +14 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/cable.yml +10 -0
- data/spec/dummy/config/database.yml +54 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +54 -0
- data/spec/dummy/config/environments/production.rb +85 -0
- data/spec/dummy/config/environments/test.rb +46 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cors.rb +16 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +33 -0
- data/spec/dummy/config/puma.rb +34 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config/spring.rb +6 -0
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/config.ru +5 -0
- data/spec/dummy/db/schema.rb +167 -0
- data/spec/dummy/db/seeds.rb +1 -0
- data/spec/factories/anubis_group_locales.rb +7 -0
- data/spec/factories/anubis_group_menus.rb +7 -0
- data/spec/factories/anubis_groups.rb +6 -0
- data/spec/factories/anubis_menu_locales.rb +9 -0
- data/spec/factories/anubis_menus.rb +6 -0
- data/spec/factories/anubis_system_locales.rb +7 -0
- data/spec/factories/anubis_system_menus.rb +6 -0
- data/spec/factories/anubis_systems.rb +5 -0
- data/spec/factories/anubis_tenants.rb +7 -0
- data/spec/factories/anubis_users.rb +10 -0
- data/spec/integration/navigation_test.rb +7 -0
- data/spec/models/anoubis/group_locale_spec.rb +25 -0
- data/spec/models/anoubis/group_menu_spec.rb +50 -0
- data/spec/models/anoubis/group_spec.rb +52 -0
- data/spec/models/anoubis/menu_locale_spec.rb +31 -0
- data/spec/models/anoubis/menu_spec.rb +48 -0
- data/spec/models/anoubis/system_locale_spec.rb +20 -0
- data/spec/models/anoubis/system_menu_spec.rb +49 -0
- data/spec/models/anoubis/system_spec.rb +53 -0
- data/spec/models/anoubis/tenant_spec.rb +67 -0
- data/spec/models/anoubis/user_spec.rb +57 -0
- data/spec/rails_helper.rb +32 -0
- data/spec/requests/anoubis/users_request_spec.rb +5 -0
- data/spec/spec_helper.rb +13 -0
- metadata +408 -0
@@ -0,0 +1,220 @@
|
|
1
|
+
module Anubis
|
2
|
+
module Output
|
3
|
+
##
|
4
|
+
# Output subclass that represents data for menu action
|
5
|
+
class Menu < Basic
|
6
|
+
# @!attribute [rw] items
|
7
|
+
# @return [Array] the array of menu elements {Anubis::Output::MenuItem}.
|
8
|
+
class_attribute :items
|
9
|
+
|
10
|
+
# @!attribute [rw] keys
|
11
|
+
# @return [Hash] the hash of menu elements {Anubis::Output::MenuItem} with 'mode' as a key.
|
12
|
+
class_attribute :keys
|
13
|
+
|
14
|
+
# @!attribute [rw] user
|
15
|
+
# @return [Hash] the hash of user information.
|
16
|
+
class_attribute :user
|
17
|
+
|
18
|
+
##
|
19
|
+
# Initializes menu output data. Generates default values.
|
20
|
+
def initialize
|
21
|
+
super
|
22
|
+
self.items = []
|
23
|
+
self.keys = {}
|
24
|
+
self.user = {}
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Adds new element into menu hash
|
29
|
+
# @param [Hash] options the menu element options
|
30
|
+
# @option options [String] :title The title of the menu element.
|
31
|
+
# @option options [String] :page_title The page title of the menu element.
|
32
|
+
# @option options [String] :short_title The short title of the menu element.
|
33
|
+
# @option options [String] :mode The mode of the menu element.
|
34
|
+
# @option options [String] :action The action type of the menu element ('menu', 'data').
|
35
|
+
# @option options [Number] :position The position of the menu element in current level.
|
36
|
+
# @option options [Number] :tab The level of the menu element.
|
37
|
+
# @option options [String] :state The show state of the menu element ('visible', 'hidden').
|
38
|
+
# @option options [String] :access The access to the menu element for current user ('read', 'write').
|
39
|
+
def addElement(options)
|
40
|
+
if options.has_key? :parent
|
41
|
+
if !self.keys.has_key? options[:parent].to_s.to_sym
|
42
|
+
options[:parent] = nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
menu = MenuItem.new options
|
46
|
+
self.items.push menu
|
47
|
+
self.keys[menu.mode.to_s.to_sym] = self.items[self.items.count-1]
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# Generates hash representation of output class
|
52
|
+
# @return [Hash] hash representation of all data
|
53
|
+
def to_h
|
54
|
+
result = super.to_h
|
55
|
+
return result if self.result != 0
|
56
|
+
result[:menu] = []
|
57
|
+
self.items.each { |item|
|
58
|
+
result[:menu].push(item.to_h) if item
|
59
|
+
}
|
60
|
+
result[:user] = self.user
|
61
|
+
result
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# Generates output message based on {#result self.result} variable.
|
66
|
+
# @return [String] output message
|
67
|
+
def message
|
68
|
+
case self.result
|
69
|
+
when 0
|
70
|
+
return I18n.t('success')
|
71
|
+
else
|
72
|
+
return I18n.t('invalid_menu_output')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
##
|
77
|
+
# Returns menu element
|
78
|
+
# @param mode [String] the mode of returned menu element
|
79
|
+
# @return [MenuItem | nil] menu element or nil if element isn't exists
|
80
|
+
def key(mode)
|
81
|
+
if self.keys.has_key? mode.to_s.to_sym
|
82
|
+
|
83
|
+
return self.keys[mode.to_s.to_sym]
|
84
|
+
else
|
85
|
+
return nil
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
##
|
91
|
+
# Subclass of menu element.
|
92
|
+
class MenuItem
|
93
|
+
# @!attribute [rw] mode
|
94
|
+
# @return [String] the mode of the menu element. Identificator represents path of controller.
|
95
|
+
class_attribute :mode
|
96
|
+
|
97
|
+
# @!attribute [rw] title
|
98
|
+
# @return [String] the title of the menu element.
|
99
|
+
class_attribute :title
|
100
|
+
|
101
|
+
# @!attribute [rw] page_title
|
102
|
+
# @return [String] the page title of the menu element. Uses for show in page title.
|
103
|
+
class_attribute :page_title
|
104
|
+
|
105
|
+
# @!attribute [rw] short_title
|
106
|
+
# @return [String] the short title of the menu element. Uses for short menu link.
|
107
|
+
class_attribute :short_title
|
108
|
+
|
109
|
+
# @!attribute [rw] position
|
110
|
+
# @return [Number] the position of the menu element in current level.
|
111
|
+
class_attribute :position
|
112
|
+
|
113
|
+
# @!attribute [rw] tab
|
114
|
+
# @return [Number] the level of the menu element.
|
115
|
+
class_attribute :tab
|
116
|
+
|
117
|
+
# @!attribute [rw] action
|
118
|
+
# @return [String] the action type of the menu element ('menu', 'data').
|
119
|
+
class_attribute :action
|
120
|
+
|
121
|
+
# @!attribute [rw] access
|
122
|
+
# @return [String] the access to the menu element for current user ('read', 'write').
|
123
|
+
class_attribute :access
|
124
|
+
|
125
|
+
# @!attribute [rw] state
|
126
|
+
# @return [String] the show state of the menu element ('visible', 'hidden').
|
127
|
+
class_attribute :state
|
128
|
+
|
129
|
+
# @!attribute [rw] parent
|
130
|
+
# @return [String] the mode of parent menu of the menu element when tab more then 0.
|
131
|
+
class_attribute :parent
|
132
|
+
|
133
|
+
##
|
134
|
+
# Initializes menu element data. Generates default values.
|
135
|
+
def initialize(options = {})
|
136
|
+
if options.has_key? :mode
|
137
|
+
self.mode = options[:mode]
|
138
|
+
else
|
139
|
+
self.mode = ''
|
140
|
+
end
|
141
|
+
|
142
|
+
if options.has_key? :title
|
143
|
+
self.title = options[:title]
|
144
|
+
else
|
145
|
+
self.title = ''
|
146
|
+
end
|
147
|
+
|
148
|
+
if options.has_key? :page_title
|
149
|
+
self.page_title = options[:page_title]
|
150
|
+
else
|
151
|
+
self.page_title = ''
|
152
|
+
end
|
153
|
+
|
154
|
+
if options.has_key? :short_title
|
155
|
+
self.short_title = options[:short_title]
|
156
|
+
else
|
157
|
+
self.short_title = ''
|
158
|
+
end
|
159
|
+
|
160
|
+
if options.has_key? :position
|
161
|
+
self.position = options[:position]
|
162
|
+
else
|
163
|
+
self.position = 0
|
164
|
+
end
|
165
|
+
|
166
|
+
if options.has_key? :tab
|
167
|
+
self.tab = options[:tab]
|
168
|
+
else
|
169
|
+
self.tab = 0
|
170
|
+
end
|
171
|
+
|
172
|
+
if options.has_key? :action
|
173
|
+
self.action = options[:action]
|
174
|
+
else
|
175
|
+
self.action = 'data'
|
176
|
+
end
|
177
|
+
|
178
|
+
if options.has_key? :access
|
179
|
+
self.access = options[:access]
|
180
|
+
else
|
181
|
+
self.access = 'read'
|
182
|
+
end
|
183
|
+
|
184
|
+
if options.has_key? :state
|
185
|
+
self.state = options[:state]
|
186
|
+
else
|
187
|
+
self.state = 'visible'
|
188
|
+
end
|
189
|
+
|
190
|
+
if options.has_key? :parent
|
191
|
+
if options[:parent]
|
192
|
+
self.parent = options[:parent]
|
193
|
+
else
|
194
|
+
self.parent = ''
|
195
|
+
end
|
196
|
+
else
|
197
|
+
self.parent = ''
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
##
|
202
|
+
# Generates hash representation of output class
|
203
|
+
# @return [Hash] hash representation of all data
|
204
|
+
def to_h
|
205
|
+
{
|
206
|
+
mode: self.mode,
|
207
|
+
title: self.title,
|
208
|
+
page_title: self.page_title,
|
209
|
+
short_title: self.short_title,
|
210
|
+
position: self.position,
|
211
|
+
tab: self.tab,
|
212
|
+
action: self.action,
|
213
|
+
access: self.access,
|
214
|
+
state:self.state,
|
215
|
+
parent: self.parent
|
216
|
+
}
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Anubis
|
2
|
+
module Output
|
3
|
+
##
|
4
|
+
# Output subclass that represents data for update or create action
|
5
|
+
class Update < Basic
|
6
|
+
# @!attribute [rw]
|
7
|
+
# @return [Hash] the hash of defined fields.
|
8
|
+
class_attribute :values, default: {}
|
9
|
+
|
10
|
+
# @!attribute [rw]
|
11
|
+
# @return [Array<String>] hash of errors
|
12
|
+
class_attribute :errors, default: []
|
13
|
+
|
14
|
+
# @!attribute [rw]
|
15
|
+
# @return [String] resulting post action
|
16
|
+
class_attribute :action, default: ''
|
17
|
+
|
18
|
+
##
|
19
|
+
# Initializes menu output data. Generates default values.
|
20
|
+
def initialize
|
21
|
+
super
|
22
|
+
self.values = {}
|
23
|
+
self.errors = []
|
24
|
+
self.action = ''
|
25
|
+
self.messages[:'-3'] = I18n.t('errors.update_error')
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
# Generates hash representation of output class
|
30
|
+
# @return [Hash] hash representation of all data
|
31
|
+
def to_h
|
32
|
+
result = super.to_h
|
33
|
+
result[:errors] = self.errors if self.errors.length > 0
|
34
|
+
return result if self.result != 0
|
35
|
+
result.merge!({
|
36
|
+
values: self.values,
|
37
|
+
action: self.action
|
38
|
+
})
|
39
|
+
result
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
class Anubis::Sso::Client::ApplicationController < Anubis::Core::ApplicationController
|
2
|
+
|
3
|
+
def sso_server
|
4
|
+
Rails.configuration.sso_server
|
5
|
+
end
|
6
|
+
|
7
|
+
def sso_system_uuid
|
8
|
+
Rails.configuration.sso_system_uuid
|
9
|
+
end
|
10
|
+
|
11
|
+
def sso_system_secret
|
12
|
+
Rails.configuration.sso_system_secret
|
13
|
+
end
|
14
|
+
|
15
|
+
def user_model
|
16
|
+
begin
|
17
|
+
model = Rails.configuration.user_model.classify.constantize
|
18
|
+
rescue
|
19
|
+
model = Anubis::Sso::Server::User
|
20
|
+
end
|
21
|
+
|
22
|
+
model
|
23
|
+
end
|
24
|
+
|
25
|
+
def authentication
|
26
|
+
if !self.token
|
27
|
+
self.error_exit({ error: I18n.t('errors.authentication_required') })
|
28
|
+
return false
|
29
|
+
end
|
30
|
+
|
31
|
+
session = self.redis.get(self.redis_prefix + 'session:' + self.token)
|
32
|
+
|
33
|
+
if !session
|
34
|
+
session = self.get_session_from_sso_server self.token
|
35
|
+
else
|
36
|
+
session = JSON.parse(session,{ symbolize_names: true })
|
37
|
+
end
|
38
|
+
|
39
|
+
if !session
|
40
|
+
self.error_exit({ error: I18n.t('errors.authentication_required') })
|
41
|
+
return false
|
42
|
+
end
|
43
|
+
|
44
|
+
if session[:update].to_datetime + 300.seconds < Time.now
|
45
|
+
session = self.get_session_from_sso_server self.token
|
46
|
+
end
|
47
|
+
|
48
|
+
if !session
|
49
|
+
self.redis.del self.redis_prefix + 'session:' + self.token
|
50
|
+
self.error_exit({ error: I18n.t('errors.authentication_required') })
|
51
|
+
return false
|
52
|
+
end
|
53
|
+
|
54
|
+
if session[:time].to_datetime + session[:timeout].to_f / 86400 < Time.now
|
55
|
+
self.redis.del self.redis_prefix + 'session:' + self.token
|
56
|
+
self.error_exit({ error: I18n.t('errors.authentication_required') })
|
57
|
+
return false
|
58
|
+
end
|
59
|
+
|
60
|
+
session[:time] = Time.now
|
61
|
+
|
62
|
+
self.redis.set(self.redis_prefix + 'session:' + self.token, session.to_json, ex: session[:timeout])
|
63
|
+
|
64
|
+
begin
|
65
|
+
self.current_user = self.user_model.new(self.user_model.load_cache(self.redis, session[:uuid]))
|
66
|
+
rescue
|
67
|
+
self.current_user = nil
|
68
|
+
end
|
69
|
+
|
70
|
+
true
|
71
|
+
end
|
72
|
+
|
73
|
+
def get_session_from_sso_server(session)
|
74
|
+
#require 'rest-client'
|
75
|
+
|
76
|
+
#session = 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 })
|
77
|
+
begin
|
78
|
+
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 })
|
79
|
+
rescue
|
80
|
+
return nil
|
81
|
+
end
|
82
|
+
|
83
|
+
return nil if ses_data[:result] != 0
|
84
|
+
|
85
|
+
|
86
|
+
user_data = self.get_user_data_by_uuid ses_data[:uuid], ses_data, true
|
87
|
+
|
88
|
+
|
89
|
+
return {
|
90
|
+
uuid: user_data.uuid,
|
91
|
+
login: ses_data[:login_time],
|
92
|
+
time: Time.now,
|
93
|
+
timeout: user_data.timeout,
|
94
|
+
update: Time.now
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
##
|
99
|
+
# Returns user data by UUI
|
100
|
+
def get_user_data_by_uuid(uuid, sso_data = nil, force = false)
|
101
|
+
unless force
|
102
|
+
begin
|
103
|
+
user_data = self.user_model.new(JSON.parse(self.redis.get(self.redis_prefix + 'user:' + uuid), { symbolize_names: true }))
|
104
|
+
rescue
|
105
|
+
user_data = nil
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
unless user_data
|
110
|
+
user_data = self.user_model.find_or_create_by(uuid: uuid)
|
111
|
+
|
112
|
+
user_data.save_cache(sso_data) if user_data
|
113
|
+
end
|
114
|
+
|
115
|
+
user_data
|
116
|
+
end
|
117
|
+
|
118
|
+
##
|
119
|
+
# Return access status for current user
|
120
|
+
def menu_access(controller, exit = true)
|
121
|
+
menu_access_status = 'not'
|
122
|
+
|
123
|
+
if self.current_user
|
124
|
+
if self.current_user.menus
|
125
|
+
if self.current_user.menus.key? controller.to_s.to_sym
|
126
|
+
menu_access_status = self.current_user.menus[controller.to_s.to_sym]
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
if menu_access_status == 'not'
|
132
|
+
self.error_exit({ error: I18n.t('errors.access_not_allowed') }) if exit
|
133
|
+
return false
|
134
|
+
end
|
135
|
+
|
136
|
+
self.writer = true if menu_access_status == 'write'
|
137
|
+
true
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
##
|
2
|
+
# Module loads data from external sources for {Anubis::Sso::Client::DataController}
|
3
|
+
module Anubis::Sso::Client::Data::Load
|
4
|
+
include Anubis::Core::Data::Load
|
5
|
+
|
6
|
+
def load_menu_data
|
7
|
+
menu_json = self.redis.get(self.redis_prefix + 'menu:' + params[:controller])
|
8
|
+
|
9
|
+
unless menu_json
|
10
|
+
menu = Anubis::Sso::Client::Menu.where(mode: params[:controller], status: 'enabled').first
|
11
|
+
self.redis.set(self.redis_prefix + 'menu:'+ params[:controller], menu.to_json) if menu
|
12
|
+
else
|
13
|
+
menu = Anubis::Sso::Client::Menu.new(JSON.parse(menu_json, { :symbolize_names => true }))
|
14
|
+
end
|
15
|
+
|
16
|
+
if menu
|
17
|
+
self.etc.menu = Anubis::Etc::Menu.new menu
|
18
|
+
|
19
|
+
if self.writer
|
20
|
+
self.etc.menu.access = 'write'
|
21
|
+
else
|
22
|
+
self.etc.menu.access = 'read'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_dependency "anubis/sso/client/application_controller"
|
2
|
+
require_dependency "anubis/sso/client/data/actions"
|
3
|
+
require_dependency "anubis/sso/client/data/load"
|
4
|
+
require_dependency "anubis/sso/client/data/get"
|
5
|
+
require_dependency "anubis/sso/client/data/set"
|
6
|
+
require_dependency "anubis/sso/client/data/setup"
|
7
|
+
require_dependency "anubis/sso/client/data/defaults"
|
8
|
+
require_dependency "anubis/sso/client/data/convert"
|
9
|
+
require_dependency "anubis/sso/client/data/callbacks"
|
10
|
+
|
11
|
+
# Controller consists all procedures and function for presents and modify models data.
|
12
|
+
class Anubis::Sso::Client::DataController < Anubis::Sso::Client::ApplicationController
|
13
|
+
include Anubis::Sso::Client::Data::Actions
|
14
|
+
include Anubis::Sso::Client::Data::Load
|
15
|
+
include Anubis::Sso::Client::Data::Get
|
16
|
+
include Anubis::Sso::Client::Data::Set
|
17
|
+
include Anubis::Sso::Client::Data::Setup
|
18
|
+
include Anubis::Sso::Client::Data::Defaults
|
19
|
+
include Anubis::Sso::Client::Data::Convert
|
20
|
+
include Anubis::Sso::Client::Data::Callbacks
|
21
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Anubis::Sso::Client::Index::Actions
|
2
|
+
def menu
|
3
|
+
self.output = Anubis::Output::Menu.new
|
4
|
+
|
5
|
+
if self.current_user
|
6
|
+
self.output.user = {
|
7
|
+
name: self.current_user.name,
|
8
|
+
surname: self.current_user.surname,
|
9
|
+
locale: self.current_user.locale
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
access = Anubis::Sso::Client::GroupMenu.accesses[:read].to_s+','+Anubis::Sso::Client::GroupMenu.accesses[:write].to_s
|
14
|
+
query = <<-SQL
|
15
|
+
SELECT `t`.* FROM
|
16
|
+
(
|
17
|
+
SELECT `t2`.`id`, `t2`.`mode`, `t2`.`action`, `t2`.`title_locale`, `t2`.`page_title_locale`, `t2`.`short_title_locale`,
|
18
|
+
`t2`.`position`, `t2`.`tab`, `t2`.`menu_id`, `t2`.`state`, MAX(`t2`.`access`) AS `access`,
|
19
|
+
`t2`.`user_id`, `t2`.`parent_mode`
|
20
|
+
FROM (
|
21
|
+
SELECT `menus`.`id`, `menus`.`id` AS `menu_id`, `menus`.`mode`, `menus`.`action`, `menus`.`title_locale`, `menus`.`page_title_locale`,
|
22
|
+
`menus`.`short_title_locale`, `menus`.`position`, `menus`.`tab`, `menus`.`menu_id` AS `parent_menu_id`, `menus`.`state`,
|
23
|
+
`group_menus`.`access`, `user_groups`.`user_id`, `parent_menu`.`mode` AS `parent_mode`
|
24
|
+
FROM (`menus`, `group_menus`, `groups`, `user_groups`)
|
25
|
+
LEFT JOIN `menus` AS `parent_menu` ON `menus`.`menu_id` = `parent_menu`.`id`
|
26
|
+
WHERE `menus`.`id` = `group_menus`.`menu_id` AND `menus`.`status` = 0 AND `group_menus`.`group_id` = `groups`.`id` AND
|
27
|
+
`groups`.`id` = `user_groups`.`group_id` AND `user_groups`.`user_id` = #{self.current_user.id}
|
28
|
+
) AS `t2`
|
29
|
+
GROUP BY `t2`.`id`, `t2`.`mode`, `t2`.`action`, `t2`.`title_locale`, `t2`.`page_title_locale`, `t2`.`short_title_locale`,
|
30
|
+
`t2`.`position`, `t2`.`tab`, `t2`.`menu_id`, `t2`.`state`, `t2`.`user_id`, `t2`.`parent_mode`) AS `t`
|
31
|
+
WHERE `t`.access IN (#{access}
|
32
|
+
)
|
33
|
+
ORDER BY `t`.`menu_id`, `t`.`position`
|
34
|
+
SQL
|
35
|
+
Anubis::Sso::Client::GroupMenu.find_by_sql(query).each do |data|
|
36
|
+
self.output.addElement({
|
37
|
+
mode: data.mode,
|
38
|
+
title: data.title,
|
39
|
+
page_title: data.page_title,
|
40
|
+
short_title: data.short_title,
|
41
|
+
position: data.position,
|
42
|
+
tab: data.tab,
|
43
|
+
action: data.action,
|
44
|
+
access: data.access,
|
45
|
+
state: Anubis::Sso::Client::Menu.states.invert[data.state],
|
46
|
+
parent: data.parent_mode
|
47
|
+
})
|
48
|
+
#self.output[:data].push menu_id[data.id.to_s.to_sym]
|
49
|
+
end
|
50
|
+
|
51
|
+
self.before_menu_output
|
52
|
+
|
53
|
+
respond_to do |format|
|
54
|
+
format.json { render json: around_menu_output(self.output.to_h) }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def logout
|
59
|
+
self.output = Anubis::Output::Basic.new
|
60
|
+
self.output.result = 0
|
61
|
+
|
62
|
+
begin
|
63
|
+
RestClient.delete self.sso_server + 'api/1/login/' + self.token + '?sso_system=' + self.sso_system_uuid + '&secret_key=' + self.sso_system_secret
|
64
|
+
result = true
|
65
|
+
rescue
|
66
|
+
result = false
|
67
|
+
end
|
68
|
+
|
69
|
+
if result
|
70
|
+
self.redis.del self.redis_prefix + 'session:' + self.token
|
71
|
+
else
|
72
|
+
self.output.result = -1
|
73
|
+
end
|
74
|
+
|
75
|
+
respond_to do |format|
|
76
|
+
format.json { render json: around_menu_output(self.output.to_h) }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_dependency "anubis/sso/client/index/actions"
|
2
|
+
require_dependency "anubis/sso/client/index/callbacks"
|
3
|
+
|
4
|
+
class Anubis::Sso::Client::IndexController < Anubis::Sso::Client::ApplicationController
|
5
|
+
include Anubis::Sso::Client::Index::Actions
|
6
|
+
include Anubis::Sso::Client::Index::Callbacks
|
7
|
+
|
8
|
+
##
|
9
|
+
# Check if authentication required
|
10
|
+
def check_menu_access?
|
11
|
+
if controller_name == 'index'
|
12
|
+
if action_name == 'login' || action_name == 'menu' || action_name == 'logout'
|
13
|
+
return false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
return true
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class Anubis::Sso::Server::ApplicationController < Anubis::Core::ApplicationController
|
2
|
+
def user_model
|
3
|
+
begin
|
4
|
+
model = Rails.configuration.user_model.classify.constantize
|
5
|
+
rescue
|
6
|
+
model = Anubis::Sso::Server::User
|
7
|
+
end
|
8
|
+
|
9
|
+
model
|
10
|
+
end
|
11
|
+
|
12
|
+
def front_url
|
13
|
+
Rails.configuration.sso_front_url
|
14
|
+
end
|
15
|
+
|
16
|
+
def domain_url
|
17
|
+
Rails.configuration.sso_domain_url
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# Returns user data by UUI
|
22
|
+
def get_user_data_by_uuid(uuid)
|
23
|
+
begin
|
24
|
+
user_data = self.user_model.new(JSON.parse(self.redis.get(self.redis_prefix + 'user:' + uuid), { symbolize_names: true }))
|
25
|
+
rescue
|
26
|
+
user_data = nil
|
27
|
+
end
|
28
|
+
|
29
|
+
unless user_data
|
30
|
+
user_data = self.user_model.where(uuid: uuid, status: 'enabled').first
|
31
|
+
|
32
|
+
user_data.save_cache if user_data
|
33
|
+
end
|
34
|
+
|
35
|
+
user_data
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# Format user information to result hash
|
40
|
+
def format_user_output(user_data, result)
|
41
|
+
result[:uuid] = user_data.uuid
|
42
|
+
result[:name] = user_data.name
|
43
|
+
result[:surname] = user_data.surname
|
44
|
+
result[:login] = user_data.login
|
45
|
+
result[:locale] = user_data.locale
|
46
|
+
result[:timezone] = user_data.timezone
|
47
|
+
result[:timeout] = user_data.timeout
|
48
|
+
end
|
49
|
+
end
|