activate_my_directory 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9e6a83f83e6e0fef91a6abdfc05fe14153305c8c
4
+ data.tar.gz: 0dba9ffc72eaeea4216a6acfcab7b6a6f58a805d
5
+ SHA512:
6
+ metadata.gz: d3fe9dc6b72c7d720aefe920712e9cf4daebcbc9db1dbffc4ba5470850494d4fbfea6aa6ee3cf4e2cbe8ed18c5315119d2a143aaa28d8c0f69d8f441def9ce97
7
+ data.tar.gz: f3da84d2cbf590f8c1b3fc27fd3222d02aae1b597bc8f90aa759b3f6541f3910745fd8f4c24794d51465122567b3748f9d9fb2f80a52d2da70dcf0b845e7bfbd
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ config.yml
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in activate_my_directory.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ryan Kowalick
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # ActivateMyDirectory
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'activate_my_directory'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install activate_my_directory
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/activate_my_directory/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'activate_my_directory/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "activate_my_directory"
8
+ spec.version = ActivateMyDirectory::VERSION
9
+ spec.authors = ["Ryan Kowalick"]
10
+ spec.email = ["rkowalick@covermymeds.com"]
11
+ spec.summary = %q{Tools for ActiveDirectory authentication}
12
+ spec.description = %q{This gems allows you to easily authenticate with ActiveDirectory and determine if a user is a member of a certain group.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "pry"
25
+ spec.add_dependency "active_directory"
26
+ end
@@ -0,0 +1,48 @@
1
+ require "activate_my_directory/version"
2
+ require 'active_directory'
3
+ require 'yaml'
4
+
5
+ module ActivateMyDirectory
6
+ class << self
7
+ def yaml
8
+ @yaml ||= YAML::load_file(File.join(File.dirname(File.expand_path(__FILE__)), '..', 'config.yml'))
9
+ end
10
+
11
+ def settings
12
+ @settings ||= {
13
+ host: yaml['host'],
14
+ port: yaml['port'],
15
+ base: yaml['base'],
16
+ auth: { method: :simple,
17
+ username: "#{yaml['username']}@#{yaml['domain']}",
18
+ password: yaml['password']
19
+ },
20
+ encryption: { method: :simple_tls }
21
+ }
22
+ end
23
+
24
+ def setup
25
+ ActiveDirectory::Base.setup(settings) unless @setup
26
+ @setup = true
27
+ end
28
+
29
+ def authenticate(username, password)
30
+ setup
31
+ user = ActiveDirectory::User.find(:first, userprincipalname: "#{username}@#{yaml['domain']}")
32
+ return false unless user
33
+ user.authenticate(password)
34
+ end
35
+
36
+ def user_is_in_group?(username, groupname)
37
+ setup
38
+ user = ActiveDirectory::User.find(:first, userprincipalname: "#{username}@#{yaml['domain']}")
39
+ group = ActiveDirectory::Group.find(:first, cn: groupname)
40
+ return false unless user && group
41
+ user.groups.include?(group)
42
+ end
43
+
44
+ def authenticate_and_is_in_group?(username, password, groupname)
45
+ authenticate(username, password) && user_is_in_group?(username, groupname)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,3 @@
1
+ module ActivateMyDirectory
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+ require 'pry'
3
+
4
+ describe ActivateMyDirectory do
5
+ describe ".authenticate" do
6
+ subject { described_class.authenticate(*credentials) }
7
+
8
+ context "a correct username/password combination" do
9
+ let(:credentials) { Get.credentials }
10
+ it { should be_true }
11
+ end
12
+
13
+ context "an incorrect/username combination" do
14
+
15
+ context "a nonexistent user" do
16
+ let(:credentials) { ["fake_user", "fake_password"] }
17
+ it { should be_false }
18
+ end
19
+
20
+ context "an actual user but a bad password" do
21
+ let(:credentials) { [ Get.username, "fake_password"] }
22
+ it { should be_false }
23
+ end
24
+ end
25
+ end
26
+
27
+ describe ".user_is_in_group?" do
28
+ subject { described_class.user_is_in_group?(username, group) }
29
+
30
+ context "user is in the group" do
31
+ let(:username) { Get.username }
32
+ let(:group) { "Autobahn" }
33
+ it { should be_true }
34
+ end
35
+
36
+ context "user is not in the group" do
37
+ let(:username) { Get.username }
38
+ let(:group) { "Support" }
39
+ it { should be_false }
40
+ end
41
+ end
42
+
43
+ describe ".authenticate_and_is_in_group?" do
44
+ subject { described_class.authenticate_and_is_in_group?(username, password, groupname) }
45
+
46
+ context "user failed to authenticate" do
47
+ let(:username) { "fake_username" }
48
+ let(:password) { "fake_password" }
49
+ let(:groupname) { "Autobahn" }
50
+ it { should be_false }
51
+ end
52
+
53
+ context "user is authenticated" do
54
+ let(:username) { Get.username }
55
+ let(:password) { Get.password }
56
+
57
+ context "but not in group" do
58
+ let(:groupname) { "Nonexistent Group" }
59
+ it { should be_false }
60
+ end
61
+
62
+ context "but is in group" do
63
+ let(:groupname) { "Autobahn" }
64
+ it { should be_true }
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,46 @@
1
+ require 'io/console'
2
+ require 'activate_my_directory'
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # Require this file using `require "spec_helper"` to ensure that it is only
6
+ # loaded once.
7
+ #
8
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
9
+ #
10
+
11
+ class Get
12
+ class << self
13
+ def credentials
14
+ [username, password]
15
+ end
16
+
17
+ def username
18
+ return @username if @username
19
+ print "\n"
20
+ puts "Please enter your ActiveDirectory credentials"
21
+ print "username: "
22
+ @username = gets.chomp
23
+ end
24
+
25
+ def password
26
+ username
27
+ return @password if @password
28
+ print "password: "
29
+ @password = STDIN.noecho(&:gets).chomp
30
+ print "\n"
31
+ @password
32
+ end
33
+ end
34
+ end
35
+
36
+ RSpec.configure do |config|
37
+ config.treat_symbols_as_metadata_keys_with_true_values = true
38
+ config.run_all_when_everything_filtered = true
39
+ config.filter_run :focus
40
+
41
+ # Run specs in random order to surface order dependencies. If you find an
42
+ # order dependency and want to debug it, you can fix the order by providing
43
+ # the seed, which is printed after each run.
44
+ # --seed 1234
45
+ config.order = 'random'
46
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activate_my_directory
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Kowalick
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: active_directory
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: This gems allows you to easily authenticate with ActiveDirectory and
84
+ determine if a user is a member of a certain group.
85
+ email:
86
+ - rkowalick@covermymeds.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - .rspec
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - activate_my_directory.gemspec
98
+ - lib/activate_my_directory.rb
99
+ - lib/activate_my_directory/version.rb
100
+ - spec/activate_my_directory_spec.rb
101
+ - spec/spec_helper.rb
102
+ homepage: ''
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.2.2
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Tools for ActiveDirectory authentication
126
+ test_files:
127
+ - spec/activate_my_directory_spec.rb
128
+ - spec/spec_helper.rb