gatepass 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.
- checksums.yaml +7 -0
- data/README.md +58 -0
- data/Rakefile +8 -0
- data/app/assets/config/gatepass_manifest.js +1 -0
- data/app/assets/stylesheets/gatepass/application.css +15 -0
- data/app/controllers/gatepass/application_controller.rb +4 -0
- data/app/controllers/gatepass/authentication_controller.rb +68 -0
- data/app/controllers/gatepass/users_controller.rb +60 -0
- data/app/helpers/gatepass/application_helper.rb +4 -0
- data/app/helpers/gatepass/authentication_helper.rb +4 -0
- data/app/helpers/gatepass/users_helper.rb +4 -0
- data/app/jobs/gatepass/application_job.rb +4 -0
- data/app/mailers/gatepass/application_mailer.rb +6 -0
- data/app/models/gatepass/application_record.rb +5 -0
- data/app/models/gatepass/user.rb +5 -0
- data/app/views/gatepass/authentication/authenticate.html.erb +2 -0
- data/app/views/gatepass/authentication/login.html.erb +13 -0
- data/app/views/gatepass/authentication/logout.html.erb +2 -0
- data/app/views/gatepass/users/_form.html.erb +37 -0
- data/app/views/gatepass/users/_user.html.erb +22 -0
- data/app/views/gatepass/users/edit.html.erb +10 -0
- data/app/views/gatepass/users/index.html.erb +14 -0
- data/app/views/gatepass/users/new.html.erb +9 -0
- data/app/views/gatepass/users/show.html.erb +10 -0
- data/app/views/layouts/gatepass/application.html.erb +15 -0
- data/config/initializers/assets.rb +1 -0
- data/config/routes.rb +6 -0
- data/db/migrate/20230726110030_create_gatepass_users.rb +12 -0
- data/lib/gatepass/engine.rb +5 -0
- data/lib/gatepass/version.rb +3 -0
- data/lib/gatepass.rb +10 -0
- data/lib/tasks/gatepass_tasks.rake +4 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6adfbc31cccc12d1786457c468667bcba579db0db4639aae68a01bb61a570e64
|
4
|
+
data.tar.gz: 5e456e23ddcda822bc391601c88fb0286184abc9f164de6ad2cf35e1765b912d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 10d45f2705514fbd230e72a336f13935e88d571b55d76431c1acedb942f47c34b84cb352c55c442842fe1df00d08641b21ac02444ded243149aba3a77f20e0c9
|
7
|
+
data.tar.gz: 200c1bf025039c8e889951d30afe355dc8b010087c8e66526d854ff38438887b6cb329ccefdb00f063baf4e3f5d4017346b45ba564160890ffc2b3e78a954304
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Gatepass
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem "gatepass"
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install gatepass
|
22
|
+
```
|
23
|
+
|
24
|
+
Modify the application controller to include the Gatepass module and add the authentication check:
|
25
|
+
```
|
26
|
+
class ApplicationController < ActionController::Base
|
27
|
+
include Gatepass
|
28
|
+
before_action :check_authenticated
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
TODO - Configuration parameters
|
33
|
+
|
34
|
+
Create an initial user account with:
|
35
|
+
```
|
36
|
+
$ rails c
|
37
|
+
u1 = Gatepass::User.new
|
38
|
+
u1.username = 'nitin'
|
39
|
+
u1.password = 'green'
|
40
|
+
u1.auth_type = 'local'
|
41
|
+
u1.save
|
42
|
+
```
|
43
|
+
|
44
|
+
Login with the above account, and access the user account management page at:
|
45
|
+
http://localhost:3000/gatepass/users
|
46
|
+
|
47
|
+
## Other Notes
|
48
|
+
The User model has the fields: username:string auth_type:string password_digest:string username_mapping:string
|
49
|
+
|
50
|
+
auth_type is `local` or `activedirectory`.
|
51
|
+
|
52
|
+
Use a dummy password for activedirectory users.
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
Contribution directions go here.
|
56
|
+
|
57
|
+
## License
|
58
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
//= link_directory ../stylesheets/gatepass .css
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Gatepass
|
2
|
+
class AuthenticationController < ApplicationController
|
3
|
+
def login
|
4
|
+
end
|
5
|
+
|
6
|
+
def logout
|
7
|
+
session.delete :user
|
8
|
+
redirect_to :action => :login
|
9
|
+
end
|
10
|
+
|
11
|
+
def authenticate
|
12
|
+
username = params[:username]
|
13
|
+
password = params[:password]
|
14
|
+
|
15
|
+
user = User.find_by(username: username)
|
16
|
+
if user.auth_type == 'local'
|
17
|
+
user_obj = user.authenticate(password)
|
18
|
+
|
19
|
+
if user_obj === false
|
20
|
+
redirect_to ({ controller: 'gatepass/authentication', action: 'login' })
|
21
|
+
else
|
22
|
+
session[:user] = user_obj
|
23
|
+
redirect_to main_app.root_url
|
24
|
+
end
|
25
|
+
elsif user.auth_type == 'activedirectory' # 'ldap'
|
26
|
+
require 'net/ldap'
|
27
|
+
|
28
|
+
server_address = Rails.application.config.ldap_server_hostname # 'ad.nitinkatkam.mdbrecruit.net'
|
29
|
+
server_port = Rails.application.config.ldap_server_port
|
30
|
+
ca_certificate = Rails.application.config.ldap_ca_cert
|
31
|
+
|
32
|
+
ldap = Net::LDAP.new :host => server_address,
|
33
|
+
:port => server_port, # 636, # 389,
|
34
|
+
:encryption => {
|
35
|
+
method: :simple_tls,
|
36
|
+
tls_options: {
|
37
|
+
ca_file: ca_certificate # '/Users/nitin.katkam/Downloads/nitinkatkam-ad-ca.cer',
|
38
|
+
# verify_mode: OpenSSL::SSL::VERIFY_NONE
|
39
|
+
}
|
40
|
+
},
|
41
|
+
:auth => {
|
42
|
+
:method => :simple,
|
43
|
+
:username => user.username_mapping,
|
44
|
+
:password => password
|
45
|
+
}
|
46
|
+
|
47
|
+
filter = Net::LDAP::Filter.eq("distinguishedname", user.username_mapping)
|
48
|
+
treebase = Rails.application.config.ldap_base # "dc=nitinkatkam, dc=mdbrecruit, dc=net"
|
49
|
+
|
50
|
+
search_result_count = 0
|
51
|
+
ldap.search(:base => treebase, :filter => filter) do |entry|
|
52
|
+
search_result_count += 1
|
53
|
+
# puts "DN: #{entry.dn}" # CN=bindUser1,CN=Users,DC=nitinkatkam,DC=mdbrecruit,DC=net
|
54
|
+
# puts "memberOf: #{entry.memberof}" #["CN=peopleOfNitinKatkam,CN=Users,DC=nitinkatkam,DC=mdbrecruit,DC=net", "CN=Administrators,CN=Builtin,DC=nitinkatkam,DC=mdbrecruit,DC=net"]
|
55
|
+
|
56
|
+
if ldap.get_operation_result.code == 49 or search_result_count == 0
|
57
|
+
redirect_to({ controller: 'gatepass/authentication', action: 'login' })
|
58
|
+
elsif search_result_count == 1
|
59
|
+
session[:user] = user # entry # user_obj
|
60
|
+
redirect_to main_app.root_url
|
61
|
+
else
|
62
|
+
redirect_to({ controller: 'gatepass/authentication', action: 'login' })
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Gatepass
|
2
|
+
class UsersController < ApplicationController
|
3
|
+
before_action :set_user, only: %i[ show edit update destroy ]
|
4
|
+
|
5
|
+
# GET /users
|
6
|
+
def index
|
7
|
+
@users = User.all
|
8
|
+
end
|
9
|
+
|
10
|
+
# GET /users/1
|
11
|
+
def show
|
12
|
+
end
|
13
|
+
|
14
|
+
# GET /users/new
|
15
|
+
def new
|
16
|
+
@user = User.new
|
17
|
+
end
|
18
|
+
|
19
|
+
# GET /users/1/edit
|
20
|
+
def edit
|
21
|
+
end
|
22
|
+
|
23
|
+
# POST /users
|
24
|
+
def create
|
25
|
+
@user = User.new(user_params)
|
26
|
+
|
27
|
+
if @user.save
|
28
|
+
redirect_to @user, notice: "User was successfully created."
|
29
|
+
else
|
30
|
+
render :new, status: :unprocessable_entity
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# PATCH/PUT /users/1
|
35
|
+
def update
|
36
|
+
if @user.update(user_params)
|
37
|
+
redirect_to @user, notice: "User was successfully updated."
|
38
|
+
else
|
39
|
+
render :edit, status: :unprocessable_entity
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# DELETE /users/1
|
44
|
+
def destroy
|
45
|
+
@user.destroy
|
46
|
+
redirect_to users_url, notice: "User was successfully destroyed.", status: :see_other
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
# Use callbacks to share common setup or constraints between actions.
|
51
|
+
def set_user
|
52
|
+
@user = User.find(params[:id])
|
53
|
+
end
|
54
|
+
|
55
|
+
# Only allow a list of trusted parameters through.
|
56
|
+
def user_params
|
57
|
+
params.require(:user).permit(:username, :auth_type, :password_digest, :username_mapping)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<h1>Authentication#login</h1>
|
2
|
+
|
3
|
+
<%= form_with url: { action: :authenticate } do |form| %>
|
4
|
+
<%= form.label :username %>
|
5
|
+
<%= form.text_field :username %>
|
6
|
+
<br />
|
7
|
+
|
8
|
+
<%= form.label :password %>
|
9
|
+
<%= form.password_field :password %>
|
10
|
+
<br />
|
11
|
+
|
12
|
+
<%= form.submit 'Login' %>
|
13
|
+
<% end %>
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<%= form_with(model: user) do |form| %>
|
2
|
+
<% if user.errors.any? %>
|
3
|
+
<div style="color: red">
|
4
|
+
<h2><%= pluralize(user.errors.count, "error") %> prohibited this user from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<% user.errors.each do |error| %>
|
8
|
+
<li><%= error.full_message %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div>
|
15
|
+
<%= form.label :username, style: "display: block" %>
|
16
|
+
<%= form.text_field :username %>
|
17
|
+
</div>
|
18
|
+
|
19
|
+
<div>
|
20
|
+
<%= form.label :auth_type, style: "display: block" %>
|
21
|
+
<%= form.text_field :auth_type %>
|
22
|
+
</div>
|
23
|
+
|
24
|
+
<div>
|
25
|
+
<%= form.label :password_digest, style: "display: block" %>
|
26
|
+
<%= form.text_field :password_digest %>
|
27
|
+
</div>
|
28
|
+
|
29
|
+
<div>
|
30
|
+
<%= form.label :username_mapping, style: "display: block" %>
|
31
|
+
<%= form.text_field :username_mapping %>
|
32
|
+
</div>
|
33
|
+
|
34
|
+
<div>
|
35
|
+
<%= form.submit %>
|
36
|
+
</div>
|
37
|
+
<% end %>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<div id="<%= dom_id user %>">
|
2
|
+
<p>
|
3
|
+
<strong>Username:</strong>
|
4
|
+
<%= user.username %>
|
5
|
+
</p>
|
6
|
+
|
7
|
+
<p>
|
8
|
+
<strong>Auth type:</strong>
|
9
|
+
<%= user.auth_type %>
|
10
|
+
</p>
|
11
|
+
|
12
|
+
<p>
|
13
|
+
<strong>Password digest:</strong>
|
14
|
+
<%= user.password_digest %>
|
15
|
+
</p>
|
16
|
+
|
17
|
+
<p>
|
18
|
+
<strong>Username mapping:</strong>
|
19
|
+
<%= user.username_mapping %>
|
20
|
+
</p>
|
21
|
+
|
22
|
+
</div>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<p style="color: green"><%= notice %></p>
|
2
|
+
|
3
|
+
<h1>Users</h1>
|
4
|
+
|
5
|
+
<div id="users">
|
6
|
+
<% @users.each do |user| %>
|
7
|
+
<%= render user %>
|
8
|
+
<p>
|
9
|
+
<%= link_to "Show this user", user %>
|
10
|
+
</p>
|
11
|
+
<% end %>
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<%= link_to "New user", new_user_path %>
|
@@ -0,0 +1 @@
|
|
1
|
+
Rails.application.config.assets.precompile += %w( gatepass/application.css gatepass/application.js )
|
data/config/routes.rb
ADDED
data/lib/gatepass.rb
ADDED
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gatepass
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nitin Reddy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-07-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 7.0.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 7.0.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bcrypt
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.1.19
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.1.19
|
41
|
+
description: This Rails plugin enables you to authenticate users against the local
|
42
|
+
database as well as against an ActiveDirectory server
|
43
|
+
email:
|
44
|
+
- 82951937+nitredd@users.noreply.github.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- app/assets/config/gatepass_manifest.js
|
52
|
+
- app/assets/stylesheets/gatepass/application.css
|
53
|
+
- app/controllers/gatepass/application_controller.rb
|
54
|
+
- app/controllers/gatepass/authentication_controller.rb
|
55
|
+
- app/controllers/gatepass/users_controller.rb
|
56
|
+
- app/helpers/gatepass/application_helper.rb
|
57
|
+
- app/helpers/gatepass/authentication_helper.rb
|
58
|
+
- app/helpers/gatepass/users_helper.rb
|
59
|
+
- app/jobs/gatepass/application_job.rb
|
60
|
+
- app/mailers/gatepass/application_mailer.rb
|
61
|
+
- app/models/gatepass/application_record.rb
|
62
|
+
- app/models/gatepass/user.rb
|
63
|
+
- app/views/gatepass/authentication/authenticate.html.erb
|
64
|
+
- app/views/gatepass/authentication/login.html.erb
|
65
|
+
- app/views/gatepass/authentication/logout.html.erb
|
66
|
+
- app/views/gatepass/users/_form.html.erb
|
67
|
+
- app/views/gatepass/users/_user.html.erb
|
68
|
+
- app/views/gatepass/users/edit.html.erb
|
69
|
+
- app/views/gatepass/users/index.html.erb
|
70
|
+
- app/views/gatepass/users/new.html.erb
|
71
|
+
- app/views/gatepass/users/show.html.erb
|
72
|
+
- app/views/layouts/gatepass/application.html.erb
|
73
|
+
- config/initializers/assets.rb
|
74
|
+
- config/routes.rb
|
75
|
+
- db/migrate/20230726110030_create_gatepass_users.rb
|
76
|
+
- lib/gatepass.rb
|
77
|
+
- lib/gatepass/engine.rb
|
78
|
+
- lib/gatepass/version.rb
|
79
|
+
- lib/tasks/gatepass_tasks.rake
|
80
|
+
homepage:
|
81
|
+
licenses: []
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubygems_version: 3.4.10
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: An ActiveDirectory and local user authentication plugin for Rails
|
102
|
+
test_files: []
|