Skip to content
This repository has been archived by the owner on Dec 9, 2017. It is now read-only.

Commit

Permalink
more cleanups to the README
Browse files Browse the repository at this point in the history
  • Loading branch information
jcredding committed Aug 17, 2011
1 parent e7316ea commit 3ffc713
Showing 1 changed file with 54 additions and 13 deletions.
67 changes: 54 additions & 13 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -18,69 +18,110 @@ AD::LDAP is a small wrapper to the Net::LDAP library. Net::LDAP provides a nice
First, you need to configure the gem:

```ruby

AD::LDAP.configure do |config|
config.host = "127.0.0.1"
config.port = 389
config.base = "DC=mydomain, DC=com"
config.encrytion = :simple_tls
config.logger = Rails.logger
end

```

Then you can start running LDAP commands like you would with Net::LDAP.

```ruby
# logs your search and returns a collection of matching Net::LDAP::Entry

AD::LDAP.search({
:base => "DC=Users, DC=mydomain, DC=com",
:filter => "(name=collin)"
})

# most of the commands have the same syntax as they do in net-ldap
```

Most of the commands have the same syntax as they do in net-ldap:

```ruby

AD::LDAP.add({
:dn => "DN=collin, DC=Users, DC=mydomain, DC=com",
:attributes => { :givenname => "Collin", :lastname => "Redding" }
})

# some are slightly modified though
```

Some are slightly different though, the following:

```ruby

AD::LDAP.delete("DN=collin, DC=Users, DC=mydomain, DC=com")
# instead of: AD::LDAP.delete({ :dn => "DN=collin, DC=Users, DC=mydomain, DC=com })

```

The biggest feature of AD::LDAP is some of the conventions when using the search method. If I don't provide a filter and have extra keys not supported by net-ldap's search, these are converted to filters automatically for me:
is equivalent to:

```ruby
# searching for an object named "collin"

ldap = Net::LDAP.new
ldap.delete({ :dn => "DN=collin, DC=Users, DC=mydomain, DC=com })`
```
The biggest feature of AD::LDAP is some of the conventions when using the search method. If I don't provide a filter and have extra keys not supported by net-ldap's search, they are converted to filters automatically:
```ruby
AD::LDAP.search({ :name__eq => "collin" })
# the equality filter is defaulted so this can even be simplified to
```
which can be simplified even further:
```ruby
AD::LDAP.search({ :name => "collin" })
# multiple filters are supported and automatically joined (AND)
```
Multiple filters are joined together (Net::LDAP::Filter.join) by default:
```ruby
AD::LDAP.search({ :name => "collin", :objectclass => "user" })
# AD::LDAP doesn't get in your way if you need to do something complex though
```
AD::LDAP won't get in your wa if you need to do something complex:
```ruby
name_filter = Net::LDAP::Filter.eq("name", "collin*")
class_filter = Net::LDAP::Filter.eq("objectclass", "user")
filters = name_filter | class_filter
AD::LDAP.search({ :filter => filters, :size => 1 })
```
Finally, because the LDAP names for most fields are not very ruby-ish (are all one word) it's sometimes convenient to setup mappings from a more ruby friendly name to a LDAP name:
```ruby
AD::LDAP.configure do |config|
# ... use previous config here
# ...
config.mapppings = {
"login" => "samaccountname"
}
end
# you can use the mapping when performing a search
```
with the above config you can then search with the mapping:
```ruby
AD::LDAP.search({ :login => "jcredding" })
# which is equivalent to
AD::LDAP.search({ :samaccountname => "jcredding" })
```
## License
Expand Down

0 comments on commit 3ffc713

Please sign in to comment.