Skip to content

Commit

Permalink
Merge branch 'release/0.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
benlangfeld committed Jan 18, 2012
2 parents 7ba99d9 + 85d43fe commit e2af2c3
Show file tree
Hide file tree
Showing 18 changed files with 284 additions and 279 deletions.
2 changes: 0 additions & 2 deletions Gemfile
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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ In your Adhearsion app configuration file, add the following values:

```ruby
Adhearsion.config do |config|
config.ahn_ldap.host = "valid-host"
config.ahn_ldap.port = "valid-port".to_i # 389 by default
config.ahn_ldap.base = "valid-ldap-base"
config.ahn_ldap.bind_dn = "valid-ldap-binding"
config.ahn_ldap.allallow_anonymous = true # false
config.ahn_ldap.try_sasl = true # false
config.adhearsion_ldap.host = "valid-host"
config.adhearsion_ldap.port = "valid-port".to_i # 389 by default
config.adhearsion_ldap.base = "valid-ldap-base"
config.adhearsion_ldap.bind_dn = "valid-ldap-binding"
config.adhearsion_ldap.allallow_anonymous = true # false
config.adhearsion_ldap.try_sasl = true # false
end
```

Expand Down
10 changes: 5 additions & 5 deletions ahn-ldap.gemspec → adhearsion-ldap.gemspec
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"

Expand Down
1 change: 1 addition & 0 deletions lib/adhearsion-ldap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'adhearsion/ldap'
21 changes: 16 additions & 5 deletions lib/adhearsion/ldap.rb
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
38 changes: 38 additions & 0 deletions lib/adhearsion/ldap/plugin.rb
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
72 changes: 72 additions & 0 deletions lib/adhearsion/ldap/plugin/service.rb
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
5 changes: 5 additions & 0 deletions lib/adhearsion/ldap/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Adhearsion
module LDAP
VERSION = "0.1.0"
end
end
17 changes: 0 additions & 17 deletions lib/ahn_ldap.rb

This file was deleted.

36 changes: 0 additions & 36 deletions lib/ahn_ldap/plugin.rb

This file was deleted.

64 changes: 0 additions & 64 deletions lib/ahn_ldap/plugin/service.rb

This file was deleted.

3 changes: 0 additions & 3 deletions lib/ahn_ldap/version.rb

This file was deleted.

38 changes: 38 additions & 0 deletions spec/adhearsion/ldap/plugin/service_spec.rb
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
Loading

0 comments on commit e2af2c3

Please sign in to comment.