New Posts New Posts RSS Feed: Login Exception with IEntityLoginManager
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Login Exception with IEntityLoginManager

 Post Reply Post Reply
Author
LesleySastro View Drop Down
Newbie
Newbie


Joined: 13-Nov-2008
Posts: 9
Post Options Post Options   Quote LesleySastro Quote  Post ReplyReply Direct Link To This Post Topic: Login Exception with IEntityLoginManager
    Posted: 28-Nov-2008 at 1:14pm

I'm writing some unit tests to test my domain model. When testing the login procedure I am getting the following exception

IdeaBlade.EntityModel.v4.LoginException: Failed to login before using EntityManager or submitted null credentials..
 
I don't know what is causing this problem, because I don't have null credentials. This exception is thrown when in the Login method of my IEntityLoginManager derived class, I am trying to get the user from the backend and compare the username and password of the User entity with the given credentials. At this point the EntityManager is not logged in, because that is what I'm trying to do with this method. BTW, I used to do this in DevForce Classic with no problems.
 
Did anyone encounter the same problem and know what the fix is?
Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 01-Dec-2008 at 3:06pm
You can't access the back-end datastore with an unauthenticated EntityManager unless it knows it's a server-side EntityManager.  The EntityManager that's passed into the Login() method is a server-side one, but it lacks the static EntityQuery properties (e.g., em1.Users) that your specialized EntityManager type (e.g., DomainModelEntityManager) includes. So you have a couple of choices:
 
     1. Use the ExecuteQuery<T>() method on the provided EntityManager to execute your query, or
     2. Create a specialized DomainModelEntityManager using the constructor that takes another EntityManager as a parameter, and forward the one passed to Login().
 
            DomainModelEntityManager manager = new DomainModelEntityManager(pManager);
 
Then you can use invoke the manager.Users property.
 
My guess is that in v3 you used (directly) the PersistenceManager that was passed into Login().
 
 

For reference, here's some commented code from my own from my implementation of IEntityLoginManager.Login() that spells it all out:

        public IPrincipal Login(ILoginCredential pCredential, EntityManager pManager) {
            // pManager is a server-side EntityManager and is authorized to access the
            // back-end data stores without authentication. However, it contains none of the
            // convenient EntityQuery<T> properties -- e.g., em.Users -- that are included
            // with its specialized offspring, the DomainModelEntityManager.  Therefore
            // to use it to retrieve data, you must go through its ExecuteQuery() methods:
            //   
            //    pManager.ExecuteQuery<User>(new EntityQuery<User>().Where(u => u.UserName == pUserName));
            //    
            // Alternatively, you can get a specialized DomainModelEntityManager for use,
            // but you must obtain it as follows:
 
            DomainModelEntityManager manager = new DomainModelEntityManager(pManager);
 
            // Creating your new EntityManager using the credentials of the existing
            // server-side one results in another server-side EntityManager. It therefore also
            // permits access to the backend datastore without authentication. As a bonus, it also
            // excludes the client-server communications overhead that a client-side
            // EntityManager normally carries.
            //    
            // Two things that don't work:
            //
            // 1. Direct casting of the passed-in EntityManager:
            //
            //    DomainModelEntityManager manager = (DomainModelEntityManager)pManager;
            //
            // 2. Creation of a new DomainModelEntityManager using the parameterless constructor:
            //
            //    DomainModelEntityManager manager = new DomainModelEntityManager();
            //
            // In the first case, the cast simply fails. In the second, you get a normal (client-side)
            // DomainModelEntityManager that doesn't permit data retrieval from the back-end
            // data sources without authentication.
 
 
Regards,
Greg
 
Back to Top
LesleySastro View Drop Down
Newbie
Newbie


Joined: 13-Nov-2008
Posts: 9
Post Options Post Options   Quote LesleySastro Quote  Post ReplyReply Direct Link To This Post Posted: 02-Dec-2008 at 6:20am
That makes sense, thanks Greg. Like you said in DevForce Classic I used the PersistenceManager directly passed into Login(). I also tried those two options (direct casting and parameterless constructor) with both giving me the aforementioned exception, that's why I was a little bit clueless. So the trick for me is actually using
 
var manager = new DomainModelEntityManager(pManager);
 
And that did it.
 
Will I have the same kind of problems with the implementation of IEntityServerSaving? I'm using this to implement an Audit Trail feature, and I have the following code
 

var manager = args.GetEntityManager();

var changedEntities = manager.FindEntities(EntityState.Added | EntityState.Modified | EntityState.Deleted);

foreach (var entity in new IterIsolate(changedEntities))

{// Check if it is an Auditable entity

if (entity.GetType().IsAssignableFrom(typeof(AuditableEntity)))

{

// If so, invoke the audit trail process

((AuditableEntity) entity).AuditSelf((DomainModelEntityManager) manager, args.Principal);

}

}

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down