lockdown 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.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2008-04-18
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 FIXME full name
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/Manifest.txt ADDED
@@ -0,0 +1,39 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ PostInstall.txt
5
+ README
6
+ README.txt
7
+ Rakefile
8
+ app_generators/lockdown/USAGE
9
+ app_generators/lockdown/lockdown_generator.rb
10
+ app_generators/lockdown/lockdown_generator.rb.orig
11
+ app_generators/lockdown/templates/access.rb
12
+ app_generators/lockdown/templates/session.rb
13
+ bin/lockdown
14
+ config/hoe.rb
15
+ config/requirements.rb
16
+ lib/lockdown.rb
17
+ lib/lockdown/controller.rb
18
+ lib/lockdown/controller_inspector.rb
19
+ lib/lockdown/helper.rb
20
+ lib/lockdown/model.rb
21
+ lib/lockdown/version.rb
22
+ lib/lockdown/view.rb
23
+ script/console
24
+ script/destroy
25
+ script/generate
26
+ script/txt2html
27
+ setup.rb
28
+ tasks/deployment.rake
29
+ tasks/environment.rake
30
+ tasks/website.rake
31
+ test/test_generator_helper.rb
32
+ test/test_helper.rb
33
+ test/test_lockdown.rb
34
+ test/test_lockdown_generator.rb
35
+ website/index.html
36
+ website/index.txt
37
+ website/javascripts/rounded_corners_lite.inc.js
38
+ website/stylesheets/screen.css
39
+ website/template.html.erb
data/PostInstall.txt ADDED
@@ -0,0 +1,3 @@
1
+
2
+ For more information on lockdown, see http://lockdown.rubyforge.org
3
+
data/README ADDED
File without changes
data/README.txt ADDED
@@ -0,0 +1,60 @@
1
+ = lockdown
2
+
3
+ http://lockdown.rubyforge.org
4
+
5
+ == DESCRIPTION:
6
+
7
+ Lockdown is a authentication/authorization system for RubyOnRails and Merb.
8
+
9
+ For more information please visit the rubyforge site.
10
+
11
+ == REQUIREMENTS:
12
+
13
+ Lockdown currently supports:
14
+
15
+ Frameworks: RubyOnRails or Merb
16
+
17
+ ORMs: ActiveRecord or DataMapper
18
+
19
+ == INSTALL:
20
+
21
+ # Install the gem
22
+
23
+ sudo gem install lockdown
24
+
25
+ # Go to your application root directory
26
+
27
+ cd <your application>
28
+
29
+ # Install lockdown to your application
30
+
31
+ lockdown .
32
+
33
+ # Modify lib/lockdown/access.rb to grant access to your application
34
+
35
+ # Modify lib/lockdown/session.rb to add/remove session information
36
+
37
+ == LICENSE:
38
+
39
+ (The MIT License)
40
+
41
+ Copyright (c) 2008 Andrew Stone
42
+
43
+ Permission is hereby granted, free of charge, to any person obtaining
44
+ a copy of this software and associated documentation files (the
45
+ 'Software'), to deal in the Software without restriction, including
46
+ without limitation the rights to use, copy, modify, merge, publish,
47
+ distribute, sublicense, and/or sell copies of the Software, and to
48
+ permit persons to whom the Software is furnished to do so, subject to
49
+ the following conditions:
50
+
51
+ The above copyright notice and this permission notice shall be
52
+ included in all copies or substantial portions of the Software.
53
+
54
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
55
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
56
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
57
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
58
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
59
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
60
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
@@ -0,0 +1,5 @@
1
+ Description:
2
+
3
+
4
+ Usage:
5
+
@@ -0,0 +1,25 @@
1
+ class LockdownGenerator < RubiGen::Base
2
+
3
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
4
+ Config::CONFIG['ruby_install_name'])
5
+
6
+ default_options :author => "Andrew Stone"
7
+
8
+ attr_reader :name, :framework
9
+
10
+ def initialize(runtime_args, runtime_options = {})
11
+ super
12
+ usage if args.empty?
13
+ @destination_root = File.expand_path(args.shift)
14
+ @name = base_name
15
+ @framework = runtime_options[:framework]
16
+ end
17
+
18
+ def manifest
19
+ record do |m|
20
+ m.directory "lib/lockdown"
21
+ m.template "session.rb", "lib/lockdown/session.rb"
22
+ m.file "access.rb", "lib/lockdown/access.rb"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,69 @@
1
+ class LockdownGenerator < RubiGen::Base
2
+
3
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
4
+ Config::CONFIG['ruby_install_name'])
5
+
6
+ default_options :author => nil
7
+
8
+ attr_reader :name
9
+
10
+ def initialize(runtime_args, runtime_options = {})
11
+ super
12
+ usage if args.empty?
13
+ @destination_root = File.expand_path(args.shift)
14
+ @name = base_name
15
+ extract_options
16
+ end
17
+
18
+ def manifest
19
+ record do |m|
20
+ # Ensure appropriate folder(s) exists
21
+ m.directory ''
22
+ BASEDIRS.each { |path| m.directory path }
23
+
24
+ # Create stubs
25
+ # m.template "template.rb", "some_file_after_erb.rb"
26
+ # m.file "file", "some_file_copied"
27
+
28
+ m.dependency "install_rubigen_scripts", [destination_root, 'lockdown'],
29
+ :shebang => options[:shebang], :collision => :force
30
+ end
31
+ end
32
+
33
+ protected
34
+ def banner
35
+ <<-EOS
36
+ Creates a ...
37
+
38
+ USAGE: #{spec.name} name
39
+ EOS
40
+ end
41
+
42
+ def add_options!(opts)
43
+ opts.separator ''
44
+ opts.separator 'Options:'
45
+ # For each option below, place the default
46
+ # at the top of the file next to "default_options"
47
+ # opts.on("-a", "--author=\"Your Name\"", String,
48
+ # "Some comment about this option",
49
+ # "Default: none") { |options[:author]| }
50
+ opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
51
+ end
52
+
53
+ def extract_options
54
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
55
+ # Templates can access these value via the attr_reader-generated methods, but not the
56
+ # raw instance variable value.
57
+ # @author = options[:author]
58
+ end
59
+
60
+ # Installation skeleton. Intermediate directories are automatically
61
+ # created so don't sweat their absence here.
62
+ BASEDIRS = %w(
63
+ lib
64
+ log
65
+ script
66
+ test
67
+ tmp
68
+ )
69
+ end
@@ -0,0 +1,108 @@
1
+ require "lockdown"
2
+
3
+ module Lockdown
4
+ #
5
+ #
6
+ # Permissions are used to group access rights into logical components.
7
+ # Each method defined in the Permissions module represents an array
8
+ # of methods from a controller (or multiple controllers.)
9
+ #
10
+ # Controller methods available are:
11
+ #
12
+ # # Returns all methods from all controllers
13
+ # all_controllers
14
+ #
15
+ # # Returns all methods from all controllers listed
16
+ # all_methods :controller1, controller2, ...
17
+ #
18
+ # # For a single controller, returns only methods listed
19
+ # only_methods :controller1, :method1, :method2, ...
20
+ #
21
+ # # For a single controller, returns all methods except the methods listed
22
+ # all_except_methods :controller1, :method1, :method2, ...
23
+ #
24
+ # They all return an array of controller/action. For example, if you had a
25
+ # standard REST controller called products this would be the result:
26
+ #
27
+ #
28
+ # all_methods :products => [ "products/index , "products/show",
29
+ # "products/new", "products/edit",
30
+ # "products/create", "products/update",
31
+ # "products/destroy"]
32
+ #
33
+ module Permissions
34
+ class << self
35
+
36
+ def sessions_management
37
+ # all_methods :sessions
38
+ end
39
+
40
+ end # end class block
41
+ end # end Permissions module
42
+
43
+ #
44
+ # UserGroups are used to group Permissions together to define role type
45
+ # functionality. Users may belong to multiple groups.
46
+ #
47
+ module UserGroups
48
+ class << self
49
+ #
50
+ # This method defines which UserGroups cannot be managed
51
+ # via the management screens.
52
+ #
53
+ # Users can still be assigned to these groups.
54
+ #
55
+ def private_records
56
+ [:administrators]
57
+ end
58
+ #
59
+ # This method defines which UserGroups have limited access
60
+ # via the management screens. Deletion is not allowed.
61
+ #
62
+ # Users can still be assigned to these groups.
63
+ #
64
+ def protected_records
65
+ [:public_access, :registered_users]
66
+ end
67
+
68
+ # ** The administrator method is "special", please don't rename.
69
+ # If you remove/rename, etc... YOU WILL BREAK STUFF
70
+ #
71
+ # Standard administrator user group.
72
+ # Please don't alter without careful consideration.
73
+ #
74
+ def administrators
75
+ [:all]
76
+ end
77
+
78
+ # ** The public_access method is "special", please don't rename.
79
+ # If you remove/rename, etc... YOU WILL BREAK STUFF
80
+ #
81
+ # Standard public_access user group.
82
+ #
83
+ # Feel free to add Permissions to the array without issue.
84
+ #
85
+ # **Notice: All permissions added to this public_access group will not be
86
+ # restricted to logged in users.
87
+ # So be careful what you add here!
88
+ #
89
+ def public_access
90
+ [:sessions_management]
91
+ end
92
+
93
+ # ** The registered_users method is "special", please don't rename.
94
+ # Not as special as the others, but still...
95
+ #
96
+ # All newly created users are assigned to this User Group by default
97
+ #
98
+ def registered_users
99
+ #[:my_account]
100
+ end
101
+
102
+ #
103
+ # Define your own user groups below
104
+ #
105
+
106
+ end # end class block
107
+ end # end UserGroups module
108
+ end # end Lockdown module
@@ -0,0 +1,72 @@
1
+ module Lockdown
2
+ # 1 hour
3
+ SESSION_TIMEOUT = 60 * 60
4
+
5
+ #
6
+ # The Lockdown gem defines additional Session methods:
7
+ #
8
+ # current_user_is_admin?: returns true if user is assigned
9
+ # administrator rights.
10
+ #
11
+ # nil_lockdown_values: This will nil all session values starting with
12
+ # user_ or access_ or expiry
13
+ #
14
+ # current_user_access_in_group?(grp): grp is a symbol referencing a
15
+ # Lockdown::UserGroups method such as :registered_users
16
+ # Will return true if the session[:access_rights] contain at
17
+ # least one match to the access_right list associated to the group
18
+ #
19
+ module Session
20
+ protected
21
+
22
+ def set_session_user(user)
23
+ if user.nil?
24
+ nil_lockdown_values
25
+ return
26
+ end
27
+ session[:user_id] = user.id
28
+ session[:user_name] = user.full_name
29
+ session[:user_profile_id] = user.profile.id
30
+
31
+ #
32
+ # If you remove this method, you will not gain access to any
33
+ # protected resources
34
+ #
35
+ add_lockdown_session_values(user)
36
+ end
37
+
38
+ def logged_in?
39
+ current_user_id > 0
40
+ end
41
+
42
+ def current_user_id
43
+ return session[:user_id] || -1
44
+ end
45
+
46
+ def current_user_name
47
+ session[:user_name]
48
+ end
49
+
50
+ def current_profile_id
51
+ return session[:user_profile_id] || -1
52
+ end
53
+
54
+ def current_user
55
+ return User.find(current_user_id, :include => [:profile, :user_groups])
56
+ end
57
+
58
+ end # Session module
59
+ end # Lockdown module
60
+
61
+ <% if framework == "merb" -%>
62
+ Merb::Controller.send :include, Lockdown::Session
63
+ <% else %>
64
+ ActionController::Base.send :include, Lockdown::Session
65
+ ActionController::Base.send :helper_method, :logged_in?,
66
+ :current_user,
67
+ :current_user_name,
68
+ :current_user_id,
69
+ :current_profile_id,
70
+ :current_user_is_admin?,
71
+ :current_user_access_in_group?
72
+ <% end -%>
data/bin/lockdown ADDED
@@ -0,0 +1,140 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubygems"
4
+ require "rubigen"
5
+ require "rubigen/scripts/generate"
6
+ require 'optparse'
7
+
8
+ #require File.join(File.dirname(__FILE__), "..", "lib", "lockdown_generator")
9
+
10
+ #
11
+ # Created on 2008-4-21.
12
+ # Copyright (c) 2008. All rights reserved.
13
+
14
+ MERB_CONFIG = 'config/init.rb'
15
+ RAILS_CONFIG = 'config/environment.rb'
16
+
17
+ if File.exists?(MERB_CONFIG)
18
+ @framework = "merb"
19
+ elsif File.exists?(RAILS_CONFIG)
20
+ @framework = "rails"
21
+ else
22
+ raise NotImplementedError, "Configuration file not found. Looking for init.rb (Merb) or environment.rb (Rails)"
23
+ end
24
+
25
+ def merb_app?
26
+ @framework == "merb"
27
+ end
28
+
29
+ def rails_app?
30
+ @framework == "rails"
31
+ end
32
+
33
+ #
34
+ # Right now we only have the two and we raise an exception
35
+ # if we don't know prior to getting here..
36
+ #
37
+ def config_file
38
+ if merb_app?
39
+ MERB_CONFIG
40
+ else
41
+ RAILS_CONFIG
42
+ end
43
+ end
44
+
45
+ begin
46
+ require 'rubygems'
47
+ rescue LoadError
48
+ # no rubygems to load, so we fail silently
49
+ end
50
+
51
+
52
+ OPTIONS = {
53
+ :path => File.expand_path('.')
54
+ }
55
+
56
+ parser = OptionParser.new do |opts|
57
+ opts.banner = <<-BANNER
58
+ Lockdown will add access.rb and session.rb to the lib/lockdown directory and require them in #{config_file}.
59
+
60
+ Usage: #{File.basename($0)} [options]
61
+
62
+ Options are:
63
+ BANNER
64
+
65
+ opts.separator ""
66
+ opts.on("-p", "--path=PATH", String,
67
+ "The root path for selecting files",
68
+ "Default: [current directory]") { |OPTIONS[:path]| }
69
+ opts.on("-h", "--help",
70
+ "Show this help message.") { puts opts; exit }
71
+ opts.parse!(ARGV)
72
+ end
73
+
74
+ #
75
+ # Load up the config file contents
76
+ #
77
+ @configuration = File.open config_file do |f|
78
+ f.map {|line| line.chomp}
79
+ end
80
+
81
+ def configuration_file_has?(req)
82
+ @configuration.include?(req)
83
+ end
84
+
85
+ puts <<-MSG
86
+ \n------------------------------------------------------------
87
+ Installing Lockdown
88
+ MSG
89
+
90
+ begin
91
+ source = RubiGen::PathSource.new(:application,
92
+ File.join(File.dirname(__FILE__), "../app_generators"))
93
+ RubiGen::Base.reset_sources
94
+ RubiGen::Base.append_sources source
95
+ RubiGen::Scripts::Generate.new.run(ARGV, :generator => 'lockdown', :framework => @framework)
96
+
97
+ File.open(config_file, "a") do |f|
98
+ require_access = %Q(require "lockdown/access")
99
+ require_session = %Q(require "lockdown/session")
100
+
101
+ f << %Q(\n#{require_access}\n) unless configuration_file_has?(require_access)
102
+
103
+ f << %Q(#{require_session}\n\n) unless configuration_file_has?(require_session)
104
+ end
105
+ rescue Exception => e
106
+ puts e.backtrace.join("\n")
107
+ raise e
108
+ end
109
+
110
+ puts <<-MSG
111
+ ------------------------------------------------------------\n
112
+ MSG
113
+
114
+ puts <<-MSG
115
+ \n------------------------------------------------------------
116
+ Modified #{config_file} by adding:
117
+ require "lockdown/access"
118
+ require "lockdown/session"
119
+ ------------------------------------------------------------\n
120
+ MSG
121
+
122
+ puts <<-MSG
123
+ \n------------------------------------------------------------
124
+ You are now locked down. To open up access to your application
125
+ please modify lib/lockdown/access.rb. This is where you'll
126
+ add permissions and create user groups.
127
+
128
+ To modify the contents of your session and to add access
129
+ methods, modify lib/lockdown/session.rb.
130
+
131
+ If you want to know more, please visit:
132
+
133
+ http://lockdown.rubyforge.org
134
+
135
+ If you have any suggestions, comments or issues
136
+ please visit the Lockdown Google group:
137
+
138
+ http://groups.google.com/group/stonean_lockdown?hl=en
139
+ ------------------------------------------------------------\n
140
+ MSG
data/config/hoe.rb ADDED
@@ -0,0 +1,73 @@
1
+ require 'lockdown/version'
2
+
3
+ AUTHOR = 'FIXME full name' # can also be an array of Authors
4
+ EMAIL = "FIXME email"
5
+ DESCRIPTION = "description of gem"
6
+ GEM_NAME = 'lockdown' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'lockdown' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+ EXTRA_DEPENDENCIES = [
11
+ # ['activesupport', '>= 1.3.1']
12
+ ] # An array of rubygem dependencies [name, version]
13
+
14
+ @config_file = "~/.rubyforge/user-config.yml"
15
+ @config = nil
16
+ RUBYFORGE_USERNAME = "unknown"
17
+ def rubyforge_username
18
+ unless @config
19
+ begin
20
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
21
+ rescue
22
+ puts <<-EOS
23
+ ERROR: No rubyforge config file found: #{@config_file}
24
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
25
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
26
+ EOS
27
+ exit
28
+ end
29
+ end
30
+ RUBYFORGE_USERNAME.replace @config["username"]
31
+ end
32
+
33
+
34
+ REV = nil
35
+ # UNCOMMENT IF REQUIRED:
36
+ # REV = YAML.load(`svn info`)['Revision']
37
+ VERS = Lockdown::VERSION::STRING + (REV ? ".#{REV}" : "")
38
+ RDOC_OPTS = ['--quiet', '--title', 'lockdown documentation',
39
+ "--opname", "index.html",
40
+ "--line-numbers",
41
+ "--main", "README",
42
+ "--inline-source"]
43
+
44
+ class Hoe
45
+ def extra_deps
46
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
47
+ @extra_deps
48
+ end
49
+ end
50
+
51
+ # Generate all the Rake tasks
52
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
53
+ $hoe = Hoe.new(GEM_NAME, VERS) do |p|
54
+ p.developer(AUTHOR, EMAIL)
55
+ p.description = DESCRIPTION
56
+ p.summary = DESCRIPTION
57
+ p.url = HOMEPATH
58
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
59
+ p.test_globs = ["test/**/test_*.rb"]
60
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
61
+
62
+ # == Optional
63
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
64
+ #p.extra_deps = EXTRA_DEPENDENCIES
65
+
66
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
67
+ end
68
+
69
+ CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
70
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
71
+ $hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
72
+ $hoe.rsync_args = '-av --delete --ignore-errors'
73
+ $hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
@@ -0,0 +1,15 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))