authentasaurus 0.4.1
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.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +173 -0
- data/TODO +4 -0
- data/app/controllers/areas_controller.rb +4 -0
- data/app/controllers/groups_controller.rb +4 -0
- data/app/controllers/permissions_controller.rb +4 -0
- data/app/controllers/recoveries_controller.rb +2 -0
- data/app/controllers/registrations_controller.rb +2 -0
- data/app/controllers/sessions_controller.rb +2 -0
- data/app/controllers/user_invitations_controller.rb +4 -0
- data/app/controllers/users_controller.rb +4 -0
- data/app/controllers/validations_controller.rb +2 -0
- data/app/models/area.rb +2 -0
- data/app/models/authentasaurus_emailer.rb +2 -0
- data/app/models/group.rb +2 -0
- data/app/models/permission.rb +2 -0
- data/app/models/recovery.rb +2 -0
- data/app/models/session.rb +2 -0
- data/app/models/user.rb +3 -0
- data/app/models/user_invitation.rb +2 -0
- data/app/models/user_sync.rb +3 -0
- data/app/models/validation.rb +2 -0
- data/app/views/areas/edit.html.erb +7 -0
- data/app/views/areas/index.html.erb +11 -0
- data/app/views/areas/new.html.erb +7 -0
- data/app/views/areas/show.html.erb +7 -0
- data/app/views/authentasaurus_emailer/invitation_mail.html.erb +4 -0
- data/app/views/authentasaurus_emailer/recovery_mail.html.erb +7 -0
- data/app/views/authentasaurus_emailer/validation_mail.html.erb +6 -0
- data/app/views/groups/edit.html.erb +7 -0
- data/app/views/groups/index.html.erb +11 -0
- data/app/views/groups/new.html.erb +7 -0
- data/app/views/groups/show.html.erb +7 -0
- data/app/views/permissions/edit.html.erb +19 -0
- data/app/views/permissions/index.html.erb +17 -0
- data/app/views/permissions/new.html.erb +19 -0
- data/app/views/permissions/show.html.erb +7 -0
- data/app/views/recoveries/edit.html.erb +24 -0
- data/app/views/recoveries/new.html.erb +15 -0
- data/app/views/registrations/new.html.erb +21 -0
- data/app/views/sessions/new.html.erb +41 -0
- data/app/views/sessions/no_access.html.erb +1 -0
- data/app/views/user_invitations/index.html.erb +14 -0
- data/app/views/user_invitations/new.html.erb +9 -0
- data/app/views/users/edit.html.erb +27 -0
- data/app/views/users/index.html.erb +19 -0
- data/app/views/users/new.html.erb +27 -0
- data/app/views/users/show.html.erb +11 -0
- data/app/views/validations/activate.html.erb +6 -0
- data/app/views/validations/resend_validation_email.html.erb +6 -0
- data/config/locales/en.yml +34 -0
- data/generators/authentasaurus/USAGE +2 -0
- data/generators/authentasaurus/authentasaurus_generator.rb +9 -0
- data/generators/authentasaurus/templates/authentasaurus_tasks.rake +48 -0
- data/generators/authentasaurus/templates/defaults.yml +51 -0
- data/generators/authentasaurus/templates/initializer.rb +3 -0
- data/generators/authentasaurus_views/USAGE +12 -0
- data/generators/authentasaurus_views/authentasaurus_views_generator.rb +87 -0
- data/generators/authentasaurus_views/templates/views/areas/edit.html.erb +7 -0
- data/generators/authentasaurus_views/templates/views/areas/index.html.erb +11 -0
- data/generators/authentasaurus_views/templates/views/areas/new.html.erb +7 -0
- data/generators/authentasaurus_views/templates/views/areas/show.html.erb +7 -0
- data/generators/authentasaurus_views/templates/views/authentasaurus_emailer/invitation_mail.html.erb +4 -0
- data/generators/authentasaurus_views/templates/views/authentasaurus_emailer/recovery_mail.html.erb +7 -0
- data/generators/authentasaurus_views/templates/views/authentasaurus_emailer/validation_mail.html.erb +6 -0
- data/generators/authentasaurus_views/templates/views/groups/edit.html.erb +7 -0
- data/generators/authentasaurus_views/templates/views/groups/index.html.erb +11 -0
- data/generators/authentasaurus_views/templates/views/groups/new.html.erb +7 -0
- data/generators/authentasaurus_views/templates/views/groups/show.html.erb +7 -0
- data/generators/authentasaurus_views/templates/views/permissions/edit.html.erb +19 -0
- data/generators/authentasaurus_views/templates/views/permissions/index.html.erb +17 -0
- data/generators/authentasaurus_views/templates/views/permissions/new.html.erb +19 -0
- data/generators/authentasaurus_views/templates/views/permissions/show.html.erb +7 -0
- data/generators/authentasaurus_views/templates/views/recoveries/edit.html.erb +24 -0
- data/generators/authentasaurus_views/templates/views/recoveries/new.html.erb +15 -0
- data/generators/authentasaurus_views/templates/views/registrations/new.html.erb +21 -0
- data/generators/authentasaurus_views/templates/views/sessions/new.html.erb +41 -0
- data/generators/authentasaurus_views/templates/views/sessions/no_access.html.erb +1 -0
- data/generators/authentasaurus_views/templates/views/user_invitations/index.html.erb +14 -0
- data/generators/authentasaurus_views/templates/views/user_invitations/new.html.erb +9 -0
- data/generators/authentasaurus_views/templates/views/users/edit.html.erb +27 -0
- data/generators/authentasaurus_views/templates/views/users/index.html.erb +19 -0
- data/generators/authentasaurus_views/templates/views/users/new.html.erb +27 -0
- data/generators/authentasaurus_views/templates/views/users/show.html.erb +11 -0
- data/generators/authentasaurus_views/templates/views/validations/activate.html.erb +6 -0
- data/generators/authentasaurus_views/templates/views/validations/resend_validation_email.html.erb +6 -0
- data/lib/action_controller/authorization.rb +215 -0
- data/lib/action_view/authorization.rb +123 -0
- data/lib/active_record/acts_as_authenticatable.rb +80 -0
- data/lib/active_record/acts_as_authenticatable_validatable.rb +32 -0
- data/lib/active_record/authenticatable.rb +56 -0
- data/lib/active_resource/acts_as_authenticatable.rb +42 -0
- data/lib/active_resource/authenticatable.rb +22 -0
- data/lib/authentasaurus.rb +21 -0
- data/lib/authentasaurus/areas_controller.rb +71 -0
- data/lib/authentasaurus/authentasaurus_controller.rb +2 -0
- data/lib/authentasaurus/groups_controller.rb +73 -0
- data/lib/authentasaurus/models/area.rb +8 -0
- data/lib/authentasaurus/models/authentasaurus_emailer.rb +31 -0
- data/lib/authentasaurus/models/group.rb +8 -0
- data/lib/authentasaurus/models/permission.rb +9 -0
- data/lib/authentasaurus/models/recovery.rb +23 -0
- data/lib/authentasaurus/models/session.rb +63 -0
- data/lib/authentasaurus/models/user_invitation.rb +21 -0
- data/lib/authentasaurus/models/validation.rb +18 -0
- data/lib/authentasaurus/permissions_controller.rb +71 -0
- data/lib/authentasaurus/recoveries_controller.rb +59 -0
- data/lib/authentasaurus/registrations_controller.rb +32 -0
- data/lib/authentasaurus/sessions_controller.rb +45 -0
- data/lib/authentasaurus/user_invitations_controller.rb +39 -0
- data/lib/authentasaurus/users_controller.rb +71 -0
- data/lib/authentasaurus/validations_controller.rb +34 -0
- data/lib/helpers/migrations.rb +171 -0
- data/lib/helpers/routing.rb +90 -0
- data/rails/init.rb +37 -0
- metadata +188 -0
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2010 Mash Ltd.
|
|
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.rdoc
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
== Authentasaurus
|
|
2
|
+
|
|
3
|
+
Authentasaurus is a dynamic group/permission based authentication and authorization engine plugin, its simple to use and easy
|
|
4
|
+
to setup.
|
|
5
|
+
|
|
6
|
+
Most helpers are inspired by Devise.
|
|
7
|
+
|
|
8
|
+
== Installation
|
|
9
|
+
|
|
10
|
+
To start using Authentasaurus follow these simple steps :
|
|
11
|
+
|
|
12
|
+
1. install authentasaurus gem by running the following command
|
|
13
|
+
gem install authentasaurus
|
|
14
|
+
2. add authentasaurus to your application environment; in config/environment.rb
|
|
15
|
+
config.gem "authentasaurus"
|
|
16
|
+
3. generate authentasaurus configuration and tasks in your application
|
|
17
|
+
script/generate authentasaurus
|
|
18
|
+
4. setup your migrations using the migration helpers
|
|
19
|
+
in the migration up method just use
|
|
20
|
+
authentasaurus_tables
|
|
21
|
+
in the migration down method
|
|
22
|
+
authentasaurus_drop_tables
|
|
23
|
+
5. migrate your database and setup your default data
|
|
24
|
+
rake authentasaurus:setup_defaults
|
|
25
|
+
6. add your routes
|
|
26
|
+
map.authentasaurus_routes :authorizable, :validatable, :invitable
|
|
27
|
+
|
|
28
|
+
that's the most basic and quick setup, you can now test your application by running script/server in your
|
|
29
|
+
project root directory and going to http://localhost:3000/sessions/sign-in
|
|
30
|
+
|
|
31
|
+
Authentasaurus is modular, you can install modules as you need them (the previous setup contains all modules), refer to the documentation for more
|
|
32
|
+
information.
|
|
33
|
+
|
|
34
|
+
== Under the hood
|
|
35
|
+
|
|
36
|
+
Authentasaurus takes advantage of rails' before_filter; it checks for the appropriate permissions before
|
|
37
|
+
every action that requires a login, a write or read permission.
|
|
38
|
+
|
|
39
|
+
At login, authentasaurus would load the user's group permissions into a session hash and then attempts to read that hash
|
|
40
|
+
when it meets a require helper on a controller.
|
|
41
|
+
|
|
42
|
+
=== Authentasaurus uses the following terms:
|
|
43
|
+
|
|
44
|
+
<tt>Area</tt>::
|
|
45
|
+
An area is in plain english the controller's name, so if you have a controller named "PostsController", the corresponding
|
|
46
|
+
area name would be "posts" (just as you type it in the generator command)
|
|
47
|
+
|
|
48
|
+
<tt>Group</tt>::
|
|
49
|
+
A group is as the name suggests, each group contains a number of users, and each user inherits the group permissions,
|
|
50
|
+
also note that at any given time, the user can only belong to one group
|
|
51
|
+
|
|
52
|
+
<tt>Permission</tt>::
|
|
53
|
+
A permission is one of two, either read or write, but take care, read or write is only a naming, and though it doesn't make
|
|
54
|
+
sense, you could treat a read permission as a write permission and vice versa, but as i said it makes no sense !
|
|
55
|
+
|
|
56
|
+
== Generators
|
|
57
|
+
|
|
58
|
+
There are two generators in Authentasaurus, the default generator
|
|
59
|
+
authentasaurus
|
|
60
|
+
and the views generator
|
|
61
|
+
authentasaurus_views
|
|
62
|
+
|
|
63
|
+
The default generator generates configurations and tasks needed by Authentasaurus, while the views generator
|
|
64
|
+
generates the views used by Authentasaurus in your application, this is useful for customizing authentasaurus and is totally
|
|
65
|
+
optional.
|
|
66
|
+
|
|
67
|
+
Authentasaurus views generator takes the name of the user controller, by default it's users
|
|
68
|
+
script/generate authentasaurus_views users
|
|
69
|
+
|
|
70
|
+
You can also use namespaces:
|
|
71
|
+
script/generate authentasaurus_views admin/users
|
|
72
|
+
|
|
73
|
+
Also you can use some options with the Authentasaurus views generator to add the modules you need:
|
|
74
|
+
|
|
75
|
+
<tt>--authorizable</tt>::
|
|
76
|
+
generates the views necessary for authorization (groups, areas and permissions)
|
|
77
|
+
|
|
78
|
+
<tt>--invitable</tt>::
|
|
79
|
+
generates the views necessary for invitable users
|
|
80
|
+
|
|
81
|
+
<tt>--validatable</tt>::
|
|
82
|
+
generates the views necessary for validatable users
|
|
83
|
+
|
|
84
|
+
You can use a combination of those options like the following example:
|
|
85
|
+
script/generate authentasaurus_views users --authorizable --invitable --validatable
|
|
86
|
+
|
|
87
|
+
== Controller Authorization Helpers
|
|
88
|
+
|
|
89
|
+
There are four main authorization helpers in Authentasaurus for use on controllers:
|
|
90
|
+
|
|
91
|
+
<tt>require_login</tt>::
|
|
92
|
+
requires the user to login before accessing the actions specified
|
|
93
|
+
|
|
94
|
+
<b>ex:</b> Tells Authentasaurus that the action destroy requires login and that
|
|
95
|
+
Authentasaurus shouldn't store the request in the session
|
|
96
|
+
(typically for logout actions)
|
|
97
|
+
|
|
98
|
+
* :skip_request - skips saving the original request (to redirect to after login)
|
|
99
|
+
* :user_model - if defined, authentasaurus will use that model instead of the default "User"
|
|
100
|
+
* :if - specifies a method, proc or string to call to determine if the authorization should occur
|
|
101
|
+
* :unless - specifies a method, proc or string to call to determine if the authorization should not occur
|
|
102
|
+
|
|
103
|
+
require_login :destroy, :skip_request => true
|
|
104
|
+
|
|
105
|
+
<tt>require_write</tt>::
|
|
106
|
+
requires the user to have a write permission to that area to access the actions specified
|
|
107
|
+
|
|
108
|
+
<b>ex:</b> Tells Authentasaurus that the actions create_user and delete_user
|
|
109
|
+
requires login and write permission.
|
|
110
|
+
|
|
111
|
+
* :skip_request - skips saving the original request (to redirect to after login)
|
|
112
|
+
* :user_model - if defined, authentasaurus will use that model instead of the default "User"
|
|
113
|
+
* :if - specifies a method, proc or string to call to determine if the authorization should occur
|
|
114
|
+
* :unless - specifies a method, proc or string to call to determine if the authorization should not occur
|
|
115
|
+
|
|
116
|
+
require_write :create_user, :delete_user
|
|
117
|
+
|
|
118
|
+
<tt>require_read</tt>::
|
|
119
|
+
requires the user to have a read permission to that area to access the actions specified
|
|
120
|
+
|
|
121
|
+
<b>ex:</b> Tells Authentasaurus that the action show_user requires login and read
|
|
122
|
+
permission.
|
|
123
|
+
|
|
124
|
+
* :skip_request - skips saving the original request (to redirect to after login)
|
|
125
|
+
* :user_model - if defined, authentasaurus will use that model instead of the default "User"
|
|
126
|
+
* :if - specifies a method, proc or string to call to determine if the authorization should occur
|
|
127
|
+
* :unless - specifies a method, proc or string to call to determine if the authorization should not occur
|
|
128
|
+
|
|
129
|
+
require_read :show_user, :if api_key.nil?
|
|
130
|
+
|
|
131
|
+
You can use any of those class methods on you controllers to restrict access levels like so:
|
|
132
|
+
class PostsController < ApplicationController
|
|
133
|
+
require_login :index
|
|
134
|
+
require_read :show
|
|
135
|
+
require_write :new, :create, :edit, :update, :destroy
|
|
136
|
+
|
|
137
|
+
def index
|
|
138
|
+
# your code here
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def show
|
|
142
|
+
# your code here
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def new
|
|
146
|
+
# your code here
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def create
|
|
150
|
+
# your code here
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def edit
|
|
154
|
+
# your code here
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def update
|
|
158
|
+
# your code here
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def destroy
|
|
162
|
+
# your code here
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
In addition there is also the has? helper which is available in both Controllers and Views
|
|
167
|
+
|
|
168
|
+
<tt>has?(permission, area=nil)</tt>::
|
|
169
|
+
Checks if the current user has the appropriate permissions for the area specified
|
|
170
|
+
|
|
171
|
+
<b>ex</b>: has?(:write) or has?(:read, :users)
|
|
172
|
+
|
|
173
|
+
Copyright (c) 2010 Mash, Ltd., released under the MIT license
|
data/TODO
ADDED
data/app/models/area.rb
ADDED
data/app/models/group.rb
ADDED
data/app/models/user.rb
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<h1>Editing <%= @permission.area.target %> permissions for <%= @permission.group.name %></h1>
|
|
2
|
+
<% form_for @permission do |f| %>
|
|
3
|
+
<%= f.label :group_id %>
|
|
4
|
+
<%= f.collection_select(:group_id, Group.find(:all), :id, :name, {:prompt => true}) %>
|
|
5
|
+
<br>
|
|
6
|
+
<%= f.label :area_id %>
|
|
7
|
+
<%= f.collection_select(:area_id, Area.find(:all), :id, :name, {:prompt => true}) %>
|
|
8
|
+
<br>
|
|
9
|
+
<%= f.label :group_id %>
|
|
10
|
+
<%= f.collection_select(:group_id, Group.find(:all), :id, :name, {:prompt => true}) %>
|
|
11
|
+
<br>
|
|
12
|
+
<%= f.label :read %>
|
|
13
|
+
<%= f.check_box :read %>
|
|
14
|
+
<br>
|
|
15
|
+
<%= f.label :write %>
|
|
16
|
+
<%= f.check_box :write %>
|
|
17
|
+
<br>
|
|
18
|
+
<%= f.submit %>
|
|
19
|
+
<% end %>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<h1>Permissions</h1>
|
|
2
|
+
<table>
|
|
3
|
+
<tr>
|
|
4
|
+
<th>Group</th>
|
|
5
|
+
<th>Area</th>
|
|
6
|
+
<th>Read</th>
|
|
7
|
+
<th>Write</th>
|
|
8
|
+
</tr>
|
|
9
|
+
<% @permissions.each do |permission| %>
|
|
10
|
+
<tr>
|
|
11
|
+
<td><%= link_to permission.group.name, permission.group %></td>
|
|
12
|
+
<td><%= link_to permission.area.name, permission.area %></td>
|
|
13
|
+
<td><%= check_box_tag :read, "read", permission.read, :disabled => true %></td>
|
|
14
|
+
<td><%= check_box_tag :write, "write", permission.write, :disabled => true %></td>
|
|
15
|
+
</tr>
|
|
16
|
+
<% end %>
|
|
17
|
+
</table>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<h1>Create Permission</h1>
|
|
2
|
+
<% form_for @permission do |f| %>
|
|
3
|
+
<%= f.label :group_id %>
|
|
4
|
+
<%= f.collection_select(:group_id, Group.find(:all), :id, :name, {:prompt => true}) %>
|
|
5
|
+
<br>
|
|
6
|
+
<%= f.label :area_id %>
|
|
7
|
+
<%= f.collection_select(:area_id, Area.find(:all), :id, :name, {:prompt => true}) %>
|
|
8
|
+
<br>
|
|
9
|
+
<%= f.label :group_id %>
|
|
10
|
+
<%= f.collection_select(:group_id, Group.find(:all), :id, :name, {:prompt => true}) %>
|
|
11
|
+
<br>
|
|
12
|
+
<%= f.label :read %>
|
|
13
|
+
<%= f.check_box :read %>
|
|
14
|
+
<br>
|
|
15
|
+
<%= f.label :write %>
|
|
16
|
+
<%= f.check_box :write %>
|
|
17
|
+
<br>
|
|
18
|
+
<%= f.submit %>
|
|
19
|
+
<% end %>
|