adauth 0.1.0 → 1.0.0pre

Sign up to get free protection for your applications and to get access to all the features.
data/lib/adauth.rb CHANGED
@@ -10,6 +10,9 @@ module Adauth
10
10
  if @config.allowed_groups != []
11
11
  user = Adauth::User.authenticate(login, pass)
12
12
  (user && @config.allowed_groups != (@config.allowed_groups - user.groups)) ? user : nil
13
+ elsif @config.denied_groups != []
14
+ user = Adauth::User.authenticate(login, pass)
15
+ (user && @config.denied_groups == (@config.denied_groups - user.groups)) ? user : nil
13
16
  else
14
17
  Adauth::User.authenticate(login, pass)
15
18
  end
data/lib/adauth/config.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  module Adauth
2
2
  class Config
3
- attr_accessor :domain, :port, :base, :server, :allowed_groups
3
+ attr_accessor :domain, :port, :base, :server, :allowed_groups, :denied_groups
4
4
 
5
5
  def initialize
6
6
  @port = 389
7
7
  @allowed_groups = []
8
+ @denied_groups = []
8
9
  end
9
10
  end
10
11
  end
@@ -8,9 +8,17 @@ module Adauth
8
8
  group_strings.split(", ")
9
9
  end
10
10
 
11
+ def update_from_adauth(adauth_user)
12
+ self.group_strings = adauth_user.groups.join(", ")
13
+ self.name = adauth_user.name
14
+ self.save
15
+ end
16
+
11
17
  module ClassMethods
12
18
  def return_and_create_with_adauth(adauth_user)
13
- find_by_login(adauth_user.login) || create_user_with_adauth(adauth_user)
19
+ user = (find_by_login(adauth_user.login) || create_user_with_adauth(adauth_user))
20
+ user.update_from_adauth(adauth_user)
21
+ return user
14
22
  end
15
23
 
16
24
  def create_user_with_adauth(adauth_user)
@@ -1,3 +1,3 @@
1
1
  module Adauth
2
- Version = "0.1.0"
2
+ Version = "1.0.0pre"
3
3
  end
@@ -0,0 +1,5 @@
1
+ Description:
2
+ Runs all the adauth generators with defaults.
3
+
4
+ Example:
5
+ rails g adauth:all
@@ -0,0 +1,11 @@
1
+ module Adauth
2
+ module Generators
3
+ class AllGenerator < Rails::Generators::Base
4
+ def all_generators
5
+ generate "adauth:config"
6
+ generate "adauth:user_model"
7
+ generate "adauth:sessions"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ Description:
2
+ Creates a controller for sessions.
3
+
4
+ Example:
5
+ rails g adauth:sessions user
6
+
7
+ rails g adauth:sessions employee
@@ -0,0 +1,23 @@
1
+ module Adauth
2
+ module Generators
3
+ class SessionsGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+ argument :model_name, :type => :string, :default => "user"
6
+
7
+ def generate_sessions
8
+ template "sessions_controller.rb.erb", "app/controllers/sessions_controller.rb"
9
+ template "new.html.erb", "app/views/sessions/new.html.erb"
10
+ route "resources :sessions"
11
+ route "match \"/adauth\" => \"sessions#create\""
12
+ route "match \"/signout\" => \"sessions#destroy\""
13
+ puts " extra Add this code to your ApplicationController"
14
+ puts ""
15
+ puts " helper_method :current_user"
16
+ puts ""
17
+ puts " def current_user"
18
+ puts " @current_user ||= User.find(session[:user_id]) if session[:user_id]"
19
+ puts " end"
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ <h1>Login</h1>
2
+
3
+ <%%= default_adauth_form %>
@@ -0,0 +1,21 @@
1
+ class SessionsController < ApplicationController
2
+ def new
3
+ redirect_to root_path if current_user
4
+ end
5
+
6
+ def create
7
+ ldap_user = Adauth.authenticate(params[:username], params[:password])
8
+ if ldap_user
9
+ user = <%= model_name.camelize %>.return_and_create_with_adauth(ldap_user)
10
+ session[:user_id] = user.id
11
+ redirect_to root_path
12
+ else
13
+ redirect_to root_path, :error => "Invalid Login"
14
+ end
15
+ end
16
+
17
+ def destroy
18
+ session[:user_id] = nil
19
+ redirect_to root_path
20
+ end
21
+ end
@@ -7,7 +7,7 @@ module Adauth
7
7
 
8
8
  def generate_user_model
9
9
  template "model.rb.erb", "app/models/#{file_name}.rb"
10
- template "migration.rb.erb", "db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_#{migration_name_for_array}.rb"
10
+ generate "migration", "#{migration_name_for_array}", "login:string", "group_strings:string", "name:string"
11
11
  end
12
12
 
13
13
  private
data/spec/adauth_spec.rb CHANGED
@@ -60,6 +60,16 @@ describe Adauth, "#authenticate" do
60
60
  Adauth.config.allowed_groups = @yaml["domain"]["fail_allowed_groups"]
61
61
  Adauth.authenticate(@yaml["user"]["login"], @yaml["user"]["password"]).should be_nil
62
62
  end
63
+
64
+ it "should dis-allow users who are in a denied group" do
65
+ Adauth.config.denied_groups = @yaml["domain"]["pass_allowed_groups"]
66
+ Adauth.authenticate(@yaml["user"]["login"], @yaml["user"]["password"]).should be_nil
67
+ end
68
+
69
+ it "should dis-allow users who are in a denied group" do
70
+ Adauth.config.denied_groups = @yaml["domain"]["fail_allowed_groups"]
71
+ Adauth.authenticate(@yaml["user"]["login"], @yaml["user"]["password"]).should be_a Adauth::User
72
+ end
63
73
  end
64
74
 
65
75
  describe Adauth::User do
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adauth
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease:
4
+ hash: 961915988
5
+ prerelease: 5
6
6
  segments:
7
- - 0
8
7
  - 1
9
8
  - 0
10
- version: 0.1.0
9
+ - 0
10
+ - pre
11
+ version: 1.0.0pre
11
12
  platform: ruby
12
13
  authors:
13
14
  - Adam "Arcath" Laycock
@@ -15,7 +16,7 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2011-06-23 00:00:00 +01:00
19
+ date: 2011-07-22 00:00:00 +01:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
@@ -68,11 +69,16 @@ files:
68
69
  - lib/adauth/user.rb
69
70
  - lib/adauth/user_model.rb
70
71
  - lib/adauth/version.rb
72
+ - lib/generators/adauth/all/USAGE
73
+ - lib/generators/adauth/all/all_generator.rb
71
74
  - lib/generators/adauth/config/USAGE
72
75
  - lib/generators/adauth/config/config_generator.rb
73
76
  - lib/generators/adauth/config/templates/config.rb.erb
77
+ - lib/generators/adauth/sessions/USAGE
78
+ - lib/generators/adauth/sessions/sessions_generator.rb
79
+ - lib/generators/adauth/sessions/templates/new.html.erb
80
+ - lib/generators/adauth/sessions/templates/sessions_controller.rb.erb
74
81
  - lib/generators/adauth/user_model/USAGE
75
- - lib/generators/adauth/user_model/templates/migration.rb.erb
76
82
  - lib/generators/adauth/user_model/templates/model.rb.erb
77
83
  - lib/generators/adauth/user_model/user_model_generator.rb
78
84
  - spec/adauth_spec.rb
@@ -97,12 +103,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
103
  required_rubygems_version: !ruby/object:Gem::Requirement
98
104
  none: false
99
105
  requirements:
100
- - - ">="
106
+ - - ">"
101
107
  - !ruby/object:Gem::Version
102
- hash: 3
108
+ hash: 25
103
109
  segments:
104
- - 0
105
- version: "0"
110
+ - 1
111
+ - 3
112
+ - 1
113
+ version: 1.3.1
106
114
  requirements: []
107
115
 
108
116
  rubyforge_project:
@@ -1,14 +0,0 @@
1
- class <%= migration_name_for_array.camelize %>
2
- def self.up
3
- create_table :<%= model_name.pluralize %> do |t|
4
- t.string :login
5
- t.string :group_strings
6
- t.string :name
7
- t.timestamps
8
- end
9
- end
10
-
11
- def self.down
12
- drop_table :<%= model_name.pluralize %>
13
- end
14
- end