Permalink
Browse files

Copied and updated Lockdown 2.0.4.

  • Loading branch information...
0 parents commit 2001678198e11c5eacbcb968512ad86dc32c67e1 @maji-mobile maji-mobile committed May 10, 2012
@@ -0,0 +1,7 @@
+*.DS_Store
+*.swp
+.yardoc/**
+pkg/**
+doc/**
+email.txt
+coverage/**
@@ -0,0 +1,42 @@
+## Description
+
+**Lockdown 2.0.x does not support a Rails application that is deployed to a subdirectory, although Lockdown 1.x did.
+It looks like Lockdown is no longer maintained by Andy Stone since it has been removed from github.
+Therefore we use updated Lockdown 2.0.4, renamed it and added it to github.**
+
+Lockdown is an authorization system for RubyOnRails. It is designed to handle a simple public vs private configuration to very fine grained access controls.
+
+If you are starting a site and just have public and protected (user required) areas, use Lockdown. Lockdown includes built in user groups of public and protected. From there you can easily add/extend permissions and create new user groups as your site needs grow.
+
+If you already have a complex permission scheme, use Lockdown to simplify the management of access rules.
+
+Follow me on Twitter (@stonean) to keep up to date.
+
+## DOCS:
+
+ [http://docs.stonean.com/page/lockdown](http://docs.stonean.com/page/lockdown)
+
+## LICENSE:
+
+(The MIT License)
+
+Copyright (c) 2010 Andrew Stone
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,55 @@
+require 'rubygems'
+require 'rake'
+
+require File.join(File.dirname(__FILE__), "lib", "lockdown")
+
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gem|
+ gem.name = "lockdown"
+ gem.version = Lockdown.version
+ gem.rubyforge_project = "lockdown"
+ gem.summary = "Authorization system for Rails"
+ gem.description = "Restrict access to your controller actions. "
+ gem.email = "andy@stonean.com"
+ gem.homepage = "https://github.com/ludo/patrick-lockdown"
+ gem.authors = ["Andrew Stone", "Patrick Baselier"]
+ end
+ Jeweler::GemcutterTasks.new
+rescue LoadError
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
+end
+
+begin
+ require 'yard'
+ YARD::Rake::YardocTask.new do |t|
+ t.files = FileList['lib/**/*.rb']
+ t.options = ['-r'] # optional
+ end
+rescue LoadError
+ task :yard do
+ abort "YARD is not available. In order to run yard, you must: sudo gem install yard"
+ end
+end
+
+require 'rake/testtask'
+Rake::TestTask.new(:test) do |test|
+ test.libs << 'lib' << 'test'
+ test.pattern = 'test/**/test_*.rb'
+ test.verbose = true
+end
+
+begin
+ require 'rcov/rcovtask'
+ Rcov::RcovTask.new do |test|
+ test.libs << 'test'
+ test.pattern = 'test/**/test_*.rb'
+ test.verbose = true
+ end
+rescue LoadError
+ task :rcov do
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install rcov"
+ end
+end
+
+task :default => 'test'
@@ -0,0 +1,42 @@
+# encoding: utf-8
+
+$:.unshift File.dirname(__FILE__)
+
+require 'logger'
+
+require File.join("lockdown", "errors")
+require File.join("lockdown", "helper")
+require File.join("lockdown", "configuration")
+require File.join("lockdown", "session")
+require File.join("lockdown", "delivery")
+require File.join("lockdown", "resource")
+require File.join("lockdown", "permission")
+require File.join("lockdown", "user_group")
+require File.join("lockdown", "access")
+require File.join("lockdown", "database")
+
+
+module Lockdown
+ extend Lockdown::Helper
+
+ class << self
+ attr_accessor :logger
+
+ # @return the version string for the library.
+ def version
+ '2.0.4'
+ end
+
+ def rails_mixin
+ require File.join("lockdown", "frameworks", "rails")
+ include Lockdown::Frameworks::Rails
+
+ require File.join("lockdown", "orms", "active_record")
+ include Lockdown::Orms::ActiveRecord
+ end
+
+ end # class block
+
+ self.logger = Logger.new(STDOUT)
+
+end # Lockdown
@@ -0,0 +1,108 @@
+# encoding: utf-8
+
+module Lockdown
+ module Access
+ # Define permision that defines how your application is accessed.
+ # # All methods on the site resource will be open to users who have
+ # # this permission.
+ # permission :public_pages do
+ # resource :site
+ # end
+ #
+ # # Can use multiple resource statements
+ # permission :public_pages do
+ # resource :site
+ # resource :posts
+ # end
+ #
+ # # Only methods show, edit and update on the users resource will
+ # # be open to users who have this permission.
+ # permission :my_account_pages do
+ # resource :users do
+ # only :show, :edit, :update
+ # end
+ # end
+ #
+ # # All methods except destroy on the users resource will be
+ # # open to users who have this permission.
+ # permission :manage_users do
+ # resource :users do
+ # except :destroy
+ # end
+ # end
+ #
+ # @param [String,Symbol] name permission reference.
+ # @yield [Lockdown::Permission.new(name)] new permission object
+ def permission(name, &block)
+ permission = Lockdown::Permission.new(name)
+ if block_given?
+ permission.instance_eval(&block)
+ else
+ permission.resource(permission.name)
+ end
+
+ unless Lockdown::Configuration.has_permission?(permission)
+ Lockdown::Configuration.permissions << permission
+ end
+
+ permission
+ end
+
+ # Define which permissions are accessible to everyone
+ # public_access :site, :user_registration
+ #
+ # @param *[String,Symbol] permissions that are accessible to everyone
+ def public_access(*permissions)
+ permissions.each do |name|
+ Lockdown::Configuration.make_permission_public(name)
+ end
+
+ Lockdown::Configuration.public_access = regexes(permissions)
+ end
+
+ # Define which permissions are accessible to everyone
+ # protected_access :my_account, :site_administration
+ #
+ # @param *[String,Symbol] permissions that are accessbile to authenticated users
+ def protected_access(*permissions)
+ permissions.each do |name|
+ Lockdown::Configuration.make_permission_protected(name)
+ end
+
+ Lockdown::Configuration.protected_access = regexes(permissions)
+ end
+
+ # Create user group by giving it a name and a list of permission names.
+ # @param [String, Array] user group name, permission names
+ def user_group(name, *permissions)
+ return if permissions.empty?
+ name = name.to_s
+ ug = Lockdown::Configuration.find_or_create_user_group(name)
+
+ permissions.each do |name|
+ if (perm = Lockdown::Configuration.permission(name))
+ ug.permissions << perm unless ug.permissions.include?(perm)
+ end
+ end
+
+ Lockdown::Configuration.maybe_add_user_group(ug)
+ end
+
+ # Method called by Lockdown::Delivery to trigger parsing of class methods
+ def configure
+ unless Lockdown::Configuration.configured
+ Lockdown::Database.sync_with_db unless Lockdown::Configuration.skip_sync?
+ Lockdown::Configuration.configured = true
+ end
+ end
+
+ private
+
+ def regexes(permissions)
+ permissions.collect!{|p| p.to_s}
+ perms = Lockdown::Configuration.permissions.select{|p| permissions.include?(p.name)}
+ perms.collect{|p| p.regex_pattern}.join("|")
+ end
+
+ end # Access
+end # Lockdown
Oops, something went wrong.

0 comments on commit 2001678

Please sign in to comment.