Hi,everybody
look below code in page 119 of Web Service Security
Scenarios, Patterns, and Implementation Guidance
for Web Services Enhancements (WSE) 3.0:
protected override string AuthenticateToken( UsernameToken token )
{
bool validCredentials = Membership.ValidateUser(token.Username,
token.Password);
if (!validCredentials)
{
throw new ApplicationException(Resources.Messages.AuthenticationError);
}
GenericIdentity identity = new GenericIdentity(token.Username);
GenericPrincipal principal = new GenericPrincipal(identity,
Roles.GetRolesForUser(token.Username));
token.Principal = principal;
return token.Password;
}
Do invoke AuthenticateToken method for each request?if yes,that have any
performance problem?
Because I wonder this thing,so I do that:
protected override string AuthenticateToken(UsernameToken token)
{
if (token.PasswordOption != PasswordOption.SendPlainText)
throw new ArgumentException("token is only SendPlainText");
string password = token.Password;
Microsoft.Practices.EnterpriseLibrary.Security.IToken cacheToken =
new MyCacheToken(token.Username);
IPrincipal principal=
Microsoft.Practices.EnterpriseLibrary.Security.ISecurityCacheProvider.Ge
tPrincipal(cacheToken);
if (principal == null)
{
bool isAuth = Membership.ValidateUser(token.Username, password);
if (isAuth)
{
principal= MyPrincipal.Create(cacheToken);
}
else
{
this.OnLogonUserFailed(token);
}
}
token.Principal = principal;
return password;
}
My code is right?
Pablo Cibraro - 13 Feb 2006 14:24 GMT
Hi Kevin,
You are right, the AuthenticateToken method is invoked for each request if
that request contains an UsernameToken.
In my opinion, the best approach in this case is to use SecureConversation.
When SecureConversation is enabled, the token negotiation happens once
compared to other turn-key scenarios where the negotiation is done for each
message. (As a result, the method AuthenticateToken is only called the first
time).
Regards,
Pablo Cibraro
http://weblogs.asp.net/cibrax
http://www.lagash.com
> Hi,everybody
>
[quoted text clipped - 49 lines]
>
> My code is right?
Kevin - 22 Feb 2006 09:43 GMT
But I do each invoke,I always create a proxy instance.
SecureConversation is only for one proxy instance,not for new instance.
> Hi Kevin,
> You are right, the AuthenticateToken method is invoked for each
[quoted text clipped - 9 lines]
> http://weblogs.asp.net/cibrax
> http://www.lagash.com