add starttls support,
add starttls option to config
This commit is contained in:
parent
fd84f9a991
commit
99242b70a0
@ -15,6 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var LDAPSessions map[string]*LDAPClient
|
var LDAPSessions map[string]*LDAPClient
|
||||||
|
var AppVersion = "1.0.5"
|
||||||
var APIVersion = "1.0.4"
|
var APIVersion = "1.0.4"
|
||||||
|
|
||||||
func Run() {
|
func Run() {
|
||||||
@ -47,7 +48,7 @@ func Run() {
|
|||||||
LDAPSessions = make(map[string]*LDAPClient)
|
LDAPSessions = make(map[string]*LDAPClient)
|
||||||
|
|
||||||
router.GET("/version", func(c *gin.Context) {
|
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) {
|
router.POST("/ticket", func(c *gin.Context) {
|
||||||
@ -93,7 +94,7 @@ func Run() {
|
|||||||
uuid := SessionUUID.(string)
|
uuid := SessionUUID.(string)
|
||||||
delete(LDAPSessions, uuid)
|
delete(LDAPSessions, uuid)
|
||||||
session.Options(sessions.Options{MaxAge: -1}) // set max age to -1 so it is deleted
|
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})
|
c.JSON(http.StatusUnauthorized, gin.H{"auth": false})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
12
app/ldap.go
12
app/ldap.go
@ -1,6 +1,7 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -20,6 +21,17 @@ type LDAPClient struct {
|
|||||||
// returns a new LDAPClient from the config
|
// returns a new LDAPClient from the config
|
||||||
func NewLDAPClient(config Config) (*LDAPClient, error) {
|
func NewLDAPClient(config Config) (*LDAPClient, error) {
|
||||||
LDAPConn, err := ldap.DialURL(config.LdapURL)
|
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{
|
return &LDAPClient{
|
||||||
client: LDAPConn,
|
client: LDAPConn,
|
||||||
basedn: config.BaseDN,
|
basedn: config.BaseDN,
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
ListenPort int `json:"listenPort"`
|
ListenPort int `json:"listenPort"`
|
||||||
LdapURL string `json:"ldapURL"`
|
LdapURL string `json:"ldapURL"`
|
||||||
|
StartTLS bool `json:"startTLS"`
|
||||||
BaseDN string `json:"baseDN"`
|
BaseDN string `json:"baseDN"`
|
||||||
SessionSecretKey string `json:"sessionSecretKey"`
|
SessionSecretKey string `json:"sessionSecretKey"`
|
||||||
SessionCookieName string `json:"sessionCookieName"`
|
SessionCookieName string `json:"sessionCookieName"`
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"listenPort": 80,
|
"listenPort": 80,
|
||||||
"ldapURL": "ldap://localhost",
|
"ldapURL": "ldap://localhost",
|
||||||
|
"startTLS": true,
|
||||||
"basedn": "dc=example,dc=com",
|
"basedn": "dc=example,dc=com",
|
||||||
"sessionSecretKey": "super secret key",
|
"sessionSecretKey": "super secret key",
|
||||||
"sessionCookieName": "PAASLDAPAuthTicket",
|
"sessionCookieName": "PAASLDAPAuthTicket",
|
||||||
|
Loading…
Reference in New Issue
Block a user