aker-confident 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ .rvmrc
5
+ spec/assets/*.db
6
+
7
+
8
+ testbed/log/*.log
9
+ testbed/db/*
10
+ testbed/.bundle
11
+ testbed/*
@@ -0,0 +1 @@
1
+ ree-1.8.7-2011.03
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+ source "http://download.bioinformatics.northwestern.edu/gems/"
3
+
4
+ # Specify your gem's dependencies in confident.gemspec
5
+ gemspec
6
+
7
+ gem 'ruby-debug'
@@ -0,0 +1,159 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ aker-confident (0.1.0)
5
+ aker
6
+ aker-rails
7
+ haml
8
+ schema_qualified_tables
9
+ sinatra
10
+
11
+ GEM
12
+ remote: http://rubygems.org/
13
+ remote: http://download.bioinformatics.northwestern.edu/gems/
14
+ specs:
15
+ abstract (1.0.0)
16
+ actionmailer (3.0.11)
17
+ actionpack (= 3.0.11)
18
+ mail (~> 2.2.19)
19
+ actionpack (3.0.11)
20
+ activemodel (= 3.0.11)
21
+ activesupport (= 3.0.11)
22
+ builder (~> 2.1.2)
23
+ erubis (~> 2.6.6)
24
+ i18n (~> 0.5.0)
25
+ rack (~> 1.2.1)
26
+ rack-mount (~> 0.6.14)
27
+ rack-test (~> 0.5.7)
28
+ tzinfo (~> 0.3.23)
29
+ activemodel (3.0.11)
30
+ activesupport (= 3.0.11)
31
+ builder (~> 2.1.2)
32
+ i18n (~> 0.5.0)
33
+ activerecord (3.0.11)
34
+ activemodel (= 3.0.11)
35
+ activesupport (= 3.0.11)
36
+ arel (~> 2.0.10)
37
+ tzinfo (~> 0.3.23)
38
+ activeresource (3.0.11)
39
+ activemodel (= 3.0.11)
40
+ activesupport (= 3.0.11)
41
+ activesupport (3.0.11)
42
+ aker (3.0.3)
43
+ activesupport (>= 2.3.0)
44
+ castanet (~> 1.0.0)
45
+ i18n (~> 0.4)
46
+ net-ldap (~> 0.1.1)
47
+ rubytree (~> 0.7.0)
48
+ warden (~> 1.0)
49
+ aker-rails (3.0.2)
50
+ aker (~> 3.0)
51
+ rails (~> 3.0, >= 3.0.4)
52
+ arel (2.0.10)
53
+ builder (2.1.2)
54
+ capybara (0.3.7)
55
+ culerity (>= 0.2.4)
56
+ mime-types (>= 1.16)
57
+ nokogiri (>= 1.3.3)
58
+ rack (>= 1.0.0)
59
+ rack-test (>= 0.5.2)
60
+ selenium-webdriver (>= 0.0.3)
61
+ castanet (1.0.1)
62
+ childprocess (0.3.1)
63
+ ffi (~> 1.0.6)
64
+ columnize (0.3.6)
65
+ culerity (0.2.15)
66
+ diff-lcs (1.1.3)
67
+ erubis (2.6.6)
68
+ abstract (>= 1.0.0)
69
+ ffi (1.0.11)
70
+ haml (3.1.4)
71
+ i18n (0.5.0)
72
+ json (1.6.5)
73
+ linecache (0.46)
74
+ rbx-require-relative (> 0.0.4)
75
+ mail (2.2.19)
76
+ activesupport (>= 2.3.6)
77
+ i18n (>= 0.4.0)
78
+ mime-types (~> 1.16)
79
+ treetop (~> 1.4.8)
80
+ mime-types (1.17.2)
81
+ multi_json (1.0.4)
82
+ net-ldap (0.1.1)
83
+ nokogiri (1.5.0)
84
+ polyglot (0.3.3)
85
+ rack (1.2.5)
86
+ rack-mount (0.6.14)
87
+ rack (>= 1.0.0)
88
+ rack-test (0.5.7)
89
+ rack (>= 1.0)
90
+ rails (3.0.11)
91
+ actionmailer (= 3.0.11)
92
+ actionpack (= 3.0.11)
93
+ activerecord (= 3.0.11)
94
+ activeresource (= 3.0.11)
95
+ activesupport (= 3.0.11)
96
+ bundler (~> 1.0)
97
+ railties (= 3.0.11)
98
+ railties (3.0.11)
99
+ actionpack (= 3.0.11)
100
+ activesupport (= 3.0.11)
101
+ rake (>= 0.8.7)
102
+ rdoc (~> 3.4)
103
+ thor (~> 0.14.4)
104
+ rake (0.9.2.2)
105
+ rbx-require-relative (0.0.5)
106
+ rdoc (3.12)
107
+ json (~> 1.4)
108
+ rspec (2.8.0)
109
+ rspec-core (~> 2.8.0)
110
+ rspec-expectations (~> 2.8.0)
111
+ rspec-mocks (~> 2.8.0)
112
+ rspec-core (2.8.0)
113
+ rspec-expectations (2.8.0)
114
+ diff-lcs (~> 1.1.2)
115
+ rspec-mocks (2.8.0)
116
+ rspec-rails (2.8.1)
117
+ actionpack (>= 3.0)
118
+ activesupport (>= 3.0)
119
+ railties (>= 3.0)
120
+ rspec (~> 2.8.0)
121
+ ruby-debug (0.10.4)
122
+ columnize (>= 0.1)
123
+ ruby-debug-base (~> 0.10.4.0)
124
+ ruby-debug-base (0.10.4)
125
+ linecache (>= 0.3)
126
+ rubytree (0.7.0)
127
+ rubyzip (0.9.6.1)
128
+ schema_qualified_tables (1.0.1)
129
+ activerecord (>= 2.3)
130
+ selenium-webdriver (2.19.0)
131
+ childprocess (>= 0.2.5)
132
+ ffi (~> 1.0.9)
133
+ multi_json (~> 1.0.4)
134
+ rubyzip
135
+ sinatra (1.2.8)
136
+ rack (~> 1.1)
137
+ tilt (>= 1.2.2, < 2.0)
138
+ sqlite3 (1.3.5)
139
+ thor (0.14.6)
140
+ tilt (1.3.3)
141
+ treetop (1.4.10)
142
+ polyglot
143
+ polyglot (>= 0.3.1)
144
+ tzinfo (0.3.31)
145
+ warden (1.1.0)
146
+ rack (>= 1.0)
147
+
148
+ PLATFORMS
149
+ ruby
150
+
151
+ DEPENDENCIES
152
+ aker-confident!
153
+ capybara (= 0.3.7)
154
+ rack-test
155
+ rails (= 3.0.11)
156
+ rspec
157
+ rspec-rails
158
+ ruby-debug
159
+ sqlite3
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2011 by William Dix, Peter Nyberg
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,33 @@
1
+ Confident
2
+ =========
3
+
4
+ Confident is a Rails gem-plugin which handles user
5
+ confidentiality agreements. It prevents access to resources
6
+ without a signed confidentiality agreement and provides an interface
7
+ to sign said agreement.
8
+
9
+ ### Configuration
10
+
11
+ To configure Confident create an initializer in initializers/confident.rb.
12
+
13
+ Confident.configure{ :conf_model => Signature,
14
+ :conf_file => "../../agreement.txt",
15
+ :conf_host_hook => {|env| env['aker.check']}
16
+
17
+ The class passed as conf\_model must be respond to signed? and sign methods which take
18
+ a Aker::User as arguments. The conf\_file option is a path to the file
19
+ containing the desired text for the confidentiality agreement. The conf\_host\_hook
20
+ option is an object which responds to call and receives the rack env. The hook
21
+ determines whether confident will be active or not on a request.
22
+
23
+
24
+ ### Running Tests
25
+
26
+ The tests which do not require a full Rails application are in the top level
27
+ of the spec/ directory. Within integration are specs requiring a Rails application.
28
+
29
+ In order to set up the testbed application and run Rails integration tests:
30
+
31
+ rake -f init_testbed.rakefile
32
+ cd testbed
33
+ rake spec
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "aker/confident/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "aker-confident"
7
+ s.version = Aker::Confident::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["William Dix", "Peter Nyberg"]
10
+ s.email = ["wjdix@northwestern.edu"]
11
+ s.homepage = ""
12
+ s.summary = %q{Confidentiality gem for Aker }
13
+ s.description = %q{ialdskj}
14
+
15
+ s.rubyforge_project = "aker-confident"
16
+
17
+ s.add_dependency('aker')
18
+ s.add_dependency('aker-rails')
19
+ s.add_dependency('sinatra')
20
+ s.add_dependency('haml')
21
+ s.add_dependency('schema_qualified_tables')
22
+
23
+ s.add_development_dependency('rails', "3.0.11")
24
+ s.add_development_dependency('rspec')
25
+ s.add_development_dependency('rspec-rails')
26
+ s.add_development_dependency('capybara', '0.3.7')
27
+ s.add_development_dependency('rack-test')
28
+ s.add_development_dependency('sqlite3')
29
+
30
+ s.files = `git ls-files`.split("\n")
31
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
32
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
33
+ s.require_paths = ["lib"]
34
+ end
@@ -0,0 +1,24 @@
1
+ :css
2
+ div#agreement {
3
+ width: 500px;
4
+ margin-left: 200px;
5
+ margin-top: 20px;
6
+ font-family: Arial,Sans-serif;
7
+ font-size: small;
8
+ }
9
+ input#agree_button {
10
+ margin-left:200px;
11
+ margin-top: 20px;
12
+ }
13
+ #image{
14
+ margin-left: 200px;
15
+ }
16
+
17
+ #agreement
18
+ =@conf_agreement
19
+ %form{:action => "#{@root_url}/sign_agreement", :method => "post"}
20
+ %input{:type => "hidden", :value => @original_target, :name => "original"}
21
+ %br
22
+ %input#agree_button{:type => "submit", :value => "I agree and accept the terms"}
23
+
24
+
@@ -0,0 +1,113 @@
1
+ desc "Set up a rails app for testing in the spec dir"
2
+ task :default => [:"testbed:generate", :"testbed:generate_resource", :"testbed:generate_sig_model", :"testbed:migrate",
3
+ :"testbed:config_confident", :"testbed:conf_agreement", :"testbed:bcsec"]
4
+
5
+ namespace "testbed" do
6
+ # "testbed" is also hardcoded in the spec/spec_helper.rb features/support/env.rb and gitignore file. Change it there too...
7
+
8
+ desc "Generate rails, rspec, cucumber"
9
+ task :generate do
10
+ chdir("testbed") do
11
+ sh "bundle install"
12
+ sh "bundle exec rails new . --skip-gemfile"
13
+ sh "bundle exec rails generate rspec:install"
14
+ sh "rm -rf features"
15
+ spec_helper = <<-HELPER
16
+ ENV["RAILS_ENV"] ||= 'test'
17
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment'))
18
+ require 'spec/autorun'
19
+ require 'spec/rails'
20
+ require 'capybara/dsl'
21
+ require 'capybara/rails'
22
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
23
+
24
+ Spec::Runner.configure do |config|
25
+ # If you're not using ActiveRecord you should remove these
26
+ # lines, delete config/database.yml and disable :active_record
27
+ # in your config/boot.rb
28
+ config.use_transactional_fixtures = false
29
+ config.use_instantiated_fixtures = false
30
+ config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
31
+ config.include(Capybara, :type => :integration)
32
+ Capybara.current_driver = :selenium
33
+ end
34
+ HELPER
35
+ end
36
+ end
37
+
38
+ desc "create sample resource"
39
+ task :generate_resource do
40
+ chdir("testbed") do
41
+ sh "bundle exec rails generate scaffold lab name:string result:integer"
42
+ end
43
+ end
44
+
45
+ desc "create model for conf signature"
46
+ task :generate_sig_model do
47
+ chdir("testbed") do
48
+ sh "bundle exec rails generate model Signature username:string created_at:date"
49
+ sig_model = <<-MODEL
50
+ class Signature < ActiveRecord::Base
51
+ def self.signed?(user)
52
+ find_by_username(user.username)
53
+ end
54
+ def self.sign(user)
55
+ create(:username => user.username)
56
+ end
57
+ end
58
+ MODEL
59
+ File.open('app/models/signature.rb', 'w') do |f|
60
+ f.write sig_model
61
+ end
62
+ end
63
+ end
64
+
65
+ desc "Generate, migrate testbed"
66
+ task :migrate do
67
+ chdir("testbed") do
68
+ sh "bundle exec rake db:migrate db:test:prepare"
69
+ end
70
+ end
71
+
72
+ desc "add initializer file for confident"
73
+ task :config_confident do
74
+ chdir("testbed") do
75
+ conf_config = "Aker::Confident.configure({:conf_model => Signature, :conf_file => File.join(File.dirname(__FILE__), \"..\", \"..\", \"conf_agreement.txt\")})\n"
76
+ File.open("config/initializers/confident.rb", 'w'){ |f| f.write conf_config }
77
+ end
78
+ end
79
+
80
+ desc "add initializer file for bcsec"
81
+ task :bcsec do
82
+ chdir("testbed") do
83
+ bcsec_conf = <<-CONF
84
+ Aker.configure {
85
+ ui_mode :form
86
+ portal :test
87
+ authority Aker::Authorities::Static.from_file \"\#{RAILS_ROOT}/../spec/assets/test-users.yml\"
88
+ }
89
+ CONF
90
+ File.open("config/initializers/aker.rb", 'w'){ |f| f.write bcsec_conf }
91
+ con_file = File.read "app/controllers/application_controller.rb"
92
+ File.open("app/controllers/application_controller.rb", 'w') do |f|
93
+ f.write con_file.sub!("class ApplicationController < ActionController::Base", "class ApplicationController < ActionController::Base\n include Aker::Rails::SecuredController")
94
+ end
95
+ end
96
+ end
97
+
98
+ desc "add conf_agreement file"
99
+ task :conf_agreement do
100
+ chdir("testbed") do
101
+ conf_agreement = "Don't share this, dirtbag!"
102
+ File.open("conf_agreement.txt", 'w'){|f| f.write conf_agreement}
103
+ end
104
+ end
105
+
106
+ desc "Remove testbed app"
107
+ task :remove do
108
+ puts "Removing the test_app in the spec folder"
109
+ chdir("testbed") do
110
+ sh 'rm -rf Gemfile.lock README Rakefile app config db doc features lib log public script spec surveys test tmp vendor conf_agreement.txt'
111
+ end
112
+ end
113
+ end
@@ -0,0 +1 @@
1
+ require 'aker/confident'
@@ -0,0 +1,62 @@
1
+ require 'active_support'
2
+ require 'aker'
3
+ module Aker
4
+ module Confident
5
+ autoload :Configuration, 'aker/confident/configuration'
6
+ autoload :Signer, 'aker/confident/signer'
7
+ autoload :Sinatra, 'aker/confident/sinatra'
8
+ autoload :Rack, 'aker/confident/rack'
9
+ autoload :DefaultConfiguration, 'aker/confident/configuration'
10
+ autoload :AkerUserExt, 'aker/confident/aker_user_ext'
11
+ autoload :AkerSlice, 'aker/confident/aker_slice'
12
+
13
+ class << self
14
+ include Signer
15
+ attr_accessor :configuration
16
+
17
+ def configuration
18
+ @configuration
19
+ end
20
+
21
+ def configure(hash_options={}, &config_block)
22
+ if config_block
23
+ @configuration = Confident::Configuration.new(hash_options).define &config_block
24
+ else
25
+ @configuration = Confident::Configuration.new(hash_options)
26
+ end
27
+ @configuration.verify!
28
+ end
29
+
30
+ def conf_model
31
+ @configuration.model
32
+ end
33
+ def root_url
34
+ @configuration.root_url
35
+ end
36
+ def host_hook
37
+ @configuration.host_hook
38
+ end
39
+
40
+ def pass_through?(env)
41
+ hooks.any?{|hook| hook.call(env) }
42
+ end
43
+
44
+ # if true Confident should intercept requests
45
+ def default_pass_through_hooks
46
+ [
47
+ lambda {|env| !env['aker.interactive'] },
48
+ lambda {|env| (env['aker.check'] && env['aker.check'].user == nil) },
49
+ lambda {|env| env['PATH_INFO'] == '/logout' },
50
+ lambda {|env| env['REQUEST_METHOD'] == 'POST' && env['PATH_INFO'] != '/sign_agreement' },
51
+ lambda {|env| env['aker.check'].user.signed? }
52
+ ]
53
+ end
54
+
55
+ def hooks
56
+ default_pass_through_hooks + configuration.pass_through_hooks
57
+ end
58
+ end
59
+ Aker::Configuration.add_default_slice Confident::AkerSlice.new
60
+ Aker::User.send(:include, Confident::AkerUserExt)
61
+ end
62
+ end