#1 2019-11-07 09:13:36

Georg
Member
Registered: 2016-11-22
Posts: 18

Problem with GroupRights in AuthUser table when creating new User

Hello,

I used the sample 14 (interfaced based services, Project14ServerExternal) and tried to add a new user at the startup of the server like this:

function CreateUser(const ServerL: TSQLRestServer; const strLogon, strDisplay, strPassword: String): Boolean;
var AuthUser: TSQLAuthUser;
    AuthGroup: TSQLAuthGroup;
begin
  AuthGroup := TSQLAuthGroup.Create(ServerL, 'Ident=''User''');
  AuthUser := TSQLAuthUser.Create(ServerL, 'LogonName=''' + StringToUTF8(strLogon) + '''');
  try
    if Assigned(AuthUser) and (AuthUser.ID > 0) then
      Result := False
    else
    begin
      if not Assigned(AuthUser) then
        AuthUser := TSQLAuthUser.Create;
      AuthUser.LogonName := StringToUTF8(strLogon);
      AuthUser.DisplayName := StringToUTF8(strDisplay);
      AuthUser.PasswordPlain := StringToUTF8(strPassword);
      AuthUser.GroupRights := AuthGroup;
      ServerL.Add(AuthUser, True);
      Result := True;
    end;
  finally
    AuthUser.Free;
    AuthGroup.Free;
  end;
end;

I put the call to this function in the server programm directly after CreateMissingTables.
What I expected was that this would create a new user that is part of the group "User".

When I check in the sqlite database, the new user has GroupRights=49224560 in the AuthUser table, but I would have expected GroupRights=3 (since the new user should be in the "User" group with Id=3).
This new user is not able to call the interface methods, only when I change the GroupRights to 3 manually does the user account work as expected.

Thanks in advance for your help.

Offline

#2 2019-11-07 09:37:59

pvn0
Member
From: Slovenia
Registered: 2018-02-12
Posts: 211

Re: Problem with GroupRights in AuthUser table when creating new User

Change to this :
AuthUser.GroupRights := AuthGroup.IDValue;

Then it will be as expected smile

Best regards

Offline

#3 2019-11-07 10:18:23

Georg
Member
Registered: 2016-11-22
Posts: 18

Re: Problem with GroupRights in AuthUser table when creating new User

Thanks for your answer, unfortunately, this does not work (it results in a compiler error "incompatible types" in Delphi).

AuthUser.GroupRights is of the type TSQLAuthGroup, not TID.

Best regards

Offline

#4 2019-11-07 10:21:47

pvn0
Member
From: Slovenia
Registered: 2018-02-12
Posts: 211

Re: Problem with GroupRights in AuthUser table when creating new User

Sorry I forgot you need to typecast it
AuthUser.GroupRights := TSQLAuthGroup(AuthGroup.IDValue);

For additional info check into class procedure TSQLAuthGroup.InitializeTable which will show you how the default groups and users are set up.

Last edited by pvn0 (2019-11-07 10:24:37)

Offline

#5 2019-11-07 10:32:39

Georg
Member
Registered: 2016-11-22
Posts: 18

Re: Problem with GroupRights in AuthUser table when creating new User

Thank you very much for your help and the hint with InitializeTable.
I didn't think that such a cast would be allowed.

Best regards

Offline

Board footer

Powered by FluxBB