adconnect 0.0.1
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.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README +15 -0
- data/Rakefile +2 -0
- data/adconnect.gemspec +22 -0
- data/lib/adconnect.rb +48 -0
- data/lib/adconnect/version.rb +3 -0
- metadata +73 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Adconnect is a bare-bones gem for authenticating to an Active Directory server.
|
2
|
+
|
3
|
+
Example:
|
4
|
+
|
5
|
+
require 'adconnect'
|
6
|
+
|
7
|
+
Adconnect::ActiveDirectoryUser.server = "localhost"
|
8
|
+
Adconnect::ActiveDirectoryUser.port = "389"
|
9
|
+
Adconnect::ActiveDirectoryUser.base = "DC=example,DC=com"
|
10
|
+
Adconnect::ActiveDirectoryUser.domain = "example.com"
|
11
|
+
|
12
|
+
user = Adconnect::ActiveDirectoryUser.authenticate('myusername','mypassword')
|
13
|
+
|
14
|
+
user.cn
|
15
|
+
=> ["firstname lastname"]
|
data/Rakefile
ADDED
data/adconnect.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "adconnect/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "adconnect"
|
7
|
+
s.version = Adconnect::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["David Moulton"]
|
10
|
+
s.email = ["dave@themoultons.net"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Connect to Active Directory}
|
13
|
+
s.description = %q{A Gem tuned specifically to authenticate to Active Directory's flavor of ldap. Very bare-bones}
|
14
|
+
|
15
|
+
s.rubyforge_project = "adconnect"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
s.add_dependency(%q<net-ldap>, [">= 0.1.1.0"])
|
22
|
+
end
|
data/lib/adconnect.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'net/ldap'
|
2
|
+
|
3
|
+
module Adconnect
|
4
|
+
class ActiveDirectoryUser
|
5
|
+
SERVER = 'localhost' # Active Directory server name or IP
|
6
|
+
PORT = 389 # Active Directory server port (default 389)
|
7
|
+
BASE = 'DC=example,DC=com' # Base to search from
|
8
|
+
DOMAIN = 'example.com' # For simplified user@domain format login
|
9
|
+
|
10
|
+
def self.authenticate(username,password)
|
11
|
+
@server ||= SERVER
|
12
|
+
@port ||= PORT
|
13
|
+
@base ||= BASE
|
14
|
+
@domain ||= DOMAIN
|
15
|
+
|
16
|
+
conn = Net::LDAP.new :host => @server,
|
17
|
+
:port => @port,
|
18
|
+
:base => @base,
|
19
|
+
:auth => {
|
20
|
+
:method => :simple,
|
21
|
+
:username => "#{username}@#{@domain}",
|
22
|
+
:password => password
|
23
|
+
}
|
24
|
+
|
25
|
+
if conn.bind && user = conn.search(:filter => "sAMAccountName=#{username}").first
|
26
|
+
user
|
27
|
+
else
|
28
|
+
nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.server=(s)
|
33
|
+
@server = s
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.port=(p)
|
37
|
+
@port = p
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.base=(b)
|
41
|
+
@base = b
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.domain=(d)
|
45
|
+
@domain = d
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: adconnect
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- David Moulton
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-02-22 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: net-ldap
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.1.1.0
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
description: A Gem tuned specifically to authenticate to Active Directory's flavor of ldap. Very bare-bones
|
28
|
+
email:
|
29
|
+
- dave@themoultons.net
|
30
|
+
executables: []
|
31
|
+
|
32
|
+
extensions: []
|
33
|
+
|
34
|
+
extra_rdoc_files: []
|
35
|
+
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- README
|
40
|
+
- Rakefile
|
41
|
+
- adconnect.gemspec
|
42
|
+
- lib/adconnect.rb
|
43
|
+
- lib/adconnect/version.rb
|
44
|
+
has_rdoc: true
|
45
|
+
homepage: ""
|
46
|
+
licenses: []
|
47
|
+
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project: adconnect
|
68
|
+
rubygems_version: 1.5.0
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: Connect to Active Directory
|
72
|
+
test_files: []
|
73
|
+
|