#1 2019-02-27 19:45:15

imperyal
Member
Registered: 2018-10-11
Posts: 54

Kill sessions on server

Hello!

I need to kill sessions from a specific user group on the server... Is this possible?

Thank you!

Offline

#2 2019-02-28 11:54:25

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Kill sessions on server

From the server side?

Use TSQLRestServer.fSessions.Lock / SessionDelete then fSessions.Unlock.

Offline

#3 2019-02-28 13:29:08

imperyal
Member
Registered: 2018-10-11
Posts: 54

Re: Kill sessions on server

SessionDelete is not public... I was trying to do this from an interface (TInjectableObjectRest), using self.Server

Offline

#4 2019-02-28 14:00:04

imperyal
Member
Registered: 2018-10-11
Posts: 54

Re: Kill sessions on server

I'm inheriting my own TSQLRestServer class, I can call SessionDelete now like advised on this topic,  but I can't call/find TSQLRestServer.fSessions.Lock.

Thank you!

Last edited by imperyal (2019-02-28 14:00:20)

Offline

#5 2019-02-28 14:48:00

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Kill sessions on server

There is a fSessions: TObjecTListLocked field in the TSQLRestServer class.

Offline

#6 2019-02-28 15:45:12

imperyal
Member
Registered: 2018-10-11
Posts: 54

Re: Kill sessions on server

Yes, that's right. But there is no Lock method on fSessions[] that I can find.

Offline

#7 2019-02-28 16:41:33

imperyal
Member
Registered: 2018-10-11
Posts: 54

Re: Kill sessions on server

Ok, I think that's TSQLRestServer.fSessions.Safe.Lock / TSQLRestServer.fSessions.Safe.Unlock

wink

Let's hope I don't need any additional help, Thank you.

Offline

#8 2019-02-28 17:16:13

imperyal
Member
Registered: 2018-10-11
Posts: 54

Re: Kill sessions on server

For other people that may need something like this:

procedure TDCS_ServerDB.kill_otherGroupSessions(Ctxt: TSQLRestServerURIContext);
var
  i:           integer;
  currSession: TAuthSession;
begin
  self.fSessions.Safe.Lock;

  for i := self.fSessions.Count - 1 downto 0 do
      begin
      currSession := (self.fSessions[i] as TAuthSession);

      if (currSession.GroupID     = Ctxt.SessionGroup) and
         (currSession.IDCardinal <> Ctxt.Session)      then
         self.SessionDelete(i, Ctxt);
      end;

  self.fSessions.Safe.UnLock;
end;

I think this is OK. Any suggestions ab?

Thank you for prompt help.

Offline

#9 2019-02-28 18:09:17

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Kill sessions on server

A little try  ... finally between the Lock and the UnLock, for safety.

wink

Offline

#10 2019-02-28 20:12:24

imperyal
Member
Registered: 2018-10-11
Posts: 54

Re: Kill sessions on server

This is all implemented now and working as we want, nice!

Thank you wink

Offline

Board footer

Powered by FluxBB