-
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
1 parent
f6ad8ea
commit 26ecc8a
Showing
12 changed files
with
321 additions
and
75 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
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,32 +1,56 @@ | ||
# Getting started | ||
ahn-ldap | ||
======== | ||
|
||
*ahn-ldap* is an Adhearsion plugin that allows AHN configuration via LDAP. | ||
ahn-ldap is an Adhearsion Plugin providing LDAP connectivity. | ||
|
||
# Install | ||
Features | ||
-------- | ||
|
||
``` | ||
gem install ahn-ldap | ||
``` | ||
* FIXME (list of features and unsolved problems) | ||
|
||
Requirements | ||
------------ | ||
|
||
* Adhearsion 2.0+ | ||
|
||
If you include the dependency in your application Gemfile, that should be enough as Adhearsion loads the Bundler environment. | ||
Install | ||
------- | ||
|
||
If you use a gemspec or have just added it to your gems folder, include the line below in the script/ahn file: | ||
Add `ahn-ldap` to your Adhearsion app's Gemfile. | ||
|
||
Configuration | ||
------------- | ||
|
||
In your Adhearsion app configuration file, add the following values: | ||
|
||
```ruby | ||
require 'adhearsion' | ||
require 'adhearsion/cli_commands' | ||
require 'ahn-ldap' | ||
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 | ||
end | ||
``` | ||
|
||
# Note on Patches/Pull Requests | ||
Links | ||
----- | ||
* [Source](https://github.com/adhearsion/ahn-ldap) | ||
* [Documentation](http://rdoc.info/github/adhearsion/ahn-ldap/master/frames) | ||
* [Bug Tracker](https://github.com/adhearsion/ahn-ldap/issues) | ||
|
||
Note on Patches/Pull Requests | ||
----------------------------- | ||
|
||
* Fork the project. | ||
* Make your feature addition or bug fix. | ||
* Add tests for it. This is important so I don't break it in a future version unintentionally. | ||
* Commit, do not mess with rakefile, version, or history. | ||
* If you want to have your own version, that is fine but bump version in a commit by itself so I can ignore when I pull | ||
* If you want to have your own version, that is fine but bump version in a commit by itself so I can ignore when I pull | ||
* Send me a pull request. Bonus points for topic branches. | ||
|
||
# Copyright | ||
Copyright | ||
--------- | ||
|
||
Check [License file](https://github.com/adhearsion/ahn-ldap/blob/master/LICENSE) | ||
Check [License file](https://github.com/adhearsion/ahn-ldap/blob/master/LICENSE) |
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,16 @@ | ||
require "bundler/gem_tasks" | ||
|
||
require "bundler/setup" | ||
|
||
|
||
task :default => :spec | ||
|
||
require 'rspec/core' | ||
require 'rspec/core/rake_task' | ||
|
||
RSpec::Core::RakeTask.new(:spec) do |spec| | ||
spec.pattern = 'spec/**/*_spec.rb' | ||
spec.rspec_opts = '--colour --format doc' | ||
end | ||
|
||
task :default => :spec |
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 |
---|---|---|
|
@@ -5,8 +5,8 @@ require "ahn_ldap/version" | |
Gem::Specification.new do |s| | ||
s.name = "ahn-ldap" | ||
s.version = AhnLDAP::VERSION | ||
s.authors = ["Taylor Carpenter"] | ||
s.email = ["[email protected]"] | ||
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} | ||
|
@@ -20,15 +20,8 @@ Gem::Specification.new do |s| | |
|
||
# s.add_runtime_dependency %q<adhearsion>, [">= 2.0.0"] | ||
s.add_runtime_dependency %q<activesupport>, [">= 3.0.10"] | ||
s.add_runtime_dependency "active_ldap" | ||
|
||
s.add_development_dependency %q<bundler>, ["~> 1.0.0"] | ||
s.add_development_dependency %q<bundler>, ["~> 1.0"] | ||
s.add_development_dependency %q<rspec>, [">= 2.5.0"] | ||
s.add_development_dependency %q<ci_reporter>, [">= 1.6.3"] | ||
s.add_development_dependency %q<simplecov>, [">= 0"] | ||
s.add_development_dependency %q<simplecov-rcov>, [">= 0"] | ||
s.add_development_dependency %q<yard>, ["~> 0.6.0"] | ||
s.add_development_dependency %q<rake>, [">= 0"] | ||
s.add_development_dependency %q<mocha>, [">= 0"] | ||
s.add_development_dependency %q<guard-rspec> | ||
#s.add_development_dependency %q<bones> | ||
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 |
---|---|---|
@@ -1,10 +1,17 @@ | ||
require 'adhearsion' | ||
require 'active_support/dependencies/autoload' | ||
require 'ahn_ldap/version' | ||
require 'adhearsion/ldap' | ||
|
||
class AhnLdapPlugin < Adhearsion::Plugin | ||
init :ldap do | ||
Ldap.start if AHN_CONFIG.ldap_enabled? | ||
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 "ahn_ldap/version" | ||
require "ahn_ldap/plugin" | ||
|
||
module AhnLDAP | ||
|
||
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,36 @@ | ||
|
||
module AhnLDAP | ||
|
||
## | ||
# 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 :ahn_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)" | ||
end | ||
|
||
# Include the LDAP service in plugins initialization process | ||
init :ahn_ldap do | ||
Service.start | ||
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,64 @@ | ||
module AhnLDAP | ||
class Plugin | ||
class Service | ||
|
||
class << self | ||
|
||
## | ||
# 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 | ||
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 | ||
Adhearsion.config.files_from_setting("paths", "models").each do |model| | ||
load model | ||
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[:ahn_ldap] | ||
end | ||
end | ||
end # Service | ||
end # Plugin | ||
end # AhnLDAP |
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,3 +1,3 @@ | ||
module AhnLDAP | ||
VERSION = "0.0.1" | ||
VERSION = "0.1.0" | ||
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 @@ | ||
require 'spec_helper' | ||
|
||
describe AhnLDAP::Plugin::Service do | ||
|
||
describe "while initializing" do | ||
after do | ||
reset_ahn_ldap_config | ||
end | ||
|
||
it "should raise an exception when no host has been configured" do | ||
lambda {Adhearsion::Plugin.load}.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[:ahn_ldap].host = "localhost" | ||
Adhearsion.config[:ahn_ldap].port = "389" | ||
lambda {Adhearsion::Plugin.load}.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[:ahn_ldap].host = "localhost" | ||
end | ||
|
||
after do | ||
reset_ahn_ldap_config | ||
end | ||
|
||
it "should call Connection.start method with the valid parameters" do | ||
AhnLDAP::Plugin::Service.should_receive(:establish_connection).with("localhost", 389, "", "", "", false, false).and_return true | ||
Adhearsion.config.should_receive(:files_from_setting).with("paths", "models").and_return [] | ||
Adhearsion::Plugin.load | ||
end | ||
|
||
end | ||
|
||
end |
Oops, something went wrong.