diff --git a/changelog/unreleased/user-and-group-name-mapping b/changelog/unreleased/user-and-group-name-mapping new file mode 100644 index 0000000000..95dedabd5d --- /dev/null +++ b/changelog/unreleased/user-and-group-name-mapping @@ -0,0 +1,6 @@ +Change: mint new username property in the reva token + +An accounts username is now taken from the on_premises_sam_account_name property instead of the preferred_name. +Furthermore the group name (also from on_premises_sam_account_name property) is now minted into the token as well. + +https://github.com/owncloud/ocis-proxy/pull/62 diff --git a/pkg/middleware/account_uuid.go b/pkg/middleware/account_uuid.go index 7eed9eaf0a..529dfc67af 100644 --- a/pkg/middleware/account_uuid.go +++ b/pkg/middleware/account_uuid.go @@ -65,10 +65,11 @@ func createAccount(l log.Logger, claims *oidc.StandardClaims, ac acc.AccountsSer // TODO check if fields are missing. req := &acc.CreateAccountRequest{ Account: &acc.Account{ - DisplayName: claims.DisplayName, - PreferredName: claims.PreferredUsername, - Mail: claims.Email, - CreationType: "LocalAccount", + DisplayName: claims.DisplayName, + PreferredName: claims.PreferredUsername, + OnPremisesSamAccountName: claims.PreferredUsername, + Mail: claims.Email, + CreationType: "LocalAccount", }, } created, err := ac.CreateAccount(context.Background(), req) @@ -125,16 +126,22 @@ func AccountUUID(opts ...Option) func(next http.Handler) http.Handler { return } + groups := make([]string, len(account.MemberOf)) + for i := range account.MemberOf { + // reva needs the unix group name + groups[i] = account.MemberOf[i].OnPremisesSamAccountName + } + l.Debug().Interface("claims", claims).Interface("account", account).Msgf("Associated claims with uuid") token, err := tokenManager.MintToken(r.Context(), &revauser.User{ Id: &revauser.UserId{ OpaqueId: account.Id, }, - Username: account.PreferredName, + Username: account.OnPremisesSamAccountName, DisplayName: account.DisplayName, Mail: account.Mail, MailVerified: account.ExternalUserState == "" || account.ExternalUserState == "Accepted", - // TODO groups + Groups: groups, }) if err != nil {