Print Page | Close Window

Windows Authentication & LoginViewModel

Printed From: IdeaBlade
Category: Cocktail
Forum Name: Community Forum
Forum Discription: A professional application framework using Caliburn.Micro and DevForce
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3551
Printed Date: 28-Mar-2024 at 7:24am


Topic: Windows Authentication & LoginViewModel
Posted By: jlozina
Subject: Windows Authentication & LoginViewModel
Date 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



Replies:
Posted By: mgood
Date Posted: 23-Jul-2012 at 9:31am

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

 
http://drc.ideablade.com/xwiki/bin/view/Documentation/security-aspnet#HWindowsAuthentication -


Posted By: jlozina
Date 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


Posted By: mgood
Date 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?
 
http://drc.ideablade.com/xwiki/bin/view/Documentation/security-aspnet - http://drc.ideablade.com/xwiki/bin/view/Documentation/security-aspnet
 

In order to use ASP.NET security in DevForce you must set the http://drc.ideablade.com/ApiDocumentation/webframe.html?IdeaBlade.Core~IdeaBlade.Core.Configuration.ServerSettingsElement~UseAspNetSecurityServices.html - http://drc.ideablade.com/ApiDocumentation/webframe.html?IdeaBlade.EntityModel.Web~IdeaBlade.EntityModel.Web.AspAuthenticatingLoginManager.html -

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

You must also enable http://drc.ideablade.com/ApiDocumentation/webframe.html?IdeaBlade.EntityModel.Web~IdeaBlade.EntityModel.Web.AspAuthenticatingLoginManager~AspNetCompatibilityEnabled.html -

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.



Posted By: jlozina
Date Posted: 25-Jul-2012 at 6:22pm
This is for a WPF application.

Are the instructions above for WPF or Silverlight?


Posted By: mgood
Date 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
    }



Print Page | Close Window