add starttls support,

add starttls option to config
This commit is contained in:
Arthur Lu 2024-10-18 04:38:26 +00:00
parent fd84f9a991
commit 99242b70a0
4 changed files with 17 additions and 2 deletions

View File

@ -15,6 +15,7 @@ import (
)
var LDAPSessions map[string]*LDAPClient
var AppVersion = "1.0.5"
var APIVersion = "1.0.4"
func Run() {
@ -47,7 +48,7 @@ func Run() {
LDAPSessions = make(map[string]*LDAPClient)
router.GET("/version", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"version": APIVersion})
c.JSON(http.StatusOK, gin.H{"version": APIVersion, "app-version": AppVersion})
})
router.POST("/ticket", func(c *gin.Context) {
@ -93,7 +94,7 @@ func Run() {
uuid := SessionUUID.(string)
delete(LDAPSessions, uuid)
session.Options(sessions.Options{MaxAge: -1}) // set max age to -1 so it is deleted
_ = session.Save()
session.Save()
c.JSON(http.StatusUnauthorized, gin.H{"auth": false})
})

View File

@ -1,6 +1,7 @@
package app
import (
"crypto/tls"
"errors"
"fmt"
"net/http"
@ -20,6 +21,17 @@ type LDAPClient struct {
// returns a new LDAPClient from the config
func NewLDAPClient(config Config) (*LDAPClient, error) {
LDAPConn, err := ldap.DialURL(config.LdapURL)
if err != nil {
return nil, err
}
if config.StartTLS {
err = LDAPConn.StartTLS(&tls.Config{InsecureSkipVerify: true})
if err != nil {
return nil, err
}
}
return &LDAPClient{
client: LDAPConn,
basedn: config.BaseDN,

View File

@ -11,6 +11,7 @@ import (
type Config struct {
ListenPort int `json:"listenPort"`
LdapURL string `json:"ldapURL"`
StartTLS bool `json:"startTLS"`
BaseDN string `json:"baseDN"`
SessionSecretKey string `json:"sessionSecretKey"`
SessionCookieName string `json:"sessionCookieName"`

View File

@ -1,6 +1,7 @@
{
"listenPort": 80,
"ldapURL": "ldap://localhost",
"startTLS": true,
"basedn": "dc=example,dc=com",
"sessionSecretKey": "super secret key",
"sessionCookieName": "PAASLDAPAuthTicket",