https://github.com/casdoor/ldapserver
Package ldapserver implements LDAP Server
https://github.com/casdoor/ldapserver
casdoor go golang ldap ldapserver
Last synced: 2 months ago
JSON representation
Package ldapserver implements LDAP Server
- Host: GitHub
- URL: https://github.com/casdoor/ldapserver
- Owner: casdoor
- License: mit
- Created: 2024-10-08T10:56:30.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-10-08T11:13:54.000Z (about 1 year ago)
- Last Synced: 2024-10-25T03:30:30.556Z (12 months ago)
- Topics: casdoor, go, golang, ldap, ldapserver
- Language: Go
- Homepage: https://github.com/casdoor/casdoor
- Size: 1.52 MB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://godoc.org/github.com/vjeantet/ldapserver)
[](https://travis-ci.org/vjeantet/ldapserver)**This package is a work in progress.**
**ldapserver** is a helper library for building server software capable of speaking the LDAP protocol. This could be an alternate implementation of LDAP, a custom LDAP proxy or even a completely different backend capable of "masquerading" its API as a LDAP Server.
The package supports
* All basic LDAP Operations (bind, search, add, compare, modify, delete, extended)
* SSL
* StartTLS
* Unbind request is implemented, but is handled internally to close the connection.
* Graceful stopping
* Basic request routing inspired by [net/http ServeMux](http://golang.org/pkg/net/http/#ServeMux)
* Logger customisation (log interface)# Default behaviors
## Abandon request
If you don't set a route to handle AbandonRequest, the package will handle it for you. (signal sent to message.Done chan)## No Route Found
When no route matches the request, the server will first try to call a special *NotFound* route, if nothing is specified, it will return an *UnwillingToResponse* Error code (53)Feel free to contribute, comment :)
# Sample Code
```Go
// Listen to 10389 port for LDAP Request
// and route bind request to the handleBind func
package mainimport (
"log"
"os"
"os/signal"
"syscall"ldap "github.com/vjeantet/ldapserver"
)func main() {
//ldap logger
ldap.Logger = log.New(os.Stdout, "[server] ", log.LstdFlags)//Create a new LDAP Server
server := ldap.NewServer()routes := ldap.NewRouteMux()
routes.Bind(handleBind)
server.Handle(routes)// listen on 10389
go server.ListenAndServe("127.0.0.1:10389")// When CTRL+C, SIGINT and SIGTERM signal occurs
// Then stop server gracefully
ch := make(chan os.Signal)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
<-ch
close(ch)server.Stop()
}// handleBind return Success if login == mysql
func handleBind(w ldap.ResponseWriter, m *ldap.Message) {
r := m.GetBindRequest()
res := ldap.NewBindResponse(ldap.LDAPResultSuccess)if string(r.Name()) == "myLogin" {
w.Write(res)
return
}log.Printf("Bind failed User=%s, Pass=%s", string(r.Name()), string(r.AuthenticationSimple()))
res.SetResultCode(ldap.LDAPResultInvalidCredentials)
res.SetDiagnosticMessage("invalid credentials")
w.Write(res)
}
```# more examples
Look into the "examples" folder