New Posts New Posts RSS Feed: Custom Authentication
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Custom Authentication

 Post Reply Post Reply
Author
jmarbutt View Drop Down
DevForce MVP
DevForce MVP


Joined: 04-Jun-2010
Posts: 17
Post Options Post Options   Quote jmarbutt Quote  Post ReplyReply Direct Link To This Post Topic: Custom Authentication
    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?
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
jmarbutt View Drop Down
DevForce MVP
DevForce MVP


Joined: 04-Jun-2010
Posts: 17
Post Options Post Options   Quote jmarbutt Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down