Skip to content

Commit

Permalink
Move Jackad methods to module
Browse files Browse the repository at this point in the history
  • Loading branch information
kugaevsky committed Jan 15, 2013
1 parent b4b1df1 commit b5070f7
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 55 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ test/tmp
test/version_tmp
tmp
.idea/
.rvmrc
1 change: 0 additions & 1 deletion .rvmrc

This file was deleted.

4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2012 Nick Kugaevsky
Copyright (c) 2012 — 2013 Nick Kugaevsky

MIT License

Expand All @@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5 changes: 3 additions & 2 deletions jackad.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ require File.expand_path('../lib/jackad/version', __FILE__)
Gem::Specification.new do |gem|
gem.authors = ["Nick Kugaevsky"]
gem.email = ["nick@kugaevsky.ru"]
gem.description = %q{ Active Directory connector }
gem.description = %q{ Simple LDAP (Active Directory) connector }
gem.summary = gem.description
gem.homepage = ""
gem.homepage = "https://github.com/pantsu/jackad"

gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
gem.files = `git ls-files`.split("\n")
Expand All @@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
gem.version = Jackad::VERSION

gem.add_dependency 'net-ldap', '~>0.2.0'
# gem.add_dependency 'yaml'

#gem.add_development_dependency('rspec')

Expand Down
35 changes: 1 addition & 34 deletions lib/jackad.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,4 @@
require "jackad/version"
require "jackad/config"
require "jackad/ad_connect"

module Jackad

class ConnectionRefused < StandardError; end
class RecordNotFound < StandardError; end

# Check validity of username and password
# Returns true or false
def self.credentials_valid?(username, password)
ad = AdConnect.new
ad.ldap.auth(username, password)
ad.ldap.bind
end

# Check user existance by configured attribute
# Returns true or false
def self.entry_exists?(username)
ad = AdConnect.new
filter = Net::LDAP::Filter.eq(ad.attribute.to_s, username)
ad.ldap.search(filter: filter, size: 1).size > 0 ? true : false
end

# Check user validity by configured attribute, useraccountcontrol flags and pwdlastset attribute
# Returns true or false
def self.entry_valid?(username)
ad = AdConnect.new
filter_by_attr = Net::LDAP::Filter.eq(ad.attribute.to_s, username)
filter_by_uac = ~Net::LDAP::Filter.construct('useraccountcontrol:1.2.840.113556.1.4.803:=2')
filter_by_pass = ~Net::LDAP::Filter.eq('pwdlastset', '0')
filter = filter_by_attr & filter_by_uac & filter_by_pass
ad.ldap.search(filter: filter, size: 1).size > 0 ? true : false
end

end
require "jackad/jackad"
19 changes: 6 additions & 13 deletions lib/jackad/config.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
module Jackad

LDAP_CONFIG = { host: 'example.com',
port: 389,
base: 'dc=example,dc=com',
attribute: 'sAMAccountName',
admin_user: 'admin_username',
admin_password: 'admin_password',
method: 'simple',
ssl: false,
admin: false
}

end
class Config
def self.setup
@@options ||= YAML.load_file('/usr/local/jackad.yml')
end
end
end
32 changes: 32 additions & 0 deletions lib/jackad/jackad.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Jackad
class ConnectionRefused < StandardError; end
class RecordNotFound < StandardError; end

# Check validity of username and password
# Returns true or false
def self.credentials_valid?(username, password)
ad = AdConnect.new
ad.ldap.auth(username, password)
ad.ldap.bind
end

# Check user existance by configured attribute
# Returns true or false
def self.entry_exists?(username)
ad = AdConnect.new
filter = Net::LDAP::Filter.eq(ad.attribute.to_s, username)
ad.ldap.search(filter: filter, size: 1).size > 0 ? true : false
end

# Check user validity by configured attribute, useraccountcontrol flags and pwdlastset attribute
# Returns true or false
def self.entry_valid?(username)
ad = AdConnect.new
filter_by_attr = Net::LDAP::Filter.eq(ad.attribute.to_s, username)
filter_by_uac = ~Net::LDAP::Filter.construct('useraccountcontrol:1.2.840.113556.1.4.803:=2')
filter_by_pass = ~Net::LDAP::Filter.eq('pwdlastset', '0')
filter = filter_by_attr & filter_by_uac & filter_by_pass
ad.ldap.search(filter: filter, size: 1).size > 0 ? true : false
end

end
4 changes: 1 addition & 3 deletions lib/jackad/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module Jackad

VERSION = "0.1.1"

VERSION = "0.1.2"
end

0 comments on commit b5070f7

Please sign in to comment.