From 04d8cb9acdae88c484f303aad9751177f93a0c97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Lapeyre?= Date: Fri, 20 May 2022 08:40:41 +0200 Subject: [PATCH] Update builtin/credential/ldap/backend.go Co-authored-by: Calvin Leung Huang <1883212+calvn@users.noreply.github.com> --- builtin/credential/ldap/backend.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/builtin/credential/ldap/backend.go b/builtin/credential/ldap/backend.go index 94562723fa9b5..bf15477a99504 100644 --- a/builtin/credential/ldap/backend.go +++ b/builtin/credential/ldap/backend.go @@ -195,15 +195,16 @@ func (b *backend) Login(ctx context.Context, req *logical.Request, username stri // Policies from each group may overlap policies = strutil.RemoveDuplicates(policies, true) - entityAliasAttribute := username - if !usernameAsAlias { - entityAliasAttribute, err = ldapClient.GetUserAliasAttributeValue(cfg.ConfigEntry, c, username) - if err != nil { - return "", nil, logical.ErrorResponse(err.Error()), nil, nil - } - if entityAliasAttribute == "" { - return "", nil, logical.ErrorResponse("missing entity alias attribute value"), nil, nil - } + if usernameAsAlias { + return username, policies, ldapResponse, allGroups, nil + } + + entityAliasAttribute, err = ldapClient.GetUserAliasAttributeValue(cfg.ConfigEntry, c, username) + if err != nil { + return "", nil, logical.ErrorResponse(err.Error()), nil, nil + } + if entityAliasAttribute == "" { + return "", nil, logical.ErrorResponse("missing entity alias attribute value"), nil, nil } return entityAliasAttribute, policies, ldapResponse, allGroups, nil