-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
284 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
source "http://rubygems.org" | ||
|
||
gem 'adhearsion', :git => 'git://github.com/adhearsion/adhearsion.git', :branch => :develop | ||
|
||
# Specify your gem's dependencies in ahn-ldap.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
# -*- encoding: utf-8 -*- | ||
$:.push File.expand_path("../lib", __FILE__) | ||
require "ahn_ldap/version" | ||
require "adhearsion/ldap/version" | ||
|
||
Gem::Specification.new do |s| | ||
s.name = "ahn-ldap" | ||
s.version = AhnLDAP::VERSION | ||
s.name = "adhearsion-ldap" | ||
s.version = Adhearsion::LDAP::VERSION | ||
s.authors = ["Taylor Carpenter", "Juan de Bravo", "Ben Langfeld"] | ||
s.email = ["[email protected]", "[email protected]", "[email protected]"] | ||
s.homepage = "http://adhearsion.com" | ||
s.summary = %q{LDAP configuration for Adhearsion} | ||
s.description = %q{An Adhearsion Plugin providing LDAP configurability} | ||
|
||
s.rubyforge_project = "ahn-ldap" | ||
s.rubyforge_project = "adhearsion-ldap" | ||
|
||
s.files = `git ls-files`.split("\n") | ||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | ||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | ||
s.require_paths = ["lib"] | ||
|
||
# s.add_runtime_dependency %q<adhearsion>, [">= 2.0.0"] | ||
s.add_runtime_dependency %q<adhearsion>, [">= 2.0.0.alpha1"] | ||
s.add_runtime_dependency %q<activesupport>, [">= 3.0.10"] | ||
s.add_runtime_dependency "activeldap" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'adhearsion/ldap' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
module Adhearsion | ||
module Ldap | ||
class << self | ||
end | ||
end | ||
require "adhearsion" | ||
require "active_support/dependencies/autoload" | ||
|
||
begin | ||
require 'active_ldap' | ||
rescue LoadError | ||
logger.fatal "LDAP support requires the \"activeldap\" gem." | ||
# Silence the abort so we don't get an ugly backtrace | ||
abort "" | ||
end | ||
|
||
require "adhearsion/ldap/version" | ||
require "adhearsion/ldap/plugin" | ||
|
||
module Adhearsion::LDAP | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Adhearsion | ||
module LDAP | ||
|
||
## | ||
# Adhearsion Plugin that defines the LDAP configuration options | ||
# and includes a hook to start the LDAP service in Adhearsion initialization process | ||
class Plugin < Adhearsion::Plugin | ||
extend ActiveSupport::Autoload | ||
|
||
autoload :Service | ||
|
||
# Default configuration for LDAP connection. | ||
# Configure an LDAP connection using ActiveLdap. See ActiveLdap::Base.establish_connect | ||
# for further information about the appropriate settings here. | ||
config :adhearsion_ldap do | ||
host nil, :desc => "LDAP server host" | ||
port 389, :desc => "LDAP server port" | ||
base "", :desc => <<-__ | ||
LDAP tree that must be used in the connection | ||
__ | ||
bind_dn "", :desc => <<-__ | ||
Specific domain name that identifies the user | ||
__ | ||
password "", :desc => "Password credentials" | ||
allow_anonymous false, :desc => "valid values: true | false (default)" | ||
try_sasl false, :desc => "valid values: true | false (default)" | ||
models "app/ldap_models", :desc => "directory containing ActiveLdap models" | ||
end | ||
|
||
# Include the LDAP service in plugins initialization process | ||
init :adhearsion_ldap do | ||
Service.start | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
module Adhearsion | ||
module LDAP | ||
class Plugin | ||
class Service | ||
|
||
class << self | ||
def start | ||
new.start | ||
end | ||
end | ||
|
||
## | ||
# Start LDAP connection | ||
def start | ||
raise "Must supply a host argument to the LDAP configuration" if (config.host.nil? || config.host.empty?) | ||
raise "Must supply a valid port to the LDAP configuration" unless config.port.is_a? Integer | ||
|
||
require_models | ||
establish_connection config.host, | ||
config.port, | ||
config.base, | ||
config.bind_dn, | ||
config.password, | ||
config.allow_anonymous, | ||
config.try_sasl | ||
|
||
Events.register_callback(:shutdown) { stop } | ||
end | ||
|
||
# TODO: It appears that ActiveLdap does not have a connection validation | ||
# or reconnection routine. | ||
#def create_call_hook_for_connection_cleanup | ||
# Events.register_callback([:asterisk, :before_call]) do | ||
# ActiveLdap::Base.verify_active_connections! | ||
# end | ||
#end | ||
|
||
## | ||
# Release LDAP connection | ||
def stop | ||
ActiveLdap::Base.remove_connection | ||
end | ||
|
||
private | ||
|
||
def require_models | ||
path = File.join(Adhearsion.config.platform.root, Adhearsion.config.adhearsion_ldap.models) | ||
Dir.open(Adhearsion.config.adhearsion_ldap.models).each do |model| | ||
require File.join(path, model) if model =~ /\.rb$/ | ||
end | ||
end | ||
|
||
## | ||
# Open LDAP connection | ||
def establish_connection host, port, base, bind_dn, password, allow_anonymous, try_sasl | ||
ActiveLdap::Base.setup_connection :host => host, | ||
:port => port, | ||
:base => base, | ||
:logger => logger, | ||
:bind_dn => bind_dn, | ||
:password => password, | ||
:allow_anonymous => allow_anonymous, | ||
:try_sasl => try_sasl | ||
end | ||
|
||
def config | ||
@config ||= Adhearsion.config[:adhearsion_ldap] | ||
end | ||
end # Service | ||
end # Plugin | ||
end # LDAP | ||
end # Adhearsion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Adhearsion | ||
module LDAP | ||
VERSION = "0.1.0" | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'spec_helper' | ||
|
||
describe Adhearsion::LDAP::Plugin::Service do | ||
|
||
describe "while initializing" do | ||
after do | ||
reset_adhearsion_ldap_config | ||
end | ||
|
||
it "should raise an exception when no host has been configured" do | ||
lambda { Adhearsion::Plugin.init_plugins }.should raise_error "Must supply a host argument to the LDAP configuration" | ||
end | ||
|
||
it "should raise an exception when an invalid port has been configured" do | ||
Adhearsion.config[:adhearsion_ldap].host = "localhost" | ||
Adhearsion.config[:adhearsion_ldap].port = "389" | ||
lambda { Adhearsion::Plugin.init_plugins }.should raise_error "Must supply a valid port to the LDAP configuration" | ||
end | ||
end | ||
|
||
describe "when starting the LDAP connection" do | ||
before do | ||
Adhearsion.config[:adhearsion_ldap].host = "localhost" | ||
Adhearsion::LDAP::Plugin::Service.any_instance.should_receive(:require_models).and_return true | ||
end | ||
|
||
after do | ||
reset_adhearsion_ldap_config | ||
end | ||
|
||
it "should call Connection.start method with the valid parameters" do | ||
Adhearsion::LDAP::Plugin::Service.any_instance.should_receive(:establish_connection).with("localhost", 389, "", "", "", false, false).and_return true | ||
Adhearsion::Plugin.init_plugins | ||
end | ||
|
||
end | ||
|
||
end |
Oops, something went wrong.