ucb_rails_security 2.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +6 -0
- data/Manifest +56 -0
- data/README +195 -0
- data/Rakefile +21 -0
- data/TODO +3 -0
- data/generators/ucb_rails_security/templates/controllers/ucb_security/base_controller.rb +17 -0
- data/generators/ucb_rails_security/templates/controllers/ucb_security/ldap_search_controller.rb +10 -0
- data/generators/ucb_rails_security/templates/controllers/ucb_security/role_users_controller.rb +27 -0
- data/generators/ucb_rails_security/templates/controllers/ucb_security/roles_controller.rb +52 -0
- data/generators/ucb_rails_security/templates/controllers/ucb_security/user_roles_controller.rb +29 -0
- data/generators/ucb_rails_security/templates/controllers/ucb_security/users_controller.rb +59 -0
- data/generators/ucb_rails_security/templates/db/migrate/xxx_create_ucb_rails_security_tables.rb +31 -0
- data/generators/ucb_rails_security/templates/helpers/ucb_security/base_helper.rb +23 -0
- data/generators/ucb_rails_security/templates/helpers/ucb_security/builder.rb +25 -0
- data/generators/ucb_rails_security/templates/helpers/ucb_security/roles_helper.rb +2 -0
- data/generators/ucb_rails_security/templates/helpers/ucb_security/users_helper.rb +2 -0
- data/generators/ucb_rails_security/templates/initializers/ucb_security_config.rb +20 -0
- data/generators/ucb_rails_security/templates/javascripts/ucb_security.js +99 -0
- data/generators/ucb_rails_security/templates/models/ldap_search.rb +48 -0
- data/generators/ucb_rails_security/templates/models/role.rb +32 -0
- data/generators/ucb_rails_security/templates/models/user.rb +106 -0
- data/generators/ucb_rails_security/templates/models/user_roles.rb +3 -0
- data/generators/ucb_rails_security/templates/stylesheets/ucb_security.css +347 -0
- data/generators/ucb_rails_security/templates/views/layouts/ucb_security/_main_navigation.html.erb +10 -0
- data/generators/ucb_rails_security/templates/views/layouts/ucb_security/application.html.erb +24 -0
- data/generators/ucb_rails_security/templates/views/ucb_security/ldap_search/index.html.erb +62 -0
- data/generators/ucb_rails_security/templates/views/ucb_security/role_users/_new.html.erb +11 -0
- data/generators/ucb_rails_security/templates/views/ucb_security/role_users/edit.html.erb +37 -0
- data/generators/ucb_rails_security/templates/views/ucb_security/roles/_users.html.erb +14 -0
- data/generators/ucb_rails_security/templates/views/ucb_security/roles/edit.html.erb +19 -0
- data/generators/ucb_rails_security/templates/views/ucb_security/roles/index.html.erb +34 -0
- data/generators/ucb_rails_security/templates/views/ucb_security/roles/new.html.erb +19 -0
- data/generators/ucb_rails_security/templates/views/ucb_security/roles/show.html.erb +27 -0
- data/generators/ucb_rails_security/templates/views/ucb_security/user_roles/edit.html.erb +17 -0
- data/generators/ucb_rails_security/templates/views/ucb_security/users/edit.html.erb +23 -0
- data/generators/ucb_rails_security/templates/views/ucb_security/users/index.html.erb +43 -0
- data/generators/ucb_rails_security/templates/views/ucb_security/users/new.html.erb +29 -0
- data/generators/ucb_rails_security/templates/views/ucb_security/users/show.html.erb +43 -0
- data/generators/ucb_rails_security/ucb_rails_security_generator.rb +191 -0
- data/init.rb +9 -0
- data/lib/helpers/rspec_helpers.rb +119 -0
- data/lib/tasks/ucb_rails_security.rake +22 -0
- data/lib/ucb_rails_security.rb +60 -0
- data/lib/ucb_rails_security_casauthentication.rb +117 -0
- data/lib/ucb_rails_security_logger.rb +33 -0
- data/lib/ucb_rs_controller_methods.rb +496 -0
- data/rdoc_includes/application_controller_rb.txt +9 -0
- data/rspec/_all_specs.rb +5 -0
- data/rspec/_setup.rb +36 -0
- data/rspec/filter_ldap_spec.rb +87 -0
- data/rspec/filter_role_spec.rb +56 -0
- data/rspec/filter_spec.rb +37 -0
- data/rspec/filter_user_spec.rb +55 -0
- data/rspec/logged_in_status_spec.rb +226 -0
- data/rspec/ucb_rails_security_casauthentication_spec.rb +83 -0
- data/rspec/ucb_rails_security_spec.rb +34 -0
- data/test/test_rails-2.0.x/test/test_helper.rb +38 -0
- data/test/test_rails-2.1.x/test/test_helper.rb +38 -0
- data/ucb_rails_security.gemspec +41 -0
- metadata +147 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
<h1>Ldap Search</h1>
|
2
|
+
|
3
|
+
<br/>
|
4
|
+
|
5
|
+
<div class="ucb_rails_security_form">
|
6
|
+
<% form_tag(ucb_security_ldap_search_path, :method => :get) do %>
|
7
|
+
<p>
|
8
|
+
<%= label('search_term', 'Search Term') %>
|
9
|
+
<%= select_tag('search_term', options_for_select(@select_options, @search_term)) %>
|
10
|
+
</p>
|
11
|
+
|
12
|
+
<p>
|
13
|
+
<%= label('search_value', 'Search Value') %>
|
14
|
+
<%= text_field_tag('search_value', params[:search_value], :size => 30) %>
|
15
|
+
</p>
|
16
|
+
|
17
|
+
<p>
|
18
|
+
<div class="button_widget">
|
19
|
+
<%= submit_tag("Search") %> |
|
20
|
+
<%= link_to('Clear', ucb_security_ldap_search_path()) %>
|
21
|
+
</div>
|
22
|
+
</p>
|
23
|
+
<% end %>
|
24
|
+
</div>
|
25
|
+
|
26
|
+
<br/>
|
27
|
+
|
28
|
+
<% if @search_initiated && @ldap_people.empty? %>
|
29
|
+
|
30
|
+
<p class="empty_search_results">Your search did not match any people in the directory.</p>
|
31
|
+
|
32
|
+
<% elsif !@ldap_people.empty? %>
|
33
|
+
|
34
|
+
<h2>LDAP Search Results</h2>
|
35
|
+
<p>Click on the person's LDAP UID to populate a form with their LDAP data</p>
|
36
|
+
|
37
|
+
<table class='horizontal max_width'>
|
38
|
+
<tr>
|
39
|
+
<th width="1%">LDAP UID</th>
|
40
|
+
<th>First</th>
|
41
|
+
<th>Last</th>
|
42
|
+
<th>Dept Code</th>
|
43
|
+
<th>Department</th>
|
44
|
+
<th>Phone</th>
|
45
|
+
<th>Email</th>
|
46
|
+
</tr>
|
47
|
+
<tbody class="highlight">
|
48
|
+
<% @ldap_people.each do |p| %>
|
49
|
+
<tr>
|
50
|
+
<td><%= link_to(p.uid, new_ucb_security_user_path(:ldap_uid => p.uid, :givenname => params[:givenname], :sn => params[:sn])) %></td>
|
51
|
+
<td><%=h p.first_name %></td>
|
52
|
+
<td><%=h p.last_name %></td>
|
53
|
+
<td><%=h p.dept_code %></td>
|
54
|
+
<td><%=h p.dept_name %></td>
|
55
|
+
<td><%=h p.phone %></td>
|
56
|
+
<td><%=h p.email %></td>
|
57
|
+
</tr>
|
58
|
+
<% end %>
|
59
|
+
</tbody>
|
60
|
+
</table>
|
61
|
+
|
62
|
+
<% end %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<% if @unassociated_users.empty? %>
|
2
|
+
<p>There are no unassociated users</p>
|
3
|
+
<% else %>
|
4
|
+
<% form_tag(role_users_path(:role_id => @role), :method => :put) do %>
|
5
|
+
<%= select_tag('role[user_ids][]', options_for_select(@unassociated_users), :multiple => 'true', :size => 13) %>
|
6
|
+
<% @role_users .each do |ru| %>
|
7
|
+
<%= hidden_field_tag('role[user_ids][]', ru.id ) %>
|
8
|
+
<% end %>
|
9
|
+
<%= submit_tag('Add') %>
|
10
|
+
<% end %>
|
11
|
+
<% end %>
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<h1>Role: <i><%= h @role.name.capitalize %></i></h1>
|
2
|
+
|
3
|
+
|
4
|
+
<% form_for([:ucb_security, @user, @role], :url => ucb_security_role_users_path(@role), :html => {:method => :put}) do %>
|
5
|
+
<table class="doubleSelectList">
|
6
|
+
<tr>
|
7
|
+
<td width="40%">
|
8
|
+
<label>Users without Role: <i><%= @role.name.capitalize %></i></label><br/>
|
9
|
+
<%= select_tag("", options_for_select(@unassociated_users),
|
10
|
+
:id => 'users_wo_role', :multiple => true, :size => 10) %>
|
11
|
+
</td>
|
12
|
+
<td width="20%" class="buttons">
|
13
|
+
<label>Move Selected</label><br/>
|
14
|
+
<%= button_to_function(">", "DoubleSelectList.moveSelected('users_wo_role', 'users_w_role')") %><br/>
|
15
|
+
<%= button_to_function("<", "DoubleSelectList.moveSelected('users_w_role', 'users_wo_role')") %><br/>
|
16
|
+
<br/>
|
17
|
+
|
18
|
+
<label>Move All</label><br/>
|
19
|
+
<%= button_to_function(">>", "DoubleSelectList.moveAll('users_wo_role', 'users_w_role')") %><br/>
|
20
|
+
<%= button_to_function("<<", "DoubleSelectList.moveAll('users_w_role', 'users_wo_role')") %><br/>
|
21
|
+
</td>
|
22
|
+
<td width="40%">
|
23
|
+
<label>Users with Role: <i><%= @role.name.capitalize %></i></label><br/>
|
24
|
+
<%= select_tag("user_ids[]", options_for_select(@associated_users),
|
25
|
+
:id => 'users_w_role', :multiple => true, :size => 10) %>
|
26
|
+
</td>
|
27
|
+
</tr>
|
28
|
+
</table>
|
29
|
+
|
30
|
+
<div class="button_widget">
|
31
|
+
<%= submit_tag("Update", :id => 'update_button') %> | <%= link_to("Done", ucb_security_role_path(@role)) %>
|
32
|
+
</div>
|
33
|
+
<% end %>
|
34
|
+
|
35
|
+
<%= javascript_tag("DoubleSelectList.initSubmitCallback('update_button', 'users_wo_role', 'users_w_role')") %>
|
36
|
+
|
37
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
<% if @role.users.size > 0 %>
|
3
|
+
<ul>
|
4
|
+
<% @role.users.each do |user| %>
|
5
|
+
<li><%= link_to(user.display_name, ucb_security_user_url(user), :id => "user_#{user.id}") %></li>
|
6
|
+
<% end %>
|
7
|
+
</ul>
|
8
|
+
<% else %>
|
9
|
+
<p>No uses are associated with this role</p>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<div class="button_widget">
|
13
|
+
<%= button_to("Edit", edit_ucb_security_role_users_url(@role), :method => :get) %>
|
14
|
+
</div>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<h1>Edit Role</h1>
|
2
|
+
|
3
|
+
<div class="ucb_rails_security_form">
|
4
|
+
<fieldset>
|
5
|
+
<legend>Role Details</legend>
|
6
|
+
<% form_for([:ucb_security, @role], :builder => UcbSecurity::Builder) do |f| %>
|
7
|
+
|
8
|
+
<%= f.text_field('Name:', :name, :required => true) %>
|
9
|
+
<%= f.text_area('Description:', :description, {}, {:rows => 6}) %>
|
10
|
+
|
11
|
+
<p>
|
12
|
+
<div class="button_widget">
|
13
|
+
<%= f.submit("Update") %> |
|
14
|
+
<%= link_to("Done", ucb_security_role_path(@role)) %>
|
15
|
+
</div>
|
16
|
+
</p>
|
17
|
+
<% end %>
|
18
|
+
</fieldset>
|
19
|
+
</div>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
<h1>Listing Roles</h1>
|
2
|
+
|
3
|
+
<div class="new_record_widget">
|
4
|
+
<%= link_to('New Role', new_ucb_security_role_path()) %>
|
5
|
+
</div>
|
6
|
+
|
7
|
+
|
8
|
+
<table class="horizontal mid_width">
|
9
|
+
<tr>
|
10
|
+
<th colspan="3" width="1%"></th>
|
11
|
+
<th>Name</th>
|
12
|
+
<th>Description</th>
|
13
|
+
</tr>
|
14
|
+
|
15
|
+
<% for role in @roles %>
|
16
|
+
<tbody class="highlight">
|
17
|
+
<tr>
|
18
|
+
<td><%= link_to('View', ucb_security_role_path(role)) %></td>
|
19
|
+
<td><%= link_to('Edit', edit_ucb_security_role_path(role)) %></td>
|
20
|
+
<td><%= link_to('Delete', ucb_security_role_path(role), :confirm => 'Are you sure?', :method => :delete) %></td>
|
21
|
+
<td><%=h role.name %></td>
|
22
|
+
<td><%=h role.description %></td>
|
23
|
+
</tr>
|
24
|
+
</tbody>
|
25
|
+
<% end %>
|
26
|
+
</table>
|
27
|
+
|
28
|
+
<br />
|
29
|
+
|
30
|
+
<% if @roles.size > 15 %>
|
31
|
+
<div class="new_record_widget">
|
32
|
+
<%= link_to('New Role', new_ucb_security_role_path()) %>
|
33
|
+
</div>
|
34
|
+
<% end %>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<h1>New Role</h1>
|
2
|
+
|
3
|
+
<div class="ucb_rails_security_form">
|
4
|
+
<fieldset>
|
5
|
+
<legend>Role Details</legend>
|
6
|
+
<% form_for([:ucb_security, @role], :builder => UcbSecurity::Builder) do |f| %>
|
7
|
+
|
8
|
+
<%= f.text_field('Name:', :name, :required => true) %>
|
9
|
+
<%= f.text_area('Description:', :description, {}, {:rows => 6}) %>
|
10
|
+
|
11
|
+
<p>
|
12
|
+
<div class="button_widget">
|
13
|
+
<%= f.submit("Create") %> |
|
14
|
+
<%= link_to("Back", ucb_security_roles_path) %>
|
15
|
+
</div>
|
16
|
+
</p>
|
17
|
+
<% end %>
|
18
|
+
</fieldset>
|
19
|
+
</div>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<h1>View Role</h1>
|
2
|
+
|
3
|
+
<div class="ucb_rails_security_form">
|
4
|
+
<fieldset>
|
5
|
+
<legend>Role Details</legend>
|
6
|
+
<% fields_for([:ucb_security, @role], :builder => UcbSecurity::Builder) do |f| %>
|
7
|
+
<%= f.text_field('Name:', :name, {:required => true}, {:readonly => true}) %>
|
8
|
+
<%= f.text_area('Description:', :description, {}, {:readonly => true, :rows => 6}) %>
|
9
|
+
|
10
|
+
<p>
|
11
|
+
<div class="button_widget">
|
12
|
+
<%= button_to("Edit", edit_ucb_security_role_path(@role), :method => :get) %> |
|
13
|
+
<%= link_to("List Roles", ucb_security_roles_path()) %>
|
14
|
+
</div>
|
15
|
+
</p>
|
16
|
+
<% end %>
|
17
|
+
</fieldset>
|
18
|
+
</div>
|
19
|
+
|
20
|
+
<br/>
|
21
|
+
|
22
|
+
<div class="ucb_rails_security_form">
|
23
|
+
<fieldset>
|
24
|
+
<legend>Role Users</legend>
|
25
|
+
<%= render(:partial => 'users') %>
|
26
|
+
</fielset>
|
27
|
+
</div>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<h1>Roles for: <%= h @user.full_name %></h1>
|
2
|
+
|
3
|
+
<% form_for([:ucb_security, @user], :url => ucb_security_user_roles_path(@user), :html => {:method => :put}) do %>
|
4
|
+
<ul style="display: inline; list-style-type: none;">
|
5
|
+
<% @roles.each do |role| %>
|
6
|
+
<li><%= check_box_tag('user[role_ids][]', role.id, @user.roles.include?(role)) %>
|
7
|
+
<%= role.name %></li>
|
8
|
+
<% end %>
|
9
|
+
</ul>
|
10
|
+
|
11
|
+
<br/><br/>
|
12
|
+
|
13
|
+
<div class="record_widget">
|
14
|
+
<%= submit_tag("Update") %> |
|
15
|
+
<%= link_to("Done", ucb_security_user_path(@user)) %>
|
16
|
+
</div>
|
17
|
+
<% end %>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<h1>Edit user</h1>
|
2
|
+
|
3
|
+
<div class="ucb_rails_security_form">
|
4
|
+
<fieldset>
|
5
|
+
<legend>User Details</legend>
|
6
|
+
<% form_for([:ucb_security, @user], :builder => UcbSecurity::Builder) do |f| %>
|
7
|
+
|
8
|
+
<%= f.text_field('LDAP Uid:', :ldap_uid, :required => true) %>
|
9
|
+
<%= f.text_field('First Name:', :first_name, :required => true) %>
|
10
|
+
<%= f.text_field('Last Name:', :last_name, :required => true) %>
|
11
|
+
<%= f.text_field('Email:', :email) %>
|
12
|
+
<%= f.text_field('Phone:', :phone) %>
|
13
|
+
<%= f.text_field('Department:', :department) %>
|
14
|
+
|
15
|
+
<p>
|
16
|
+
<div class="button_widget">
|
17
|
+
<%= f.submit("Update") %> |
|
18
|
+
<%= link_to("Done", ucb_security_user_path(@user)) %>
|
19
|
+
</div>
|
20
|
+
</p>
|
21
|
+
<% end %>
|
22
|
+
</fieldset>
|
23
|
+
</div>
|
@@ -0,0 +1,43 @@
|
|
1
|
+
<h1>Listing Users</h1>
|
2
|
+
|
3
|
+
|
4
|
+
<div class="new_record_widget">
|
5
|
+
<%= link_to('New User', new_ucb_security_user_path()) %>
|
6
|
+
</div>
|
7
|
+
|
8
|
+
|
9
|
+
<table class="horizontal max_width">
|
10
|
+
<tr>
|
11
|
+
<th colspan="3" width="1%"></th>
|
12
|
+
<th>Ldap uid</th>
|
13
|
+
<th>First name</th>
|
14
|
+
<th>Last name</th>
|
15
|
+
<th>Email</th>
|
16
|
+
<th>Phone</th>
|
17
|
+
<th>Department</th>
|
18
|
+
</tr>
|
19
|
+
|
20
|
+
<% for user in @users %>
|
21
|
+
<tbody class="highlight">
|
22
|
+
<tr>
|
23
|
+
<td><%= link_to('View', ucb_security_user_path(user)) %></td>
|
24
|
+
<td><%= link_to('Edit', edit_ucb_security_user_path(user)) %></td>
|
25
|
+
<td><%= link_to('Delete', ucb_security_user_path(user), :confirm => 'Are you sure?', :method => :delete) %></td>
|
26
|
+
<td><%=h user.ldap_uid %></td>
|
27
|
+
<td><%=h user.first_name %></td>
|
28
|
+
<td><%=h user.last_name %></td>
|
29
|
+
<td><%=h user.email %></td>
|
30
|
+
<td><%=h user.phone %></td>
|
31
|
+
<td><%=h user.department %></td>
|
32
|
+
</tr>
|
33
|
+
</tbody>
|
34
|
+
<% end %>
|
35
|
+
</table>
|
36
|
+
|
37
|
+
<br />
|
38
|
+
|
39
|
+
<% if @users.size > 15 %>
|
40
|
+
<div class="new_record_widget">
|
41
|
+
<%= link_to('New User', new_ucb_security_user_path()) %>
|
42
|
+
</div>
|
43
|
+
<% end %>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<h1>New User</h1>
|
2
|
+
|
3
|
+
<p>
|
4
|
+
<%= link_to("Search Ldap for New User", ucb_security_ldap_search_url()) %>
|
5
|
+
</p>
|
6
|
+
|
7
|
+
|
8
|
+
<div class="ucb_rails_security_form">
|
9
|
+
<fieldset>
|
10
|
+
<legend>User Details</legend>
|
11
|
+
<% form_for([:ucb_security, @user], :builder => UcbSecurity::Builder) do |f| %>
|
12
|
+
|
13
|
+
<%= f.text_field('LDAP Uid:', :ldap_uid, :required => true) %>
|
14
|
+
<%= f.text_field('First Name:', :first_name, :required => true) %>
|
15
|
+
<%= f.text_field('Last Name:', :last_name, :required => true) %>
|
16
|
+
<%= f.text_field('Email:', :email) %>
|
17
|
+
<%= f.text_field('Phone:', :phone) %>
|
18
|
+
<%= f.text_field('Department:', :department) %>
|
19
|
+
|
20
|
+
<p>
|
21
|
+
<div class="button_widget">
|
22
|
+
<%= f.submit("Create") %> |
|
23
|
+
<%= link_to("Back", ucb_security_users_path) %>
|
24
|
+
</div>
|
25
|
+
</p>
|
26
|
+
<% end %>
|
27
|
+
</fieldset>
|
28
|
+
</div>
|
29
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
<h1>View User</h1>
|
2
|
+
|
3
|
+
<div class="ucb_rails_security_form">
|
4
|
+
<fieldset>
|
5
|
+
<legend>User Details</legend>
|
6
|
+
<% fields_for(@user, :builder => UcbSecurity::Builder) do |f| %>
|
7
|
+
<%= f.text_field('LDAP Uid:', :ldap_uid, {:required => true}, {:readonly => true}) %>
|
8
|
+
<%= f.text_field('First Name:', :first_name, {:required => true}, {:readonly => true}) %>
|
9
|
+
<%= f.text_field('Last Name:', :last_name, {:required => true}, {:readonly => true}) %>
|
10
|
+
<%= f.text_field('Email:', :email, {}, {:readonly => true}) %>
|
11
|
+
<%= f.text_field('Phone:', :phone, {}, {:readonly => true}) %>
|
12
|
+
<%= f.text_field('Department:', :department, {}, {:readonly => true}) %>
|
13
|
+
|
14
|
+
<p>
|
15
|
+
<div class="button_widget">
|
16
|
+
<%= button_to("Edit", edit_ucb_security_user_path(@user), :method => :get) %> |
|
17
|
+
<%= link_to("List Users", ucb_security_users_path()) %>
|
18
|
+
</div>
|
19
|
+
</p>
|
20
|
+
<% end %>
|
21
|
+
</fieldset>
|
22
|
+
</div>
|
23
|
+
|
24
|
+
<br/>
|
25
|
+
|
26
|
+
<div class="ucb_rails_security_form">
|
27
|
+
<fieldset>
|
28
|
+
<legend>User Roles</legend>
|
29
|
+
<% if @user.roles.empty? %>
|
30
|
+
<p>This user has no roles</p>
|
31
|
+
<% else %>
|
32
|
+
<ul>
|
33
|
+
<% @user.roles.each do |r| %>
|
34
|
+
<li><%= link_to(r.name, ucb_security_role_path(r)) %></li>
|
35
|
+
<% end %>
|
36
|
+
</ul>
|
37
|
+
<% end %>
|
38
|
+
|
39
|
+
<div class="button_widget">
|
40
|
+
<%= button_to("Edit", edit_ucb_security_user_roles_path(@user), :method => :get) %>
|
41
|
+
</div>
|
42
|
+
</fieldset>
|
43
|
+
</div>
|
@@ -0,0 +1,191 @@
|
|
1
|
+
class UcbRailsSecurityGenerator < Rails::Generator::Base
|
2
|
+
NAMESPACE = 'ucb_security'
|
3
|
+
TARGET_NAMESPACE = 'ucb_security'
|
4
|
+
|
5
|
+
def initialize(runtime_args, runtime_options = {})
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
def manifest
|
10
|
+
record do |m|
|
11
|
+
template_dir = File.join(File.expand_path(File.dirname(__FILE__)), "templates")
|
12
|
+
|
13
|
+
###############
|
14
|
+
# Models
|
15
|
+
#
|
16
|
+
Dir["#{template_dir}/models/*"].each do |name|
|
17
|
+
name = File.basename(name)
|
18
|
+
m.file "models/#{name}", "app/models/#{name}"
|
19
|
+
end
|
20
|
+
#####
|
21
|
+
|
22
|
+
|
23
|
+
###############
|
24
|
+
# Controllers
|
25
|
+
#
|
26
|
+
m.directory "app/controllers/#{TARGET_NAMESPACE}/"
|
27
|
+
Dir["#{template_dir}/controllers/#{NAMESPACE}/*"].each do |name|
|
28
|
+
name = File.basename(name)
|
29
|
+
m.file "controllers/#{NAMESPACE}/#{name}", "app/controllers/#{TARGET_NAMESPACE}/#{name}"
|
30
|
+
end
|
31
|
+
|
32
|
+
# Helpers
|
33
|
+
m.directory "app/helpers/#{TARGET_NAMESPACE}"
|
34
|
+
Dir["#{template_dir}/helpers/#{NAMESPACE}/*"].each do |name|
|
35
|
+
name = File.basename(name)
|
36
|
+
m.file "helpers/#{NAMESPACE}/#{name}", "app/helpers/#{TARGET_NAMESPACE}/#{name}"
|
37
|
+
end
|
38
|
+
#####
|
39
|
+
|
40
|
+
|
41
|
+
################
|
42
|
+
# Views
|
43
|
+
#
|
44
|
+
m.directory "app/views/#{TARGET_NAMESPACE}/"
|
45
|
+
m.directory "app/views/#{TARGET_NAMESPACE}/roles/"
|
46
|
+
Dir["#{template_dir}/views/#{NAMESPACE}/roles/*"].each do |name|
|
47
|
+
name = File.basename(name)
|
48
|
+
m.file "views/#{NAMESPACE}/roles/#{name}", "app/views/#{TARGET_NAMESPACE}/roles/#{name}"
|
49
|
+
end
|
50
|
+
|
51
|
+
m.directory "app/views/#{TARGET_NAMESPACE}/users/"
|
52
|
+
Dir["#{template_dir}/views/#{NAMESPACE}/users/*"].each do |name|
|
53
|
+
name = File.basename(name)
|
54
|
+
m.file "views/#{NAMESPACE}/users/#{name}", "app/views/#{TARGET_NAMESPACE}/users/#{name}"
|
55
|
+
end
|
56
|
+
|
57
|
+
m.directory "app/views/#{TARGET_NAMESPACE}/user_roles/"
|
58
|
+
Dir["#{template_dir}/views/#{NAMESPACE}/user_roles/*"].each do |name|
|
59
|
+
name = File.basename(name)
|
60
|
+
m.file "views/#{NAMESPACE}/user_roles/#{name}", "app/views/#{TARGET_NAMESPACE}/user_roles/#{name}"
|
61
|
+
end
|
62
|
+
|
63
|
+
m.directory "app/views/#{TARGET_NAMESPACE}/role_users/"
|
64
|
+
Dir["#{template_dir}/views/#{NAMESPACE}/role_users/*"].each do |name|
|
65
|
+
name = File.basename(name)
|
66
|
+
m.file "views/#{NAMESPACE}/role_users/#{name}", "app/views/#{TARGET_NAMESPACE}/role_users/#{name}"
|
67
|
+
end
|
68
|
+
|
69
|
+
m.directory "app/views/#{TARGET_NAMESPACE}/role_users/"
|
70
|
+
Dir["#{template_dir}/views/#{NAMESPACE}/role_users/*"].each do |name|
|
71
|
+
name = File.basename(name)
|
72
|
+
m.file "views/#{NAMESPACE}/role_users/#{name}", "app/views/#{TARGET_NAMESPACE}/role_users/#{name}"
|
73
|
+
end
|
74
|
+
|
75
|
+
m.directory "app/views/#{TARGET_NAMESPACE}/ldap_search/"
|
76
|
+
Dir["#{template_dir}/views/#{NAMESPACE}/ldap_search/*"].each do |name|
|
77
|
+
name = File.basename(name)
|
78
|
+
m.file "views/#{NAMESPACE}/ldap_search/#{name}", "app/views/#{TARGET_NAMESPACE}/ldap_search/#{name}"
|
79
|
+
end
|
80
|
+
#####
|
81
|
+
|
82
|
+
|
83
|
+
###############
|
84
|
+
# Layouts
|
85
|
+
#
|
86
|
+
m.directory "app/views/layouts/#{TARGET_NAMESPACE}"
|
87
|
+
Dir["#{template_dir}/views/layouts/#{NAMESPACE}/*"].each do |name|
|
88
|
+
name = File.basename(name)
|
89
|
+
m.file "views/layouts/#{NAMESPACE}/#{name}", "app/views/layouts/#{TARGET_NAMESPACE}/#{name}"
|
90
|
+
end
|
91
|
+
#####
|
92
|
+
|
93
|
+
|
94
|
+
###############
|
95
|
+
# Stylesheets
|
96
|
+
#
|
97
|
+
m.file "stylesheets/#{NAMESPACE}.css", "public/stylesheets/#{TARGET_NAMESPACE}.css"
|
98
|
+
#####
|
99
|
+
|
100
|
+
|
101
|
+
###############
|
102
|
+
# Javascripts
|
103
|
+
#
|
104
|
+
m.file "javascripts/ucb_security.js", "public/javascripts/ucb_security.js"
|
105
|
+
#####
|
106
|
+
|
107
|
+
|
108
|
+
###############
|
109
|
+
# Initializers
|
110
|
+
#
|
111
|
+
m.directory "config"
|
112
|
+
m.directory "config/initializers"
|
113
|
+
m.file "initializers/ucb_security_config.rb", "config/initializers/ucb_security_config.rb"
|
114
|
+
#####
|
115
|
+
|
116
|
+
|
117
|
+
###############
|
118
|
+
# Migrations
|
119
|
+
#
|
120
|
+
m.directory "db/migrate"
|
121
|
+
m.file "db/migrate/xxx_create_ucb_rails_security_tables.rb", "db/migrate/#{next_migration}_create_ucb_rails_security_tables.rb"
|
122
|
+
#####
|
123
|
+
|
124
|
+
|
125
|
+
###############
|
126
|
+
# Routes
|
127
|
+
#
|
128
|
+
write_named_routes_to_route_file
|
129
|
+
#####
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
private
|
134
|
+
def pad_zeros(str, num_of_zeros)
|
135
|
+
if str.length == num_of_zeros
|
136
|
+
return str
|
137
|
+
else
|
138
|
+
pad_zeros("0".concat(str), num_of_zeros)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def latest_migration
|
143
|
+
num = 0
|
144
|
+
unless migrations.empty?
|
145
|
+
migrations.last =~ /^([0-9]+)_/
|
146
|
+
num = $1
|
147
|
+
end
|
148
|
+
raise(Exception, "Unable to determine latest migration: #{migrations.last}") unless num
|
149
|
+
num.to_i
|
150
|
+
end
|
151
|
+
|
152
|
+
def next_migration
|
153
|
+
pad_zeros((latest_migration + 1).to_s, 3)
|
154
|
+
end
|
155
|
+
|
156
|
+
def migrations
|
157
|
+
Dir["#{RAILS_ROOT}/db/migrate/*"].map { |f| File.basename(f) }
|
158
|
+
end
|
159
|
+
|
160
|
+
def write_named_routes_to_route_file
|
161
|
+
ucb_security_routes = <<-ROUTE
|
162
|
+
map.ucb_security '/ucb_security', :controller => 'ucb_security/users'
|
163
|
+
map.logout '/logout', :controller => 'ucb_security/base', :action => 'logout'
|
164
|
+
map.not_authorized '/not_authorized', :controller => 'ucb_security/base', :action => 'not_authorized'
|
165
|
+
|
166
|
+
map.namespace(:ucb_security) do |ucb_security|
|
167
|
+
ucb_security.resources :roles do |roles|
|
168
|
+
roles.resource :users, :controller => 'role_users'
|
169
|
+
end
|
170
|
+
|
171
|
+
ucb_security.resources :users do |users|
|
172
|
+
users.resource :roles, :controller => 'user_roles'
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
map.ucb_security_ldap_search '/ucb_security/ldap_search',
|
177
|
+
:controller => 'ucb_security/ldap_search', :action => 'index'
|
178
|
+
ROUTE
|
179
|
+
|
180
|
+
sentinel = 'ActionController::Routing::Routes.draw do |map|'
|
181
|
+
gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
|
182
|
+
"#{match}\n # START ucb_rails_security routes: \n #{ucb_security_routes}\n # END ucb_rails_security routes:\n"
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def gsub_file(relative_destination, regexp, *args, &block)
|
187
|
+
path = destination_path(relative_destination)
|
188
|
+
content = File.read(path).gsub(regexp, *args, &block)
|
189
|
+
File.open(path, 'wb') { |file| file.write(content) }
|
190
|
+
end
|
191
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# Include hook code here
|
2
|
+
require 'ucb_rails_security'
|
3
|
+
require 'ucb_rails_security_casauthentication'
|
4
|
+
require 'ucb_rs_controller_methods'
|
5
|
+
require 'helpers/rspec_helpers'
|
6
|
+
require 'ucb_rails_security_logger'
|
7
|
+
|
8
|
+
UCB::Rails::Security.logger = UCB::Rails::Security::Logger.new("#{RAILS_ROOT}/log/ucb_security_#{RAILS_ENV}.log")
|
9
|
+
UCB::Rails::Security.logger.formatter = UCB::Rails::Security::Logger::Formatter.new
|