Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UserTypeProperty to get user type from ldap user entry #3744

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/add-ldap-usertype-attribute.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Add LDAP user type attribute

Adding an LDAP attribute so that we can distinguish between member and guest users.

https://github.com/cs3org/reva/pull/3744
2 changes: 1 addition & 1 deletion pkg/auth/manager/ldap/ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (am *mgr) Authenticate(ctx context.Context, clientID, clientSecret string)
userID := &user.UserId{
Idp: am.c.Idp,
OpaqueId: uid,
Type: user.UserType_USER_TYPE_PRIMARY, // TODO: assign the appropriate user type
Type: am.c.LDAPIdentity.GetUserType(userEntry),
}
gwc, err := pool.GetGatewayServiceClient(am.c.GatewaySvc)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/user/manager/ldap/ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,6 @@ func (m *manager) ldapEntryToUserID(entry *ldap.Entry) (*userpb.UserId, error) {
return &userpb.UserId{
Idp: m.c.Idp,
OpaqueId: uid,
Type: userpb.UserType_USER_TYPE_PRIMARY,
Type: m.c.LDAPIdentity.GetUserType(entry),
}, nil
}
20 changes: 20 additions & 0 deletions pkg/utils/ldap/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"strings"

identityUser "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
"github.com/cs3org/reva/v2/pkg/errtypes"
"github.com/go-ldap/ldap/v3"
"github.com/google/uuid"
Expand All @@ -43,6 +44,7 @@ type userConfig struct {
Objectclass string `mapstructure:"user_objectclass"`
DisableMechanism string `mapstructure:"user_disable_mechanism"`
EnabledProperty string `mapstructure:"user_enabled_property"`
UserTypeProperty string `mapstructure:"user_type_property"`
Schema userSchema `mapstructure:"user_schema"`
SubstringFilterType string `mapstructure:"user_substring_filter_type"`
substringFilterVal int
Expand Down Expand Up @@ -207,6 +209,8 @@ func (i *Identity) GetLDAPUserByFilter(log *zerolog.Logger, lc ldap.Client, filt
i.User.Schema.Username,
i.User.Schema.UIDNumber,
i.User.Schema.GIDNumber,
i.User.EnabledProperty,
i.User.UserTypeProperty,
},
nil,
)
Expand Down Expand Up @@ -246,6 +250,7 @@ func (i *Identity) GetLDAPUserByDN(log *zerolog.Logger, lc ldap.Client, dn strin
i.User.Schema.Username,
i.User.Schema.UIDNumber,
i.User.Schema.GIDNumber,
i.User.EnabledProperty,
},
nil,
)
Expand Down Expand Up @@ -277,6 +282,8 @@ func (i *Identity) GetLDAPUsers(log *zerolog.Logger, lc ldap.Client, query strin
i.User.Schema.DisplayName,
i.User.Schema.UIDNumber,
i.User.Schema.GIDNumber,
i.User.EnabledProperty,
i.User.UserTypeProperty,
},
nil,
)
Expand Down Expand Up @@ -685,3 +692,16 @@ func (i *Identity) getGroupAttributeFilter(attribute, value string) (string, err
value,
), nil
}

// GetUserType is used to get the proper UserType from ldap entry string
func (i *Identity) GetUserType(userEntry *ldap.Entry) identityUser.UserType {
userTypeString := userEntry.GetEqualFoldAttributeValue(i.User.UserTypeProperty)
switch strings.ToLower(userTypeString) {
case "member":
return identityUser.UserType_USER_TYPE_PRIMARY
case "guest":
return identityUser.UserType_USER_TYPE_GUEST
default:
return identityUser.UserType_USER_TYPE_PRIMARY
}
}