diff --git a/pkg/js/libs/ldap/ldap.go b/pkg/js/libs/ldap/ldap.go index 3961fa7b7e..e10015acfa 100644 --- a/pkg/js/libs/ldap/ldap.go +++ b/pkg/js/libs/ldap/ldap.go @@ -155,7 +155,7 @@ func NewClient(call goja.ConstructorCall, runtime *goja.Runtime) *goja.Object { // const client = new ldap.Client('ldap://ldap.example.com', 'acme.com'); // client.Authenticate('user', 'password'); // ``` -func (c *Client) Authenticate(username, password string) { +func (c *Client) Authenticate(username, password string) bool { c.nj.Require(c.conn != nil, "no existing connection") if c.BaseDN == "" { c.BaseDN = fmt.Sprintf("dc=%s", strings.Join(strings.Split(c.Realm, "."), ",dc=")) @@ -163,19 +163,21 @@ func (c *Client) Authenticate(username, password string) { if err := c.conn.NTLMBind(c.Realm, username, password); err == nil { // if bind with NTLMBind(), there is nothing // else to do, you are authenticated - return + return true } + var err error switch password { case "": - if err := c.conn.UnauthenticatedBind(username); err != nil { + if err = c.conn.UnauthenticatedBind(username); err != nil { c.nj.ThrowError(err) } default: - if err := c.conn.Bind(username, password); err != nil { + if err = c.conn.Bind(username, password); err != nil { c.nj.ThrowError(err) } } + return err == nil } // AuthenticateWithNTLMHash authenticates with the ldap server using the given username and NTLM hash @@ -185,14 +187,16 @@ func (c *Client) Authenticate(username, password string) { // const client = new ldap.Client('ldap://ldap.example.com', 'acme.com'); // client.AuthenticateWithNTLMHash('pdtm', 'hash'); // ``` -func (c *Client) AuthenticateWithNTLMHash(username, hash string) { +func (c *Client) AuthenticateWithNTLMHash(username, hash string) bool { c.nj.Require(c.conn != nil, "no existing connection") if c.BaseDN == "" { c.BaseDN = fmt.Sprintf("dc=%s", strings.Join(strings.Split(c.Realm, "."), ",dc=")) } - if err := c.conn.NTLMBindWithHash(c.Realm, username, hash); err != nil { + var err error + if err = c.conn.NTLMBindWithHash(c.Realm, username, hash); err != nil { c.nj.ThrowError(err) } + return err == nil } // Search accepts whatever filter and returns a list of maps having provided attributes