You are not logged in.
Pages: 1
I am new to mORMot framework. I have a project (proof of concept really) that is loosely based on your demo project 14 - using interface classes - no direct db access.
It implements a single class (at the moment) with a bunch of methods. It works fine with dummy user using TSQLRestServerAuthenticationNone
but I actually need to authenticate against a custom authentication provider (existing external system that I have a delphi class for already that works - just not with your framework as yet)
I tried creating a custom authentication by doing:
TSQLAuthUserESI = class(TSQLAuthUser)
<snip code - just a bunch of properties that are in addition to your std username and pwd and are needed for locating and connecting to the authentication server so Server, port , role , environment all are RawUTF8 except for port which is integer >
TSQLRestServerAuthenticationEsi = class(TSQLRestServerAuthenticationURI)
protected
class function ClientComputeSessionKey(Sender: TSQLRestClientURI; User: TSQLAuthUser): RawUTF8; override;
public
function RetrieveSession(Ctxt: TSQLRestServerURIContext): TAuthSession; override;
function Auth(Ctxt: TSQLRestServerURIContext): boolean; override;
class function ClientSignIn(Sender: TSQLRestClientURI; const aUserName, aPassword,aServer: RawUTF8;
const aPort: integer; const sEnvironment, sRole: RawUTF8
): RawUTF8; virtual;
constructor Create(aServer: TSQLRestServer); override;
end;
But In my implementation of the new auth class methods in a bunch of spots I am running up against issues accessing protected methods of your ancestor classes, because unlike your ones, my classes are not in the same pas unit as your base classes.
example:
class function TSQLRestServerAuthenticationEsi.ClientSignIn(
Sender: TSQLRestClientURI; const aUserName, aPassword, aServer: RawUTF8;
const aPort: integer; const sEnvironment, sRole: RawUTF8): RawUTF8;
var U: TSQLAuthUserESIJDE;
begin
result := 'FAIL';
if Sender=nil then exit;
try
Sender.SessionClose; // **** Cannot access protected symbol TSQLRestClientURI.SessionClose
U := TSQLAuthUserESIJDE.Create;
try
U.LogonName := trim(uppercase(aUserName));
U.PasswordPlain := aPassword; // compute SHA256('salt'+aPassword);
//etc ...
result := Sender.SessionCreate(self,U,ClientComputeSessionKey(Sender,U)); // ***** TSQLRestClientURI.SessionCreate protected method
fServer.SessionCreate(User,Ctxt,Session); // ***** protected method ...
So I guess I have 2 questions ;-)
1) Am I even doing the right thing here trying to create my own auth and user classes or can I just avoid auth altogether and do it later after I get my class custom instance?
2) If I am doing the right thing - how do I get it to work? If not how do I avoid the need for setuser call- if I remove it then I seem to be unable to get the instance of my class due to 403 error.
Some more info:
I am using sicPerSession life for the classes.
I can for example in a (non mormot) vcl delphi app do:
mycon := Tmycon.create();
MyCon.Server := 'someserver';
MyCon.user := 'someuser';
MyCon.pwd := 'somepwd';
MyCon.role :='somerole';
MyCon.Environment := 'someEnvironment';
...
if MyCon.connect then
begin
mycon.Dosomething(some params);
mycon.dosomethingelse(some other params);
end;
mycon.free;
I want one instance of my Tmycon class per client session plus some other classes of my own code that uses that instance of Tmycon to make further calls to mycon and process the results etc. prior to passing results back to the REST client. For performance each session should process in it's own thread. Tmycon is not talking to a traditional database but to a special system exposed though an api via the tmycon component.
So I create the interface and server class that exposes the fn's I want (as per your demo proj 14). That class (Tconnector) internally creates and uses a instance of my (non mormot) Tmycon class.
(so far very simple but will expand it ...)
But in my client code (depending what button the user selects etc. I need to call something like:
TSQLRestServerAuthenticationNone.ClientSetUser(Client,'User',''); // want to get rid of this bit - it is useless and confusing to other customers ...
Client.ServiceRegister([TypeInfo(IConnector)],sicPerSession)
if Client.Services['Connector'].Get(I) then
begin
if i.sigon('someserver',''someuser','somepwd',''somerole','someenvironment') then
i.dosomething(someparams ...)
end
So I either
1) need a way to tell your system - I want a session but don't want to call ClientSetUser at all I just want it to allow anyone to start a session when the first Client.Services['Connector'].Get(I) is called (ie when teh contract get statement arrives at server
I think this may be possible as some calls like getsessiontimestamp or synchronizetimestamp don't seem to require auth having being done at all ...
or
2) need a way to create a custom class so I can instead do:
if TSQLRestServerAuthenticationESI.sigon (Client,'someserver','someuser','somepwd','somerole','someenvironment') = 'SUCCESS' then ...
We will provide a default delphi client using mormot but our customers will be using their own systems (not always delphi) to talk to my http server - so I need the rest calls to be as simple and few as possible they will be generating and processing the calls without the benefit or your framework on the client end in many cases ...
Hope this makes sense ...
Pages: 1