Print Page | Close Window

Windows auth

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2356
Printed Date: 28-Mar-2024 at 5:57am


Topic: Windows auth
Posted By: mikedfox
Subject: Windows auth
Date Posted: 08-Dec-2010 at 2:30pm
Do you have any samples that show using Windows auth against a custom security table in silverlight.
 
my web.config contains
 
  <objectServer>
<serverSettings allowAnonymousLogin="false"  />
  </objectServer>
  
  </ideablade.configuration>
  <system.web>
  <compilation debug="true" targetFramework="4.0" />
  <authentication mode="Windows" />
  </system.web>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
</system.serviceModel>
 
before querying my entitymanager I call 
Manager.LoginAsync(null, LoginCallback, null);
 
and in my LoginManager : IEntityLoginManager
the credential comes across as null. In the drc, it says that if you use a null in the 
call to LoginAsynch, and the credentials will be your windows credentials, but this doesn't seem to be working.
I need a sample to follow, or maybe someone can see what I missed in the configuration.





Replies:
Posted By: kimj
Date Posted: 08-Dec-2010 at 7:18pm
Sorry, we don't have a sample showing Windows ASP.NET authentication with a custom IEntityLoginManager.  The DRC is a bit misleading, since it's both assuming use ofthe AspNetAuthenticatingLoginManager and jumping ahead to the final result. 
 
The actual ILoginCredential passed into your Login method will be null, since that's what you passed from the client.  What the built-in login manager does, and what you need to do in your custom login manager, is grab the HttpContext.Current.User, which with Windows authentication enabled will be a WindowsPrincipal.   In the built-in manager we build a UserBase/UserIdentity from the WindowsPrincipal and return that from the login method.  Since the WindowsPrincipal can't be serialized to a Silverlight application you'll need to also build a UserBase/UserIdentity, or some other custom IPrincipal/IIdentity which can be serialized. 


Posted By: mikedfox
Date Posted: 09-Dec-2010 at 5:57am
I figured out the missing bit you mentioned. :)
 
Once I changed my login to
 
 
public IPrincipal Login(ILoginCredential credential, EntityManager entityManager)
{
var principal = new UserBase(HttpContext.Current.User.Identity);
return principal;
}
 
I get
 
" The Login could not be completed because the server did not respond.  Check that the server is available and contains a clientApplicationType='Silverlight' configuration setting."
 
I changed the serversettings in config to
<serverSettings allowAnonymousLogin="false"  loginManagerRequired="true" supportedClientApplicationType="Silverlight"/>
but that didn't help


Posted By: mikedfox
Date Posted: 09-Dec-2010 at 6:06am
doh, i figured out the last problem. I didn't folow your directions well enough :)
 
I was creating a UserBase from HttpContext.Current.User.Identity
 
Instead I needed to build a UserIdentity from  HttpContext.Current.User.Identity.Name, then build the new user base from that.
so the final form looks like
 
public IPrincipal Login(ILoginCredential credential, EntityManager entityManager)
{
var ident = new UserIdentity(HttpContext.Current.User.Identity.Name, "Custom"true);
var principal = new UserBase(ident);
return principal;
}
 
Thanks


Posted By: kimj
Date Posted: 09-Dec-2010 at 8:28am
Great!   Sorry I wasn't very clear - as you found neither WindowsPrincipal nor WindowsIdentity are serializable to Silverlight.



Print Page | Close Window