| Author |
Share Topic Topic Search Topic Options
|
Walid
Senior Member
Joined: 14-Nov-2010
Posts: 161
|
Post Options
Quote Reply
Topic: Seeding initial data Posted: 11-Mar-2012 at 6:34am |
Hello, I want to seed (and maintain) some data in a silverlight application, let's say, when the server starts (in the Application_Start method for example). I want the seed method to be called only one time, and thus before any user log in the system, so I think I need to have some kind of trusted server login for an EntityManager... Could you please provide some guidance or best practice for doing that ? Regards, Walid.
|
 |
mgood
IdeaBlade
Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
|
Post Options
Quote Reply
Posted: 12-Mar-2012 at 7:20pm |
|
A trusted server login is generally a bad idea. One never knows where to securely store the credentials. Seeding is normally done once at deployment time, so this sounds like a unique requirement that may need some consulting time to understand better and come up with a suitable approach for your situation.
|
 |
Walid
Senior Member
Joined: 14-Nov-2010
Posts: 161
|
Post Options
Quote Reply
Posted: 13-Mar-2012 at 1:29am |
Thank you Marcel. I have found that the EntityManager can execute queries before being authenticated, and thus during the authentication process. Is it a bad idea to use an EntityManager with copyconstructor at this point ? cause it seems to work fine... or maybe is it an unwanted feature or a bug ? Regards,
|
 |
mgood
IdeaBlade
Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
|
Post Options
Quote Reply
Posted: 13-Mar-2012 at 5:06am |
The EntityManager always needs to be authenticated before running a query. By default, if you don't authenticate the EntityManager yourself, it will automatically attempt to login as anonymous user as part of the first operation. You can disable anonymous access on the server and then the EntityManager will throw an exception if you try to run a query before authenticating. When you use the copy constructor, the authentication context carries over.
|
 |
Walid
Senior Member
Joined: 14-Nov-2010
Posts: 161
|
Post Options
Quote Reply
Posted: 13-Mar-2012 at 1:38pm |
Sorry Marcel but I found a moment when an entityManager doesn't need to be authenticated to execute queries... That occurs when executing the Login method of an IEntityLoginManager. (Of corse I have set allowAnonymousLogin in the web.config to false.) In that Login method I am supposed to query the database to check the user credentials... public class LoginManager : IEntityLoginManager { public virtual IPrincipal Login(ILoginCredential credential, EntityManager entityManager) { if (credential == null) throw new LoginException(LoginExceptionType.NoCredentials, "Credentials are required."); var myManager = new MyManager(entityManager); // myManager can query/SaveChanges without any authentication ! I have imagined a static class that verifies the minimal seed data and that can update it if needed, of corse I have made this initialization executed only once, at the first loggin after the server starts... Regards,
Edited by Walid - 13-Mar-2012 at 1:39pm
|
 |
smi-mark
DevForce MVP
Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
|
Post Options
Quote Reply
Posted: 13-Mar-2012 at 2:16pm |
|
That's because you are executing it on the server. A client cannot execute queries anonymously, but the server manager is not going through the LoginManager.
|
 |
Walid
Senior Member
Joined: 14-Nov-2010
Posts: 161
|
Post Options
Quote Reply
Posted: 16-Mar-2012 at 3:07pm |
Thank you smi-mark. So, my question is : how to anonymously execute a query server side ? (with allowAnonymousLogin being set to false) Regards,
|
 |
smi-mark
DevForce MVP
Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
|
Post Options
Quote Reply
Posted: 16-Mar-2012 at 3:24pm |
|
I'm not sure I understand the question - you can always execute a query from the server, with anonymous login enabled or not.
|
 |
mgood
IdeaBlade
Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
|
Post Options
Quote Reply
Posted: 16-Mar-2012 at 3:32pm |
Walid, The EntityManagers on the server that are passed to the LoginManager, Save/QueryInterceptors and server-side methods are special EntityManagers. They look the same, but they behave different because you are on the server and they were created by DF for the purpose. You can't new up one of those server EntityManagers yourself, except by using the copy constructor, which means you first have to get a server EntityManager from somewhere. That means a client has to initiate a request, but a client can't initate a request unless it gets authenticated first or you allow anonymous login.
|
 |
smi-mark
DevForce MVP
Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
|
Post Options
Quote Reply
Posted: 16-Mar-2012 at 3:40pm |
|
You could allow anonymous login but then use authorization to control what can be accessed.
http://drc.ideablade.com/xwiki/bin/view/Documentation/authorize
|
 |
Walid
Senior Member
Joined: 14-Nov-2010
Posts: 161
|
Post Options
Quote Reply
Posted: 16-Mar-2012 at 3:53pm |
Thank you for your answers. But that doesn't meet my needs. I'm trying to expose the problem diiferently : (every thing is executing on the server side) 1- Don't want to allow anonymous login 2- Need to implement custom authentication => implementing IEntitiyLoginManager... 3- Need to make some checks/updates each time application is started => implementing some actions in Global.asax.cs / Application_Start But when trying to execute some entity queries on custom manager it tries to login (with my custom login method) Is there any way to bypass this last process in order to let that entitymanager executing "anonymously" queries ? Hope I was clearer this time.
|
 |
smi-mark
DevForce MVP
Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
|
Post Options
Quote Reply
Posted: 16-Mar-2012 at 4:00pm |
|
I'll let Marcel chime in on this - but one possible option is to use another composition context that does not use the existing LoginManage, you could then use this context on your server manager which bypasses the LoginManager.
|
 |
Walid
Senior Member
Joined: 14-Nov-2010
Posts: 161
|
Post Options
Quote Reply
Posted: 18-Mar-2012 at 7:37am |
Thank you smi-mark You have shown me the right way... using alternative CompositionContext that didn't use the existing LogniManager gave me a good way to do what I want.
|
 |