ixtlan-remote 0.1.0

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.
Files changed (89) hide show
  1. data/Gemfile +2 -0
  2. data/README.md +64 -0
  3. data/agpl-3.0.txt +661 -0
  4. data/lib/ixtlan-remote.rb +23 -0
  5. data/lib/ixtlan/passwords.rb +52 -0
  6. data/lib/ixtlan/passwords.rb~ +47 -0
  7. data/lib/ixtlan/railtie.rb~ +17 -0
  8. data/lib/ixtlan/remote.rb +23 -0
  9. data/lib/ixtlan/remote/access_controller.rb +62 -0
  10. data/lib/ixtlan/remote/access_controller.rb~ +25 -0
  11. data/lib/ixtlan/remote/constant_time_compare.rb +39 -0
  12. data/lib/ixtlan/remote/constant_time_compare.rb~ +19 -0
  13. data/lib/ixtlan/remote/heartbeat.rb~ +80 -0
  14. data/lib/ixtlan/remote/model_conversion.rb~ +245 -0
  15. data/lib/ixtlan/remote/model_helpers.rb +73 -0
  16. data/lib/ixtlan/remote/model_helpers.rb~ +53 -0
  17. data/lib/ixtlan/remote/permission.rb +40 -0
  18. data/lib/ixtlan/remote/permission.rb~ +19 -0
  19. data/lib/ixtlan/remote/railtie.rb +30 -0
  20. data/lib/ixtlan/remote/railtie.rb~ +9 -0
  21. data/lib/ixtlan/remote/remote_access_controller.rb~ +25 -0
  22. data/lib/ixtlan/remote/remote_permisson.rb~ +9 -0
  23. data/lib/ixtlan/remote/resource.rb +145 -0
  24. data/lib/ixtlan/remote/resource.rb-~ +165 -0
  25. data/lib/ixtlan/remote/resource.rb~ +152 -0
  26. data/lib/ixtlan/remote/rest.rb +108 -0
  27. data/lib/ixtlan/remote/rest.rb~ +83 -0
  28. data/lib/ixtlan/remote/rest_resource.rb~ +140 -0
  29. data/lib/ixtlan/remote/rest_resource_config.rb~ +63 -0
  30. data/lib/ixtlan/remote/rest_resource_factory.rb~ +259 -0
  31. data/lib/ixtlan/remote/rest_resource_old.rb-~ +259 -0
  32. data/lib/ixtlan/remote/server.rb +119 -0
  33. data/lib/ixtlan/remote/server.rb~ +82 -0
  34. data/lib/ixtlan/remote/summary.rb +46 -0
  35. data/lib/ixtlan/remote/summary.rb~ +23 -0
  36. data/lib/ixtlan/remote/sync.rb +104 -0
  37. data/lib/ixtlan/remote/sync.rb~ +78 -0
  38. data/lib/ixtlan/remote/sync_summary.rb~ +23 -0
  39. data/lib/ixtlan/remote/tranlation_key.rb~ +7 -0
  40. data/lib/ixtlan/remote/translation.rake~ +194 -0
  41. data/lib/ixtlan/remote/translation_models.rb~ +11 -0
  42. data/lib/ixtlan/remote/updater.rb~ +71 -0
  43. data/lib/ixtlan/user_management/application_model.rb +30 -0
  44. data/lib/ixtlan/user_management/application_model.rb~ +21 -0
  45. data/lib/ixtlan/user_management/application_resource.rb +48 -0
  46. data/lib/ixtlan/user_management/application_resource.rb~ +21 -0
  47. data/lib/ixtlan/user_management/authentcator.rb~ +31 -0
  48. data/lib/ixtlan/user_management/authentication_model.rb +31 -0
  49. data/lib/ixtlan/user_management/authentication_model.rb~ +21 -0
  50. data/lib/ixtlan/user_management/authenticator.rb +55 -0
  51. data/lib/ixtlan/user_management/authenticator.rb~ +20 -0
  52. data/lib/ixtlan/user_management/domain_resource.rb +48 -0
  53. data/lib/ixtlan/user_management/domain_resource.rb~ +21 -0
  54. data/lib/ixtlan/user_management/dummy_authentication.rb +50 -0
  55. data/lib/ixtlan/user_management/dummy_authentication.rb~ +49 -0
  56. data/lib/ixtlan/user_management/group.rb~ +39 -0
  57. data/lib/ixtlan/user_management/group_model.rb +31 -0
  58. data/lib/ixtlan/user_management/group_model.rb~ +21 -0
  59. data/lib/ixtlan/user_management/models.rb~ +39 -0
  60. data/lib/ixtlan/user_management/session-serializer.rb~ +18 -0
  61. data/lib/ixtlan/user_management/session_cuba.rb +47 -0
  62. data/lib/ixtlan/user_management/session_cuba.rb~ +44 -0
  63. data/lib/ixtlan/user_management/session_manager.rb +38 -0
  64. data/lib/ixtlan/user_management/session_model.rb +36 -0
  65. data/lib/ixtlan/user_management/session_model.rb~ +10 -0
  66. data/lib/ixtlan/user_management/session_plugin.rb +32 -0
  67. data/lib/ixtlan/user_management/session_serializer.rb +21 -0
  68. data/lib/ixtlan/user_management/session_serializer.rb~ +21 -0
  69. data/lib/ixtlan/user_management/user.rb~ +16 -0
  70. data/lib/ixtlan/user_management/user_model.rb +36 -0
  71. data/lib/ixtlan/user_management/user_model.rb~ +33 -0
  72. data/lib/ixtlan/user_management/user_resource.rb +55 -0
  73. data/lib/ixtlan/user_management/user_resource.rb~ +24 -0
  74. data/lib/ixtlan/user_management/user_serializer.rb +15 -0
  75. data/lib/ixtlan/user_management/user_serializer.rb~ +23 -0
  76. data/spec/access_controller_spec.rb +65 -0
  77. data/spec/access_controller_spec.rb~ +65 -0
  78. data/spec/model_helpers_spec.rb +40 -0
  79. data/spec/model_helpers_spec.rb~ +36 -0
  80. data/spec/remote_access_controller_spec.rb~ +36 -0
  81. data/spec/resource_spec.rb +181 -0
  82. data/spec/resource_spec.rb~ +173 -0
  83. data/spec/rest_resource_spec.rb~ +173 -0
  84. data/spec/rest_spec.rb +94 -0
  85. data/spec/rest_spec.rb~ +99 -0
  86. data/spec/rest_with_attribute_name_like_model_name_spec.rb +82 -0
  87. data/spec/sync_spec.rb +83 -0
  88. data/spec/sync_spec.rb~ +81 -0
  89. metadata +313 -0
@@ -0,0 +1,47 @@
1
+ # -*- Coding: utf-8 -*-
2
+ require 'ixtlan/user_management/session_plugin'
3
+
4
+ module Ixtlan
5
+ module UserManagement
6
+
7
+ class SessionCuba < CubaAPI
8
+
9
+ plugin SessionPlugin
10
+
11
+ define do
12
+ on post, :reset_password do
13
+ if msg = self.class.authenticator.reset_password( login_and_password[ 0 ] )
14
+ log msg
15
+ head 200
16
+ else
17
+ log "user/email not found"
18
+ head 404
19
+ end
20
+ end
21
+
22
+ on post do
23
+ user = self.class.authenticator.login( *login_and_password )
24
+ if user
25
+ current_user( user )
26
+ # be compliant with rack-protection and rack-csrf
27
+ csrf = session[ :csrf ] || session[ "csrf.token" ]
28
+ res[ 'X-CSRF-TOKEN' ] = csrf if csrf
29
+ write self.class.sessions.create( user )
30
+ else
31
+ log "access denied"
32
+ head 403
33
+ end
34
+ end
35
+
36
+ on get, :ping do
37
+ head 200
38
+ end
39
+
40
+ on delete do
41
+ log "logout"
42
+ reset_current_user
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,44 @@
1
+ # -*- Coding: utf-8 -*-
2
+ require 'session_plugin'
3
+
4
+ module Ixtlan
5
+ module UserManagement
6
+
7
+ class SessionCuba < CubaAPI
8
+
9
+ plugin SessionPlugin
10
+
11
+ define do
12
+ on post, :reset_password do
13
+ if msg = self.class.authenticator.reset_password( login_and_password[ 0 ] )
14
+ log msg
15
+ head 200
16
+ else
17
+ log "user/email not found"
18
+ head 404
19
+ end
20
+ end
21
+
22
+ on post do
23
+ user = self.class.authenticator.login( *login_and_password )
24
+ if user
25
+ current_user( user )
26
+ write self.class.sessions.create( user )
27
+ else
28
+ log "access denied"
29
+ head 403
30
+ end
31
+ end
32
+
33
+ on get, :ping do
34
+ head 200
35
+ end
36
+
37
+ on delete do
38
+ log "logout"
39
+ reset_current_user
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,38 @@
1
+ # -*- Coding: utf-8 -*-
2
+ require 'ixtlan/user_management/user_model'
3
+ require 'ixtlan/user_management/user_serializer'
4
+ require 'ixtlan/user_management/session_model'
5
+ require 'ixtlan/user_management/session_serializer'
6
+
7
+ module Ixtlan
8
+ module UserManagement
9
+ class SessionManager
10
+
11
+ attr_accessor :idle_session_timeout, :block
12
+
13
+ def initialize( &block )
14
+ @block = block || lambda { [] }
15
+ end
16
+
17
+ def serializer( user )
18
+ UserSerializer.new( user )
19
+ end
20
+
21
+ def to_session( user )
22
+ serializer( user ).use( :session ).to_hash
23
+ end
24
+
25
+ def from_session( data )
26
+ if data
27
+ User.new( data )
28
+ end
29
+ end
30
+
31
+ def create( user )
32
+ Session.new( 'user' => user,
33
+ 'permissions' => block.call( user.groups ),
34
+ 'idle_session_timeout' => idle_session_timeout )
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,36 @@
1
+ #
2
+ # ixtlan-remote - helper sync data between miniapps or communicate wth realtime
3
+ # rest-services
4
+ # Copyright (C) 2012 Christian Meier
5
+ #
6
+ # This file is part of ixtlan-remote.
7
+ #
8
+ # ixtlan-remote is free software: you can redistribute it and/or modify
9
+ # it under the terms of the GNU Affero General Public License as
10
+ # published by the Free Software Foundation, either version 3 of the
11
+ # License, or (at your option) any later version.
12
+ #
13
+ # ixtlan-remote is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU Affero General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU Affero General Public License
19
+ # along with ixtlan-remote. If not, see <http://www.gnu.org/licenses/>.
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,10 @@
1
+ module Ixtlan
2
+ module UserManagement
3
+ class Session
4
+ include Virtus
5
+
6
+ attribute :name, String
7
+ attribute :url, String
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,32 @@
1
+ # -*- Coding: utf-8 -*-
2
+ require 'ixtlan/user_management/authenticator'
3
+
4
+ module Ixtlan
5
+ module UserManagement
6
+ module SessionPlugin
7
+
8
+ module ClassMethods
9
+ def authenticator
10
+ self[ :authenticator ] ||= Authenticator.new( self[ :rest ] )
11
+ end
12
+ end
13
+
14
+ def log( msg )
15
+ if self.respond_to? :audit
16
+ audit( msg, { :username => login } )
17
+ else
18
+ warn( "[#{login}] #{msg}" )
19
+ end
20
+ end
21
+
22
+ def login_and_password
23
+ auth = req[:authentication] || req
24
+ [ auth[:login] || auth[:email], auth[:password] ]
25
+ end
26
+
27
+ def login
28
+ login_and_password[ 0 ]
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,21 @@
1
+ require 'ixtlan/babel/serializer'
2
+ module Ixtlan
3
+ module UserManagement
4
+ class SessionSerializer < Ixtlan::Babel::Serializer
5
+
6
+ root 'session'
7
+
8
+ add_context(:single,
9
+ :only => [:idle_session_timeout],
10
+ :include => {
11
+ :user => {
12
+ },
13
+ :permissions => {
14
+ :include => [:actions, :associations]
15
+ }
16
+ }
17
+ )
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'ixtlan/babel/serializer'
2
+ module Ixtlan
3
+ module UserManagement
4
+ class SessionSerializer < Ixtlan::Babel::Serializer
5
+
6
+ root 'session'
7
+
8
+ add_context(:single,
9
+ :only => [:permissions, :idle_session_timeout],
10
+ :include=> {
11
+ :user => {
12
+ },
13
+ :permissions => {
14
+ :include => [:actions, :associations]
15
+ }
16
+ }
17
+ )
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ class User
2
+
3
+ include DataMapper::Resource
4
+
5
+ property :id, Serial, :auto_validation => false
6
+
7
+ property :login, String, :required => true, :unique => true, :length => 32
8
+ property :name, String, :required => true, :length => 128
9
+ property :updated_at, DateTime, :required => true
10
+
11
+ attr_accessor :groups, :applications
12
+
13
+ # do not record timestamps since they are set from outside
14
+ def set_timestamps_on_save
15
+ end
16
+ end
@@ -0,0 +1,36 @@
1
+ #
2
+ # ixtlan-remote - helper sync data between miniapps or communicate wth realtime
3
+ # rest-services
4
+ # Copyright (C) 2012 Christian Meier
5
+ #
6
+ # This file is part of ixtlan-remote.
7
+ #
8
+ # ixtlan-remote is free software: you can redistribute it and/or modify
9
+ # it under the terms of the GNU Affero General Public License as
10
+ # published by the Free Software Foundation, either version 3 of the
11
+ # License, or (at your option) any later version.
12
+ #
13
+ # ixtlan-remote is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU Affero General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU Affero General Public License
19
+ # along with ixtlan-remote. If not, see <http://www.gnu.org/licenses/>.
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,33 @@
1
+ #
2
+ # ixtlan-remote - helper sync data between miniapps or communicate wth realtime
3
+ # rest-services
4
+ # Copyright (C) 2012 Christian Meier
5
+ #
6
+ # This file is part of ixtlan-remote.
7
+ #
8
+ # ixtlan-remote is free software: you can redistribute it and/or modify
9
+ # it under the terms of the GNU Affero General Public License as
10
+ # published by the Free Software Foundation, either version 3 of the
11
+ # License, or (at your option) any later version.
12
+ #
13
+ # ixtlan-remote is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU Affero General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU Affero General Public License
19
+ # along with ixtlan-remote. If not, see <http://www.gnu.org/licenses/>.
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
+ end
32
+ end
33
+ end
@@ -0,0 +1,55 @@
1
+ #
2
+ # ixtlan-remote - helper sync data between miniapps or communicate wth realtime
3
+ # rest-services
4
+ # Copyright (C) 2012 Christian Meier
5
+ #
6
+ # This file is part of ixtlan-remote.
7
+ #
8
+ # ixtlan-remote is free software: you can redistribute it and/or modify
9
+ # it under the terms of the GNU Affero General Public License as
10
+ # published by the Free Software Foundation, either version 3 of the
11
+ # License, or (at your option) any later version.
12
+ #
13
+ # ixtlan-remote is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU Affero General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU Affero General Public License
19
+ # along with ixtlan-remote. If not, see <http://www.gnu.org/licenses/>.
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 initialize(params = {})
51
+ super
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,24 @@
1
+ module Ixtlan
2
+ module UserManagement
3
+ class User
4
+
5
+ include DataMapper::Resource
6
+
7
+ def self.storage_name(arg)
8
+ 'ixtlan_users'
9
+ end
10
+
11
+ property :id, Serial, :auto_validation => false
12
+
13
+ property :login, String, :required => true, :unique => true, :length => 32
14
+ property :name, String, :required => true, :length => 128
15
+ property :updated_at, DateTime, :required => true
16
+
17
+ attr_accessor :groups, :applications, :domains, :locales
18
+
19
+ # do not record timestamps since they are set from outside
20
+ def set_timestamps_on_save
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,15 @@
1
+ require 'ixtlan/babel/serializer'
2
+ module Ixtlan
3
+ module UserManagement
4
+ class UserSerializer < Ixtlan::Babel::Serializer
5
+
6
+ add_context(:session,
7
+ :only => [:login, :name],
8
+ :include=> {
9
+ :groups => {
10
+ :only => [:name]
11
+ }
12
+ })
13
+ end
14
+ end
15
+ end