New Posts New Posts RSS Feed: LoginManager and server side
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

LoginManager and server side

 Post Reply Post Reply
Author
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Topic: LoginManager and server side
    Posted: 09-Jun-2011 at 11:50am
midnit,
 
I could not verify the behavior you described.
 
In an Interceptor, if I try:
 
var newEm = new EntityManager(EntityManager);
var employees = newEm.GetQuery<Employee>().ToList();
 
newEm will be logged in and it will not trigger the LoginManager.
However, if I try:
 
var newEm = new EntityManager();
var employees = newEm.GetQuery<Employee>().ToList();
 
newEm will not be logged in and the LoginManager will be triggered when the query is executed. (expected behavior)
 
Can you provide a simple solution reproducing your issue?
 
Silvio.
 
 
 
Back to Top
midnit View Drop Down
Senior Member
Senior Member
Avatar

Joined: 22-Jun-2009
Location: Charlotte
Posts: 112
Post Options Post Options   Quote midnit Quote  Post ReplyReply Direct Link To This Post Posted: 09-Jun-2011 at 3:28am
In my case, the newEm says its logged in, but if you query or something it hits my LoginManager - at which point I don't have any credentials to use...which leads to using the .Login(sessionkey).

Edited by midnit - 09-Jun-2011 at 3:31am
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 08-Jun-2011 at 11:48am
Regarding linking an EM to the EntityManager in the SaveInterceptor,
var newEm = new SomeEntityManager(this.EntityManager);
 
the newEm will be logged in as well.
 
 
As for using Login(Guid SessionKey), it takes a "different route" (i.e. internal route) than Login(ILoginCredential credential) and doesn't actually go thru your login manager.
 
I can't think of a way of detecting where the login is coming from. I will double check with our senior engineer.
However, since the LoginManager is only triggered when using Login(ILoginCredential credential), the common case would be it being triggered by the client. That's unless you are passing credentials to a RSMC, have it hardcoded in the interceptors, or simply is logging in with null credentials.
 
Silvio.


Edited by sbelini - 08-Jun-2011 at 11:51am
Back to Top
midnit View Drop Down
Senior Member
Senior Member
Avatar

Joined: 22-Jun-2009
Location: Charlotte
Posts: 112
Post Options Post Options   Quote midnit Quote  Post ReplyReply Direct Link To This Post Posted: 08-Jun-2011 at 6:27am
Indeed. I did not mean to imply that I was unable to work around the inconsistency (missing Principal) - if I write enough code. I have started this work but it could be avoided if the entitymanager.principal was populated as elsewhere.
 
What of linking an entitymanager to the entitymanager in a saveinterceptor? I presume the one is logged in, but when you use it to link a new entitymanager the new one is not logged in. Something like...
class SaveStuffInterceptor : EntityServerSaveInterceptor
{
     protected override bool ExecuteSave() {
          var newEm = new SomeEntityManager(this.EntityManager);
     }
}
Anything done with newEm will trigger log in...but isn't this.EntityManager logged in? If you use the sessionkey the loginmanager is avoided.
class SaveStuffInterceptor : EntityServerSaveInterceptor
{
     protected override bool ExecuteSave() {
          var newEm = new SomeEntityManager();
          newEm.Login(this.EntityManager.SessionKey);
     }
}
I had just assumed if one worked the other would - or vice versa. Obviously I was wrong, just wondering why.
 
 
Per the IsClient. I was meaning that in the LoginManager I saw no way to detect if the login was triggered via the client or server (ie. serverside I create an entitymanager and log it in vs create one on the client and log it in). Is there a way?
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 07-Jun-2011 at 5:27pm
Hi midnit,
When you create an Entity Manager in the client, it's not logged in.
If you don't explicitly login, but tries to perform and operation (i.e. query/save) the Entity Manager will automatically login as a Guest (assuming you allow guest users - in your app.config). Logged in, but not authenticated.
In the server the base type EntityManager will be logged in and, if the client is authenicated, authenticated as well. Even though you cannot access the Principal via EntityManager.Principal, you can do so via the Save/QueryInterceptor (i.e. this.Principal) with all the information would find in the client's EM.Principal.
Regarding your second post, wouldn't passing the Principal from the Interceptor (i.e. this.Principal) to the audit code resolve the issue? (if you wanted the code to be the same in the client and server, couldn't you pass mgr.Principal from the client as well?)
As for your last post, in my tests my local (i.e. in the client) mgr.IsClient will return true while my SaveInterceptor's EntityManager.IsClient will return false. Can you provide a simple test case reproducing the issue?
Regards,
      sbelini.
Back to Top
midnit View Drop Down
Senior Member
Senior Member
Avatar

Joined: 22-Jun-2009
Location: Charlotte
Posts: 112
Post Options Post Options   Quote midnit Quote  Post ReplyReply Direct Link To This Post Posted: 07-Jun-2011 at 9:07am

Is there any way to test in the LoginManager if this is coming from the server?

I tried EntityManager.IsClient when our app initially logs in and it returns false. Testing when triggered in the saveinterceptor and it returns false also.
 
Please answer everything, not just this last post.
Back to Top
midnit View Drop Down
Senior Member
Senior Member
Avatar

Joined: 22-Jun-2009
Location: Charlotte
Posts: 112
Post Options Post Options   Quote midnit Quote  Post ReplyReply Direct Link To This Post Posted: 07-Jun-2011 at 8:59am
A bit more info...
 
We have some audit code that tracks who edited what. When an entity is touched (add, edit, delete) it uses...or was trying to use...the Principal of the EntityManager to attached these actions to the user in question.
 
Once we improved our security so every action must be truely logged in this no longer works. It works fine when edits are triggered from the client, but from the server, as in the saveinterceptor, Principal is null so though I can confirm( kinda) that the EntityManager is logged in (has a session key) I can't rely on the Principal existing. If I create an entity in the saveinterceptor when the audit code checks entity.EntityAspect.EntityManager.Principal it cries profusely. This code doesn't know its triggered in a saveinterceptor and has no access to the this.Principal. This would work if the Principal wasn't null.
 
In the previous thread it was mentioned that populating the Principal should be possible...where did that end up?
 
Also, if you create a new EntityManager and pass in the EntityManager from the save interceptor to link it...it does nothing. Any reason this couldn't be made to work too?
 
Am I beating a red-headed step child (SaveInterceptor)? I have considered moving this around but thats not a quick fix.
Back to Top
midnit View Drop Down
Senior Member
Senior Member
Avatar

Joined: 22-Jun-2009
Location: Charlotte
Posts: 112
Post Options Post Options   Quote midnit Quote  Post ReplyReply Direct Link To This Post Posted: 07-Jun-2011 at 8:34am
My first question, which isn't causing me an issue...I just didnt understand it: Why does the entityManager in the Login always show IsLoggedIn=true? This is in an IEntityLoginManager, the entityManager passed in always shows IsLoggedIn=true - at least in my case.  The one in a saveinterceptor is always true too.
 
What can I use to test that an EntityManager is logged in? Its not the IsLoggedIn, its not the Principal. Maybe SessionKey? What can I use that will work 100% of the time and not depend on what EntityManager is handling the Entity?
 
Also this goes back to a thread I started a while ago about the Principal being null on the EntityManager. Its causing me big headaches right now. I am assuming an EntityManager will be logged in and I need to use the Principal for context of the update - or I have to figure a different way to pass around who is logged in which seems I shouldn't have to do since the EntityManager is handling logging me in and in most cases has the Principal and in some cases the IsLoggedIn is accurate.
 
 
 


Edited by midnit - 07-Jun-2011 at 8:45am
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down