Hi Dilip,
Thanks for your replies. Please find the code below.
protected override string AuthenticateToken( UsernameToken token )
{
if(!obj.ValidateUser(token.Username, token.Password))
{
//return any invalid password which will throw authendication failed
message.
return DateTime.Now.ToLongDateString();
}
else
{
IIdentity id = new GenericIdentity(token.Username);
//This line creates a principal for the given identity with the list of
roles and returns the principal after setting Thread.CurrentPrincipal to the
principal object created
token.Principal = CustomSecurity.AttachPrincipal(id);
Thread.CurrentPrincipal = token.Principal;
return token.Password;
}
}
I have created a class CustomPrincipal extending IPrincipal interface. That
is being returned from CustomSecurity.AttachPrincipal method.
Following is the simple version of my web method.
[WebMethod]
public string RetriveAllAppliedBuilds()
{
string userName = System.Threading.Thread.CurrentPrincipal.Identity.Name;
return userName ;
}
Thanks.
Regards,
-Suresh.
[quoted text, click to view] "Dilip Krishnan" wrote:
> Hello Scribnar,
> Could you post your code please?
>
> HTH
> Regards,
> Dilip Krishnan
> MCAD, MCSD.net
> dkrishnan at geniant dot com
>
http://www.geniant.com >
> > Hi,
> >
> > I set the token.Principal and Thread.CurrentPrincipal to
> > CustomPrincipal in my CustomUsernameTokenManager.AuthenticateToken
> > method. When i try accessing the same in my WebMethod, i'm able to
> > access the CustomPrincipal only through the token.Principal variable.
> > When i try with Thread.CurrentPrincipal, it does not have the
> > CustomPrincipal object in it because of which username and the roles
> > list is empty.
> >
> > One might argue why i need to try this. The Business components i have
> > written takes the logged in users name and role list from the
> > Thread.CurrentPrincipal so what ever type of application is using the
> > Business component just need to set the Thread.CurrentPrincipal. I
> > would not want set toekn.Principal instead Thread.CurrentPrincipal.
> > Does anyone know why Thread.CurrentPrincipal is not giving my
> > CustomPrincipal that i set in AuthenticateToken method?
> >
> > Thanks in Advance!
> >
>
>