Skip to content

Commit

Permalink
return bool resp on successful ldap authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
RamanaReddy0M committed Oct 1, 2024
1 parent d161485 commit e5660b7
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pkg/js/libs/ldap/ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,27 +155,29 @@ 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="))
}
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
Expand All @@ -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
Expand Down

0 comments on commit e5660b7

Please sign in to comment.