Project

hydra-ldap

0.01
No release in over 3 years
Low commit activity in last 3 years
A gem for managing groups with ldap
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
>= 0

Runtime

 Project Readme

Hydra::LDAP

Build Status Contribution Guidelines

A gem for managing ldap groups used with hydra

Installation

Add this line to your application's Gemfile:

gem 'hydra-ldap'

And then execute:

$ bundle

Or install it yourself as:

$ gem install hydra-ldap

Usage

Create the config file (config/ldap.yml) by running:

rails generate hydra-ldap

Made the filters, attributes and result parsing all parameters as frequently as possible, to try and make this usable to many LDAP directory set ups.

It might be helpful to look at the hydra-ldap-example.ldif, config/hydra-ldap.yml and spec/integration/ldap_spec.rb to see what type of configuration the tests are running for comparison purposes.

The attributes here would change based on LDAP configuration.

attrs = {
  :cn => 'Test'
  :objectclass => 'groupofnames'
  :description => 'my test group contains users, and owners'
  :owner => 'uid=abc123'
  :member => ['john', 'jane', 'fido']
  }
Hydra::LDAP.create_group(group_code, attributes{})

Examples of how to customize the results being returned, print out the cn attribute for the groups owned by this user (hoping these are helpful for NU).

filter = Net::LDAP::Filter.construct("(owner=uid=quentin,ou=people,dc=example,dc=org)")
Hydra::LDAP.groups_owned_by_user(filter, ['owner', 'cn']){ |result| result.map{ |r| puts r[:cn].first } }
uid = 'uid'
filter=Net::LDAP::Filter.construct("(&(objectClass=groupofnames)(member=uid=#{uid}))")
attributes = ['cn']
Hydra::LDAP.groups_for_user(filter, attributes){ |result| result.map { |r| r[:cn].first }}
filter = Net::LDAP::Filter.construct("(cn=#{group_code})")
attributes = ['default attribute is description']
Hydra::LDAP.title_of_group(group_code, filter, attributes){ |result| result.first[:description].first }
filter = Net::LDAP::Filter.construct("(cn=#{group_code})")
Hydra::LDAP.users_for_group(group_code, filter, ['member']){ |result| result.first[:uniquemember].map{ |r| r.sub(/^uid=/, '') }}
filter = Net::LDAP::Filter.construct("(cn=#{group_code})")
Hydra::LDAP.owner_for_group(group_code, filter, ['owner']) { |result| result.first[:owner].map{ |r| r.sub(/^uid=/, '') }}

These are all pretty similar to previous calls, if not the same signatures.

Hydra::LDAP.delete_group(group_code).should be_true
Hydra::LDAP.add_users_to_group(group_code, ['bruce', 'beth'])
Hydra::LDAP.remove_users_from_group(group_code, ['bruce'])

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request