New Posts New Posts RSS Feed: Authentication context and problem with entity manager
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Authentication context and problem with entity manager

 Post Reply Post Reply
Author
pponzano View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Apr-2011
Location: Italy
Posts: 165
Post Options Post Options   Quote pponzano Quote  Post ReplyReply Direct Link To This Post Topic: Authentication context and problem with entity manager
    Posted: 11-Apr-2012 at 12:07am
Hello,
I've got a console application on wich I use the IAuthenticationService to login... I correctly login and it saves the principal but then I call the entitymanager and execute a method I got an exception that the user is not logged in...

in my program.cs I've a configure method that's

   private void Configure()
        {
            IAuthenticationService authenticationService = IoC.Get<IAuthenticationService>();

            if (authenticationService != null)
            {
                string userName = ConfigurationManager.AppSettings["username"];
                string password = ConfigurationManager.AppSettings["password"];
                myLoginCredential loginCredential = new myLoginCredential(userName, password);

                authenticationService.Login(loginCredential); //here it logs and the AuthenticationContext is ok
            }
        }

When I call my repository

private bool PopulateSqlData(DateTime data)

       {

           bool isOk = false;

 

           var sw = new Stopwatch();

 

           sw.Start();

 

           try

           {

               repository.GeneratoreReportmyMethod(id, data);

           }

           catch (Exception ex)

           {

               NLog.LogManager.GetLogger("exception").ErrorException("PopulateSqlData", ex);

               return false;

           }

 

           sw.Stop();

           string str = string.Format("Tempo impiegato per popolare le tabelle dati {0}", sw.Elapsed.ToString());

 

           NLog.LogManager.GetLogger("generatore").Info(str);

           return isOk;

       }


I get a call to the loginmanager on the server


   public IPrincipal Login(ILoginCredential credential, EntityManager entityManager)
   {

//credential is null here

   }


In my old version using DAF I was calling LinkForAuthentication...what am I doing wrong?
Thanks
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: 11-Apr-2012 at 1:08am
Well, you are using Cocktail in a console application. Cocktail doesn't come with a bootstrapper that correctly composes a console app, so you are most likely missing many pieces trying to shoehorn Cocktail into a console application. 

In this particular case the EntityManager isn't getting the AuthenticationContext assigned, because the hook is missing somewhere. In a Silverlight or WPF application, which are the only two platforms officially supported by Cocktail, the FrameworkBootstrapper makes sure that every EntityManager gets the AuthenticationContext assigned. 

Modifying the Configure method like follows may get you a little further:

private void Configure()
        {
            IAuthenticationService authenticationService = IoC.Get<IAuthenticationService>();

   EntityManager.EntityManagerCreated += (sender, args) => args.EntityManager.AuthenticationContext = authenticationService.AuthenticationContext;

            if (authenticationService != null)
            {
                string userName = ConfigurationManager.AppSettings["username"];
                string password = ConfigurationManager.AppSettings["password"];
                myLoginCredential loginCredential = new myLoginCredential(userName, password);

                authenticationService.Login(loginCredential); //here it logs and the AuthenticationContext is ok
            }
        }
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down