ixtlan-user-management 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.md +64 -0
- data/lib/ixtlan/passwords.rb +72 -0
- data/lib/ixtlan/user_management/application_model.rb +30 -0
- data/lib/ixtlan/user_management/application_resource.rb +48 -0
- data/lib/ixtlan/user_management/authentication_model.rb +31 -0
- data/lib/ixtlan/user_management/authenticator.rb +63 -0
- data/lib/ixtlan/user_management/domain_resource.rb +78 -0
- data/lib/ixtlan/user_management/dummy_authentication.rb +70 -0
- data/lib/ixtlan/user_management/group_model.rb +31 -0
- data/lib/ixtlan/user_management/session_cuba.rb +69 -0
- data/lib/ixtlan/user_management/session_manager.rb +70 -0
- data/lib/ixtlan/user_management/session_model.rb +36 -0
- data/lib/ixtlan/user_management/session_plugin.rb +51 -0
- data/lib/ixtlan/user_management/session_serializer.rb +41 -0
- data/lib/ixtlan/user_management/user_model.rb +36 -0
- data/lib/ixtlan/user_management/user_resource.rb +55 -0
- data/lib/ixtlan/user_management/user_serializer.rb +35 -0
- data/lib/ixtlan/user_management.rb +20 -0
- data/lib/ixtlan-user-management.rb +21 -0
- data/lib/ixtlan_user_management.rb +21 -0
- metadata +166 -0
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Kristian Meier
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
ixtlan-remote
|
2
|
+
-------------
|
3
|
+
|
4
|
+
* [![Build Status](https://secure.travis-ci.org/mkristian/ixtlan-remote.png)](http://travis-ci.org/mkristian/ixtlan-remote)
|
5
|
+
* [![Dependency Status](https://gemnasium.com/mkristian/ixtlan-remote.png)](https://gemnasium.com/mkristian/ixtlan-remote)
|
6
|
+
* [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/mkristian/ixtlan-remote)
|
7
|
+
|
8
|
+
the idea is to register the remote rest(ful) servers at one place and then just talk to a rest-manager to make a rest http request.
|
9
|
+
|
10
|
+
for example configure the 'users' server like this
|
11
|
+
|
12
|
+
rest = Ixtlan::Remote::Rest.new
|
13
|
+
rest.server( :users ) do |s|
|
14
|
+
s.url = 'http://example.com/rest'
|
15
|
+
s.add_model( Admin )
|
16
|
+
s.add_model( Account, "path/to/accounts" )
|
17
|
+
s.add_model( Locale )
|
18
|
+
end
|
19
|
+
|
20
|
+
now you can do something like this:
|
21
|
+
|
22
|
+
a = rest.create( Admin.new( :id => 1, :name => 'me and the corner' ) ) # #<Admin @id=1 @name="me and the corner">
|
23
|
+
rest.retrieve( Admin, 1 ) # #<Admin @id=1 @name="me and the corner">
|
24
|
+
a.name = 'me'
|
25
|
+
rest.update( a ) # #<Admin @id=1 @name="me">
|
26
|
+
rest.delete( a )
|
27
|
+
|
28
|
+
or the same with less magic
|
29
|
+
|
30
|
+
a = rest.create( :admins, { :id => 1, :name => 'me and the corner' } # #<Admin @id=1 @name="me and the corner">
|
31
|
+
rest.retrieve( :admins ) # [#<Admin @id=1 @name="me and the corner">]
|
32
|
+
rest.update( :admins, 1, { :id => 1, :name => 'me' } ) # #<Admin @id=1 @name="me">
|
33
|
+
rest.delete( :admins, 1 )
|
34
|
+
|
35
|
+
where the last argument is the payload and the first argument is the model (either Class, String or Symbol). the rest will be joined as "path" and appended to the baseurl of the model.
|
36
|
+
|
37
|
+
the instantiation of the model objects (Admin, Account, etc) works either with passng in the attributes into the constructor (Admin.new( attributes ), etc) or with DataMapper it will try to load the object first from the datastore and then updates its attributes (no save only update on local object).
|
38
|
+
|
39
|
+
sync
|
40
|
+
----
|
41
|
+
|
42
|
+
possible setting: there are loosely coupled miniapps which share data between them but only one miniapp can modify that data. i.e. one app manages users/groups and their authentication, another app allows to translate the i18n of apps and manages the list of allowed locales, etc. so let's say there are user data (a subset of the users-app user) and locale data which are needed in an app then you can sync them lke this:
|
43
|
+
|
44
|
+
sync = Ixtlan::Remote::Sync.new( rest )
|
45
|
+
sync.register( Locale )
|
46
|
+
|
47
|
+
sync.do_it # i.e. "update Locale - total: 1 success: 1 failures: 0"
|
48
|
+
|
49
|
+
that `sync.do_it` can run in a cronjob and your data gets easily syncronized between miniapps. one could call it a master-slave setup for quasi static data. quasi static like users or locales or venue locations or list of countries etc. quasi static since you sync with a cronjob maybe running once a day or maybe each hour. for volatile data you better use the remote server directly, i.e. for authentication.
|
50
|
+
|
51
|
+
Contributing
|
52
|
+
------------
|
53
|
+
|
54
|
+
1. Fork it
|
55
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
56
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
57
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
58
|
+
5. Create new Pull Request
|
59
|
+
|
60
|
+
meta-fu
|
61
|
+
-------
|
62
|
+
|
63
|
+
enjoy :)
|
64
|
+
|
@@ -0,0 +1,72 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2013 Christian Meier
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
require 'yaml'
|
22
|
+
require 'erb'
|
23
|
+
module Ixtlan
|
24
|
+
class HashWithDefault < ::Hash
|
25
|
+
def get( key, default = HashWithDefault.new )
|
26
|
+
self[ key ] || default
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class Passwords
|
31
|
+
|
32
|
+
def self.symbolize_keys(h)
|
33
|
+
result = HashWithDefault.new
|
34
|
+
|
35
|
+
h.each do |k, v|
|
36
|
+
v = ' ' if v.nil?
|
37
|
+
if v.is_a?(Hash)
|
38
|
+
result[k.to_sym] = symbolize_keys(v) unless v.size == 0
|
39
|
+
else
|
40
|
+
result[k.to_sym] = v unless k.to_sym == v.to_sym
|
41
|
+
end
|
42
|
+
end
|
43
|
+
result
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.load( file )
|
47
|
+
rel_file = File.expand_path( file ).sub( /#{File.expand_path '.' }\/?/, '' )
|
48
|
+
if File.exists?( file )
|
49
|
+
warn "[Passwords] Loaded #{rel_file} file"
|
50
|
+
symbolize_keys( YAML::load( ERB.new( IO.read( file ) ).result ) )
|
51
|
+
else
|
52
|
+
warn "[Passwords] No #{rel_file} file to load"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.config( file = 'password.yml' )
|
57
|
+
@config ||= load( file ) || HashWithDefault.new
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.[]( key )
|
61
|
+
@config[ key ]
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.get( key, default = nil )
|
65
|
+
if default
|
66
|
+
@config.get( key, default )
|
67
|
+
else
|
68
|
+
@config.get( key )
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2013 Christian Meier
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
module Ixtlan
|
22
|
+
module UserManagement
|
23
|
+
class Application
|
24
|
+
include Virtus
|
25
|
+
|
26
|
+
attribute :name, String
|
27
|
+
attribute :url, String
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2013 Christian Meier
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
module Ixtlan
|
22
|
+
module UserManagement
|
23
|
+
class Application
|
24
|
+
include DataMapper::Resource
|
25
|
+
|
26
|
+
def self.storage_name(arg)
|
27
|
+
'ixtlan_applications'
|
28
|
+
end
|
29
|
+
|
30
|
+
# key for selectng the IdentityMap should remain this class if
|
31
|
+
# there is no single table inheritance with Discriminator in place
|
32
|
+
# i.e. the subclass used as key for the IdentityMap
|
33
|
+
def self.base_model
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
property :id, Serial, :auto_validation => false
|
38
|
+
|
39
|
+
property :name, String, :required => true, :unique => true, :length => 32
|
40
|
+
property :url, String, :required => true, :format => /^https?\:\/\/[a-z0-9\-\.]+(\.[a-z0-9]+)*(\:[0-9]+)?(\/\S*)?$/, :length => 64, :lazy => true
|
41
|
+
property :updated_at, DateTime, :required => true, :lazy => true
|
42
|
+
|
43
|
+
# do not record timestamps since they are set from outside
|
44
|
+
def set_timestamps_on_save
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2013 Christian Meier
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
require 'virtus'
|
22
|
+
module Ixtlan
|
23
|
+
module UserManagement
|
24
|
+
class Authentication
|
25
|
+
include Virtus
|
26
|
+
|
27
|
+
attribute :login, String
|
28
|
+
attribute :password, String
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2013 Christian Meier
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
require 'ixtlan/user_management/authentication_model'
|
22
|
+
module Ixtlan
|
23
|
+
module UserManagement
|
24
|
+
class Authenticator
|
25
|
+
|
26
|
+
def initialize( restserver )
|
27
|
+
@restserver = restserver
|
28
|
+
end
|
29
|
+
|
30
|
+
def user_new( params )
|
31
|
+
User.new( params )
|
32
|
+
end
|
33
|
+
|
34
|
+
def login( username_or_email, password )
|
35
|
+
user = nil
|
36
|
+
@restserver.create( Authentication.new(:login => username_or_email, :password => password) ) do |json, req|
|
37
|
+
user = user_new( JSON.load( json ) ) unless json.strip == ''
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
user
|
41
|
+
end
|
42
|
+
|
43
|
+
def reset_password( username_or_email )
|
44
|
+
result = nil
|
45
|
+
@restserver.create( Authentication.new( :login => username_or_email ),
|
46
|
+
:reset_password ) do |json, req|
|
47
|
+
result = json unless json.strip == ''
|
48
|
+
#tell restserver to ignore response
|
49
|
+
nil
|
50
|
+
end
|
51
|
+
result
|
52
|
+
end
|
53
|
+
|
54
|
+
def ping( user )
|
55
|
+
# do nothing
|
56
|
+
end
|
57
|
+
|
58
|
+
def logout( user )
|
59
|
+
# do nothing
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2013 Christian Meier
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
module Ixtlan
|
22
|
+
module UserManagement
|
23
|
+
class Domain
|
24
|
+
|
25
|
+
include DataMapper::Resource
|
26
|
+
|
27
|
+
def self.storage_name(arg)
|
28
|
+
'ixtlan_domains'
|
29
|
+
end
|
30
|
+
|
31
|
+
# key for selectng the IdentityMap should remain this class if
|
32
|
+
# there is no single table inheritance with Discriminator in place
|
33
|
+
# i.e. the subclass used as key for the IdentityMap
|
34
|
+
def self.base_model
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
ALL_ID = 1
|
39
|
+
DEFAULT_ID = 2
|
40
|
+
|
41
|
+
ALL_NAME= 'ALL'
|
42
|
+
DEFAULT_NAME = 'DEFAULT'
|
43
|
+
|
44
|
+
def self.ALL
|
45
|
+
first_or_create( :id => ALL_ID, :name => ALL_NAME )
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.DEFAULT
|
49
|
+
first_or_create( :id => DEFAULT_ID, :name => DEFAULT_NAME )
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.almost_all( args = {} )
|
53
|
+
all( { :id.gt => ALL_ID }.merge( args ) )
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.first_or_create( args )
|
57
|
+
first( args ) || create!( args.merge( {:updated_at => DateTime.new( 1 ) } ) )
|
58
|
+
end
|
59
|
+
|
60
|
+
property :id, Serial
|
61
|
+
property :name, String, :unique => true, :format => /ALL|DEFAULT|^[a-z]+$/,:required => true, :length => 32
|
62
|
+
|
63
|
+
timestamps :updated_at
|
64
|
+
|
65
|
+
# do not record timestamps since they are set from outside
|
66
|
+
def set_timestamps_on_save
|
67
|
+
end
|
68
|
+
|
69
|
+
def all?
|
70
|
+
name == ALL_NAME
|
71
|
+
end
|
72
|
+
|
73
|
+
def default?
|
74
|
+
name == DEFAULT_NAME
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2013 Christian Meier
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
module Ixtlan
|
22
|
+
module UserManagement
|
23
|
+
module DummyAuthentication
|
24
|
+
|
25
|
+
def self.need_dummy?( rest, server )
|
26
|
+
url = rest.to_server( server ).url
|
27
|
+
(url =~ /localhost/ || url =~ /127.0.0.1/ || url =~ /::1/) && !(ENV['SSO'] == 'true' || ENV['SSO'] == '')
|
28
|
+
end
|
29
|
+
|
30
|
+
def login(login, password)
|
31
|
+
if ! login.blank? && password.blank?
|
32
|
+
result = setup_user
|
33
|
+
result.login = login.sub( /\[.*/, '' )
|
34
|
+
result.name = result.login.capitalize
|
35
|
+
result.groups = [ setup_group( login ) ]
|
36
|
+
result.applications = [] if result.respond_to? :applications
|
37
|
+
result
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
|
43
|
+
def setup_user
|
44
|
+
if u = user_model.get!(1)
|
45
|
+
result = u
|
46
|
+
else
|
47
|
+
result.id = 1
|
48
|
+
result.updated_at = DateTime.now
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def user_model
|
53
|
+
User
|
54
|
+
end
|
55
|
+
|
56
|
+
def setup_group( login )
|
57
|
+
group_for( Group, login )
|
58
|
+
end
|
59
|
+
|
60
|
+
def group_for( model, login )
|
61
|
+
model.new('name' => login.sub( /\[.*/, '' ) )
|
62
|
+
end
|
63
|
+
|
64
|
+
def split( login )
|
65
|
+
login.sub( /.*\[/ , '' ).sub( /\].*/, '' ).split( /,/ )
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2013 Christian Meier
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
require 'virtus'
|
22
|
+
module Ixtlan
|
23
|
+
module UserManagement
|
24
|
+
class Group
|
25
|
+
include Virtus
|
26
|
+
|
27
|
+
attribute :name, String
|
28
|
+
attribute :associations, Array[Object]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2013 Christian Meier
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
require 'ixtlan/user_management/session_plugin'
|
22
|
+
|
23
|
+
module Ixtlan
|
24
|
+
module UserManagement
|
25
|
+
|
26
|
+
class SessionCuba < CubaAPI
|
27
|
+
|
28
|
+
plugin SessionPlugin
|
29
|
+
|
30
|
+
define do
|
31
|
+
on post, :reset_password do
|
32
|
+
if msg = self.class.authenticator.reset_password( login_and_password[ 0 ] )
|
33
|
+
log msg
|
34
|
+
head 200
|
35
|
+
else
|
36
|
+
log "user/email not found"
|
37
|
+
head 404
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
on post do
|
42
|
+
user = self.class.authenticator.login( *login_and_password )
|
43
|
+
if user
|
44
|
+
current_user( user )
|
45
|
+
# be compliant with rack-protection and rack-csrf
|
46
|
+
csrf = session[ :csrf ] || session[ "csrf.token" ]
|
47
|
+
res[ 'X-CSRF-TOKEN' ] = csrf if csrf
|
48
|
+
write self.class.sessions.create( user )
|
49
|
+
else
|
50
|
+
log "access denied"
|
51
|
+
head 403
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
on get, :ping do
|
56
|
+
self.class.authenticator.ping( current_user )
|
57
|
+
head 200
|
58
|
+
end
|
59
|
+
|
60
|
+
on delete, current_user do
|
61
|
+
self.class.authenticator.logout( current_user )
|
62
|
+
log "logout"
|
63
|
+
reset_current_user
|
64
|
+
head 200
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2013 Christian Meier
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
require 'ixtlan/user_management/user_serializer'
|
22
|
+
require 'ixtlan/user_management/session_model'
|
23
|
+
require 'ixtlan/user_management/session_serializer'
|
24
|
+
|
25
|
+
module Ixtlan
|
26
|
+
module UserManagement
|
27
|
+
class SessionManager
|
28
|
+
|
29
|
+
attr_accessor :idle_session_timeout, :block
|
30
|
+
|
31
|
+
def initialize( &block )
|
32
|
+
@block = block || lambda { [] }
|
33
|
+
end
|
34
|
+
|
35
|
+
def serializer( user )
|
36
|
+
UserSerializer.new( user )
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_session( user )
|
40
|
+
serializer( user ).use( :session ).to_hash
|
41
|
+
end
|
42
|
+
|
43
|
+
if User.respond_to?( :properties )
|
44
|
+
def from_session( data )
|
45
|
+
if data
|
46
|
+
data = data.dup
|
47
|
+
groups = (data.delete( 'groups' ) || []).collect do |g|
|
48
|
+
Group.new( g )
|
49
|
+
end
|
50
|
+
user = User.first( :login => data[ 'login' ] )
|
51
|
+
user.groups = groups
|
52
|
+
user
|
53
|
+
end
|
54
|
+
end
|
55
|
+
else
|
56
|
+
def from_session( data )
|
57
|
+
if data
|
58
|
+
User.new( data )
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def create( user )
|
64
|
+
Session.new( 'user' => user,
|
65
|
+
'permissions' => block.call( user.groups ),
|
66
|
+
'idle_session_timeout' => idle_session_timeout )
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2013 Christian Meier
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
require 'virtus'
|
22
|
+
module Ixtlan
|
23
|
+
module UserManagement
|
24
|
+
class Session
|
25
|
+
include Virtus
|
26
|
+
|
27
|
+
attribute :idle_session_timeout, Integer
|
28
|
+
attribute :user, User
|
29
|
+
attribute :permissions, Array[Object]
|
30
|
+
|
31
|
+
def to_s
|
32
|
+
"Session( #{user.name}<#{user.login}> groups[ #{user.groups.collect { |g| g.name }.join ',' } ] #{idle_session_timeout} )"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2013 Christian Meier
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
require 'ixtlan/user_management/authenticator'
|
22
|
+
|
23
|
+
module Ixtlan
|
24
|
+
module UserManagement
|
25
|
+
module SessionPlugin
|
26
|
+
|
27
|
+
module ClassMethods
|
28
|
+
def authenticator
|
29
|
+
self[ :authenticator ] ||= Authenticator.new( self[ :rest ] )
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def log( msg )
|
34
|
+
if self.respond_to? :audit
|
35
|
+
audit( msg, { :username => login } )
|
36
|
+
else
|
37
|
+
warn( "[#{login}] #{msg}" )
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def login_and_password
|
42
|
+
auth = req[:authentication] || req
|
43
|
+
[ auth[:login] || auth[:email], auth[:password] ]
|
44
|
+
end
|
45
|
+
|
46
|
+
def login
|
47
|
+
login_and_password[ 0 ]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2013 Christian Meier
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
require 'ixtlan/babel/serializer'
|
22
|
+
module Ixtlan
|
23
|
+
module UserManagement
|
24
|
+
class SessionSerializer < Ixtlan::Babel::Serializer
|
25
|
+
|
26
|
+
root 'session'
|
27
|
+
|
28
|
+
add_context(:single,
|
29
|
+
:only => [:idle_session_timeout],
|
30
|
+
:include => {
|
31
|
+
:user => {
|
32
|
+
},
|
33
|
+
:permissions => {
|
34
|
+
:include => [:actions, :associations]
|
35
|
+
}
|
36
|
+
}
|
37
|
+
)
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2013 Christian Meier
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
require 'ixtlan/user_management/group_model'
|
22
|
+
module Ixtlan
|
23
|
+
module UserManagement
|
24
|
+
class User
|
25
|
+
include Virtus
|
26
|
+
|
27
|
+
attribute :login, String
|
28
|
+
attribute :name, String
|
29
|
+
attribute :groups, Array[Group]
|
30
|
+
|
31
|
+
def initialize( params = {} )
|
32
|
+
super params[ 'user' ] || params
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2013 Christian Meier
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
module Ixtlan
|
22
|
+
module UserManagement
|
23
|
+
class User
|
24
|
+
|
25
|
+
include DataMapper::Resource
|
26
|
+
|
27
|
+
def self.storage_name(arg)
|
28
|
+
'ixtlan_users'
|
29
|
+
end
|
30
|
+
|
31
|
+
# key for selectng the IdentityMap should remain this class if
|
32
|
+
# there is no single table inheritance with Discriminator in place
|
33
|
+
# i.e. the subclass used as key for the IdentityMap
|
34
|
+
def self.base_model
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
property :id, Serial, :auto_validation => false
|
39
|
+
|
40
|
+
property :login, String, :required => true, :unique => true, :length => 32
|
41
|
+
property :name, String, :required => true, :length => 128
|
42
|
+
property :updated_at, DateTime, :required => true
|
43
|
+
|
44
|
+
attr_accessor :groups, :applications
|
45
|
+
|
46
|
+
# do not record timestamps since they are set from outside
|
47
|
+
def set_timestamps_on_save
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_s
|
51
|
+
"User( #{name} <#{login}> )"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2013 Christian Meier
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
require 'ixtlan/babel/serializer'
|
22
|
+
module Ixtlan
|
23
|
+
module UserManagement
|
24
|
+
class UserSerializer < Ixtlan::Babel::Serializer
|
25
|
+
|
26
|
+
add_context(:session,
|
27
|
+
:only => [:login, :name],
|
28
|
+
:include=> {
|
29
|
+
:groups => {
|
30
|
+
:only => [:name]
|
31
|
+
}
|
32
|
+
})
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2013 Christian Meier
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2013 Christian Meier
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
require 'ixtlan/user_management'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2013 Christian Meier
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
require 'ixtlan/user_management'
|
metadata
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ixtlan-user-management
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Christian Meier
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
version_requirements: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 10.0.2
|
21
|
+
none: false
|
22
|
+
requirement: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 10.0.2
|
27
|
+
none: false
|
28
|
+
prerelease: false
|
29
|
+
type: :development
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: minitest
|
32
|
+
version_requirements: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - "~>"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 4.3.0
|
37
|
+
none: false
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 4.3.0
|
43
|
+
none: false
|
44
|
+
prerelease: false
|
45
|
+
type: :development
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: dm-sqlite-adapter
|
48
|
+
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - '='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.2.0
|
53
|
+
none: false
|
54
|
+
requirement: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - '='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: 1.2.0
|
59
|
+
none: false
|
60
|
+
prerelease: false
|
61
|
+
type: :development
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: dm-migrations
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.2.0
|
69
|
+
none: false
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.2.0
|
75
|
+
none: false
|
76
|
+
prerelease: false
|
77
|
+
type: :development
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: copyright-header
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - "~>"
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '1.0'
|
85
|
+
none: false
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '1.0'
|
91
|
+
none: false
|
92
|
+
prerelease: false
|
93
|
+
type: :development
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: json
|
96
|
+
version_requirements: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - "~>"
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '1.7'
|
101
|
+
none: false
|
102
|
+
requirement: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - "~>"
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '1.7'
|
107
|
+
none: false
|
108
|
+
prerelease: false
|
109
|
+
type: :development
|
110
|
+
description: helper for managing users with login/password via local db or remote rest-services
|
111
|
+
email:
|
112
|
+
- m.kristian@web.de
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- lib/ixtlan-user-management.rb
|
118
|
+
- lib/ixtlan_user_management.rb
|
119
|
+
- lib/ixtlan/passwords.rb
|
120
|
+
- lib/ixtlan/user_management.rb
|
121
|
+
- lib/ixtlan/user_management/user_serializer.rb
|
122
|
+
- lib/ixtlan/user_management/authenticator.rb
|
123
|
+
- lib/ixtlan/user_management/dummy_authentication.rb
|
124
|
+
- lib/ixtlan/user_management/user_model.rb
|
125
|
+
- lib/ixtlan/user_management/session_serializer.rb
|
126
|
+
- lib/ixtlan/user_management/group_model.rb
|
127
|
+
- lib/ixtlan/user_management/user_resource.rb
|
128
|
+
- lib/ixtlan/user_management/session_manager.rb
|
129
|
+
- lib/ixtlan/user_management/session_plugin.rb
|
130
|
+
- lib/ixtlan/user_management/application_resource.rb
|
131
|
+
- lib/ixtlan/user_management/domain_resource.rb
|
132
|
+
- lib/ixtlan/user_management/authentication_model.rb
|
133
|
+
- lib/ixtlan/user_management/session_model.rb
|
134
|
+
- lib/ixtlan/user_management/application_model.rb
|
135
|
+
- lib/ixtlan/user_management/session_cuba.rb
|
136
|
+
- MIT-LICENSE
|
137
|
+
- README.md
|
138
|
+
- Gemfile
|
139
|
+
homepage: https://github.com/mkristian/ixtlan-user-management
|
140
|
+
licenses:
|
141
|
+
- MIT
|
142
|
+
post_install_message:
|
143
|
+
rdoc_options: []
|
144
|
+
require_paths:
|
145
|
+
- lib
|
146
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: !binary |-
|
151
|
+
MA==
|
152
|
+
none: false
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: !binary |-
|
158
|
+
MA==
|
159
|
+
none: false
|
160
|
+
requirements: []
|
161
|
+
rubyforge_project:
|
162
|
+
rubygems_version: 1.8.24
|
163
|
+
signing_key:
|
164
|
+
specification_version: 3
|
165
|
+
summary: helper for managing users with login/password
|
166
|
+
test_files: []
|