New Posts New Posts RSS Feed: Windows Authentication & LoginViewModel
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Windows Authentication & LoginViewModel

 Post Reply Post Reply
Author
jlozina View Drop Down
Newbie
Newbie


Joined: 20-Jul-2011
Posts: 9
Post Options Post Options   Quote jlozina Quote  Post ReplyReply Direct Link To This Post Topic: Windows Authentication & LoginViewModel
    Posted: 23-Jul-2012 at 5:39am
Hi
 
I was looking at at the LoginViewModel and was wondering how you would be able to login using WindowsIdentity & WindowsPrincipal instead of the ILoginCredential?
 
Regards,
Joe
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: 23-Jul-2012 at 9:31am

To use Windows authentication you have to setup ASP.NET security and set authentication mode to Windows.

 
 
Then you login with null as the credential. You can do this directly in the bootstrapper in StartRuntime or StartRuntimeAsync. This will pick up your current Windows principal and log you in.
Back to Top
jlozina View Drop Down
Newbie
Newbie


Joined: 20-Jul-2011
Posts: 9
Post Options Post Options   Quote jlozina Quote  Post ReplyReply Direct Link To This Post Posted: 24-Jul-2012 at 6:27am
Hi
 
I tried using ASP.NET security but I get a exception, IdeaBlade.EntityModel.LoginException was unhandled by user code  Message=Credentials are required exception at C:\projects\TempHire\Security\LoginManager.cs:line 29
 
 
I commented out the Login() in the ShellViewModel
 
I placed the following at the bottom of the App.config

<system.web>

<authentication mode="Windows" />
</system.web>
</configuration>
 
and the Bootstrapper code is
public class AppBootstrapper : BootstrapperBase<ShellViewModel>{

[Import]

private IAuthenticationService authenticationService;

protected override IEnumerable<IResult> StartRuntimeAsync(){

yield return authenticationService.LoginAsync(null).ContinueOnError();

}}

If you could tell me where I went wrong, I would appreciate it.

 
Regards,
Joe
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: 24-Jul-2012 at 9:04am
First, ASP.NET security needs to be configured in the web.config and not the app.config. Is this WPF or Silverlight?
 
Then, did you follow the instructions at the very top of the link above to configure DevForce to use ASP.NET security?
 
 

In order to use ASP.NET security in DevForce you must set the UseAspNetSecurityServices flag in the web.config or server .config to enable it. When enabled, DevForce will use the AspAuthenticatingLoginManager to handle login requests from clients.

XML
<objectServer>
<serverSettings useAspNetSecurityServices="true" />
</objectServer>

You must also enable AspNetCompatibility in order to allow the DevForce services to integrate with ASP.NET services. You set this in the system.serviceModel configuration section. Here's the relevant element in the system.serviceModel section:

XML
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>

You must enable the ASP.NET services you wish to use in the system.web configuration section of the config file, as well as choose the type of authentication wanted. These steps are described below.

Back to Top
jlozina View Drop Down
Newbie
Newbie


Joined: 20-Jul-2011
Posts: 9
Post Options Post Options   Quote jlozina Quote  Post ReplyReply Direct Link To This Post Posted: 25-Jul-2012 at 6:22pm
This is for a WPF application.

Are the instructions above for WPF or Silverlight?
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: 25-Jul-2012 at 7:39pm
They are for both, but in case of WPF, they only apply to an n-tier IIS deployment as in order to use ASP.NET security you need to deploy the EntityServer to IIS.
 
If you are building a 2-tier WPF application or run the EntityServer from the command line or as a Windows service, then you have to implement your own LoginManager that grabs the WindowsPrincipal upon login. The following shows how you can accomplish this in a 2-tier application. You can adapt the code accordingly for the other two scenarios.
 
    public class AppBootstrapper : FrameworkBootstrapper<MainViewModel>
    {
        private IAuthenticationService _authenticationService;
 
        static AppBootstrapper()
        {
            AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
        }
 
        protected override void PrepareCompositionContainer(CompositionBatch batch)
        {
            base.PrepareCompositionContainer(batch);
            batch.AddExportedValue(_authenticationService = new AuthenticationService());
        }
 
        protected override void StartRuntime()
        {
            base.StartRuntime();
            _authenticationService.Login(null);
        }
    }
    public class WindowsLoginManager : IEntityLoginManager
    {
        #region IEntityLoginManager Members
 
        public IPrincipal Login(ILoginCredential credential, EntityManager entityManager)
        {
            return Thread.CurrentPrincipal;
        }
 
        public void Logout(IPrincipal principal, EntityManager entityManager)
        {
        }
 
        #endregion
    }
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down