New Posts New Posts RSS Feed: Pre Login Access to Entitymanager
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Pre Login Access to Entitymanager

 Post Reply Post Reply
Author
siko View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Mar-2012
Posts: 27
Post Options Post Options   Quote siko Quote  Post ReplyReply Direct Link To This Post Topic: Pre Login Access to Entitymanager
    Posted: 26-Mar-2012 at 3:35am
Hi,
 
We'd like to provide a globalized Login experience, hence we need to access some data (texts/language) before we've logged a user in.
 
How would I go ahead and do that in Cocktail/DF ... It seems I cannot access the repository before I have established a security context (?)
 
Thanks,
 
Sij
Back to Top
siko View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Mar-2012
Posts: 27
Post Options Post Options   Quote siko Quote  Post ReplyReply Direct Link To This Post Posted: 26-Mar-2012 at 7:59am
I found the way to the fake login manager like the one that comes with TempHire ref.app.
However, the entitymanager does not return any results.
What is wrong here?
 
var securityEntitesManager = new SecurityEntities(compositionContextName: "Fake");
 //Finds the FakeLoginManager and returns UserPrincipal correctly.             
            var userTest = securityEntitesManager.SecurityUsers;
            
 
            var userForIp = securityEntitesManager.SecurityUsers.SingleOrDefault(u => u.ip_address.Trim() ==
                                                                                      HttpContext.Current.Request.
                                                                                          UserHostAddress.ToString(
                                                                                              CultureInfo.
                                                                                                  InvariantCulture).Trim
                                                                                          ());
 
Should I initialize the em differently?
Is this a supported scenario? (I need data before establishing a security context)
 
Thanks
Back to Top
siko View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Mar-2012
Posts: 27
Post Options Post Options   Quote siko Quote  Post ReplyReply Direct Link To This Post Posted: 26-Mar-2012 at 8:47am
Ok, diggin in and found what I was looking for.
 
I created a custom loginmanager (LocalLoginManager:LoginManager) and used the
CompositionContextResolver
to get the default CompositionContext while my UserIdentity is 'fake'.
 
Now I'm able to expose some of the data I need for the LoginView throuhg a default silverlight web service.
 
HTH some one some day.
 
Back to Top
siko View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Mar-2012
Posts: 27
Post Options Post Options   Quote siko Quote  Post ReplyReply Direct Link To This Post Posted: 27-Mar-2012 at 12:38am
Or ... is there a way I can do this with the entityserver?
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 27-Mar-2012 at 10:50am
I'm not quite understanding your question. In order to run queries before a formal login, you have two options. You allow anonymous logins or you have a known system login. The latter is not generally recommended, because you have to store the password somewhere in your application.
 
An anonymous login is a login with null credentials. An EntityManager that isn't already logged in, will automatically attempt to login anonymously upon the first operation that involves talking to the EntityServer.
 
So, in your LoginManager, you return a Principal that represents an anonymous user when you get null credentials. You don't have to use a CompositionContext. You just have to write your LoginManager such that it accepts null credentials. You should then secure your entities so that an anonymous user can only query the small set of data that is ok to be queried as an anonymous user, because otherwise your server is essentially wide open and anybody can query your entire database.
 
 
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 27-Mar-2012 at 11:38am
Forgot to mention one thing. In the latest version of Cocktail, EntityManagers no longer login implicitly if the AuthenticationService is found. In order to allow anonymous queries with the AuthenticationService present, you have to overwrite the EntityManager's AuthenticationContext. I would create a seperate repository to query the language data, which will overwrite it's EntityManger's AuthenticationContext to allow anonymous queries. You still have to implement your LoginManager to allow anonymous logins.
 
In the constructor of the repository, you can add the following line to overwrite the AC.
 
            entityManagerProvider.ManagerCreated +=
                (sender, args) => args.EntityManager.AuthenticationContext = AnonymousAuthenticationContext.Instance;
 


Edited by mgood - 27-Mar-2012 at 11:39am
Back to Top
siko View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Mar-2012
Posts: 27
Post Options Post Options   Quote siko Quote  Post ReplyReply Direct Link To This Post Posted: 07-Apr-2012 at 5:21pm
Thank you for this. When I'll revisit the code, I will take the above in consideration. Makes sense.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down