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

Custom Authentication

 Post Reply Post Reply
Author
xer0ne View Drop Down
Newbie
Newbie
Avatar

Joined: 16-Mar-2011
Posts: 2
Post Options Post Options   Quote xer0ne Quote  Post ReplyReply Direct Link To This Post Topic: Custom Authentication
    Posted: 16-Mar-2011 at 9:12pm
Hi,

I having problems with customizing the login process, here is what i've done so far

 I'm  using these settings in the web.config

<objectServer remoteBaseURL="http://localhost">
      <clientSettings isDistributed="false"/>
      <serverSettings useAspNetSecurityServices="true" loginManagerRequired="true" allowAnonymousLogin="true" />      
 </objectServer>

*I used the devforce Business application template jetpack theme for silverlight. 
* move around the some of the template files to a wcf ria class library. build ok
* created a class to Implement IEntityLoginManager, put it on my wcf .net class project
 public partial class LoginManager : IEntityLoginManager
    {
        public IPrincipal Login(ILoginCredential credential, EntityManager entityManager)
        {
            LoginCredential guestCredential =  new LoginCredential("Guest"string.Empty, string.Empty);
 
            if (credential == null)            
                credential = guestCredential;                
                
            else
            {                           
                MainRoot svcRoot = new MainRoot(); //EF created from devforce that contains the usernames and password            
 
                InfoUser entUser = svcRoot.InfoUsers.Where(p => p.UserName == credential.UserName && p.Password == credential.Password)
                    .SingleOrDefault();
 
                if (entUser != null)
                {
 
                }
            }
 
            return CreatePrincipalUser(credential);
        }
 
        public void Logout(IPrincipal principal, EntityManager entityManager)
        {
            //no special processing needed
        }
 
        private IPrincipal CreatePrincipalUser(ILoginCredential credential)
        {            
            var identity = new UserIdentity(credential.UserName);
            var principal = new UserProfile(identity, new string[] { });
 
            return principal;
        }
}

* made a query Interceptor
 public class QueryInterceptor : EntityServerQueryInterceptor
    {
        protected override bool AuthorizeQuery()
        {
            //return base.AuthorizeQuery();
 
            bool blnAllowed = false;
 
            if (this.Principal.Identity.IsAuthenticated)
                blnAllowed = true;
            else
            {
                if (this.Query.ElementType == typeof(InfoUser))
                    blnAllowed = true;                
            }
 
            return blnAllowed;
        }
    }
* I did not touch the authenticationManager leave it as is. well change the user property to my user type.
now the problem is the one highlighted in orange, it saying inner exception, something to do with defaultmanager,
 basically what im trying to do is login the user, lookup the credential on that table and authenticate but the problem is the 
EntityManager need to be login first, so i made a guest credentials, but it get logout by the authenticationmanager every time 
a user would login, so i get a entityManager.Principal = null, if i don't logout the guest user,
 it will not carry on the login process and my custom login is not called.
I need this working so continue a prototype using your product. the documentation is not helping much on what i'm trying to accomplished.

Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1390
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 18-Mar-2011 at 6:06pm
Creating a new MainRoot EntityManager is causing the bad behavior.  Every EntityManager will actually try to login, whether it's being used on the client or not.  That's why the Login method is passed an EntityManager - this is a "logged in", connected EntityManager which you can use to run queries.  So in this case, if you instead do:
 
  MainRoot svcRoot = new MainRoot(entityManager)
 
... you can construct your domain-specific EM from the logged in EM, and then run your InfoUsers query.
 
Back to Top
xer0ne View Drop Down
Newbie
Newbie
Avatar

Joined: 16-Mar-2011
Posts: 2
Post Options Post Options   Quote xer0ne Quote  Post ReplyReply Direct Link To This Post Posted: 21-Mar-2011 at 3:21am
Ok, I will try that,

One more thing, why does IsAuthenticated always false, I tried using formsauthentication and still not authenticated.
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1390
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 21-Mar-2011 at 10:49am
The UserIdentity constructor you're using defaults IsAuthenticated to false.   Use:
 
  new UserIdentity(name, type, isAuthentication)
 
to create an authenticated user.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down