本文介绍了被动STS中的自定义SecurityTokenHandler的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我的自定义SecurityTokenHandler出了问题。我的  customUserNameSecurityTokenHandler类已加载,但从未调用过(ValidateToken)。该项目是从vs2010菜单(新网站... ASP.NET STS网站)创建的。

Hello, i got a problem with my custom SecurityTokenHandler. My customUserNameSecurityTokenHandler class is loaded but is it never called ( ValidateToken ). The project was created from vs2010 menu (New web site ... ASP.NET STS Web site)

任何想法?

CustomUserNameSecurityTokenHandler Class

CustomUserNameSecurityTokenHandler Class


public class CustomUserNameSecurityTokenHandler : WindowsUserNameSecurityTokenHandler 
{

 public CustomUserNameSecurityTokenHandler()
 {
 }

 public override bool CanValidateToken
 {
 get
 {
 return true;
 }
 }

 public override ClaimsIdentityCollection ValidateToken(SecurityToken token)
 {
 UserNameSecurityToken userNameToken = token as UserNameSecurityToken;

 if (userNameToken == null)
	throw new SecurityException(string.Format("Invalid token provided: {0}. Expecting UserNameSecurityToken.", token.GetType()));

 ExtraredUserProvider credentialStore = new ExtraredUserProvider();

 // Authenticate the caller against the credential store.
 if (credentialStore.ValidateUser(userNameToken.UserName, userNameToken.Password) == false)
	throw new SecurityTokenValidationException("El usuario o contraseña es incorrecto");

 UserInformation userInfo = credentialStore.GetUserInformation(userNameToken.UserName);

 ClaimsIdentityCollection identities = new ClaimsIdentityCollection();
 ClaimsIdentity claimsIdentity = new ClaimsIdentity("CustomUserNameSecurityTokenHandler");

 claimsIdentity.Claims.Add(new Claim(System.IdentityModel.Claims.ClaimTypes.Name, userNameToken.UserName));
 claimsIdentity.Claims.Add(new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/ExtraredUserCode", userInfo.ExtraredUserCode.ToString()));

 identities.Add(claimsIdentity);

 return identities;
 }
 }

推荐答案


这篇关于被动STS中的自定义SecurityTokenHandler的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 21:52