Custom Authentication
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=1891
Printed Date: 21-Apr-2026 at 3:49pm
Topic: Custom Authentication
Posted By: jmarbutt
Subject: Custom Authentication
Date Posted: 12-Jun-2010 at 8:53am
I am getting the following error when trying to implement a custom IEntityLoginManager:
The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://ideablade.com/EntityModel:LoginResult. The InnerException message was 'Element 'http://ideablade.com/EntityModel:Principal' contains data of the 'http://schemas.datacontract.org/2004/07/System.Security.Principal:GenericPrincipal' data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to 'GenericPrincipal' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.
Element 'http://ideablade.com/EntityModel:Principal' contains data of the 'http://schemas.datacontract.org/2004/07/System.Security.Principal:GenericPrincipal' data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to 'GenericPrincipal' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.
----------------
This is based on the example in the documentation:
public System.Security.Principal.IPrincipal Login(ILoginCredential credential, EntityManager entityManager)
{
// Disallow null credentials and throw a LoginException
if (credential == null) {
throw new LoginException( LoginExceptionType.NoCredentials, "Credentials not supplied");
}
//HttpContext.Current
// Build a simple Principal/Identity. You may return any serializable
// types implementing IPrincipal.
GenericIdentity identity = new GenericIdentity(credential.UserName);
GenericPrincipal principal = new GenericPrincipal(identity, new string[] { });
return principal;
}
------------------
What am I doing wrong?
|
Replies:
Posted By: kimj
Date Posted: 12-Jun-2010 at 9:25am
|
GenericPrincipal and GenericIdentity aren't actually defined in the Silverlight libraries. In DF2009 we'd defined these types within our assemblies, but in DF2010 we dropped that. You can sub-type UserBase and UserIdentity, or you can implement your own IPrincipal and IIdentity types, making sure that the classes are serializable.
|
Posted By: jmarbutt
Date Posted: 12-Jun-2010 at 9:40am
Do you have an example of that?
I think I am find the biggest thing with DevForce is finding the answers for the latest version. I know documentation is tough, but it seems like there have a been a ton of changes that make it to where you can't even search on stuff to find the correct answer. Also the docs seem a little scattered or need a better way to search the learning resources.
|
Posted By: kimj
Date Posted: 12-Jun-2010 at 10:48am
|
Here's an example, taken from one of the security samples (ASP.NET Profile) -
[DataContract] public class CustomUser : UserBase {
public CustomUser(IIdentity identity, IEnumerable<string> roles) : base(identity, roles) { }
[DataMember] public bool WindowSeat { get; set; }
[DataMember] public string Building { get; set; }
}
Since the class will be used on both the server and in SL, be sure to add a link in your SL project to the file containing the class.
|
|