我想实现我的自定义安全到wcf,我想使用ServiceAuthenticationManager,但我不明白它如何可以阻止消息。我试图抛出异常,但我不能得到我的异常详细信息我得到的只是“请求错误”在rest调用和“调用者没有被服务验证”在soap调用,但我不能得到我的自定义错误信息,ServiceAuthenticationManager的正确用法是什么,或者我应该阻止消息?
public class MyAuthenticationManager : ServiceAuthenticationManager
{
public override ReadOnlyCollection<IAuthorizationPolicy> Authenticate(ReadOnlyCollection<IAuthorizationPolicy> authPolicy, Uri listenUri, ref Message message)
{
//throw new AuthenticationException("Credentials expired!");
throw new SecurityException("my custom message:Invalid authentication");
return base.Authenticate(authPolicy, listenUri,ref message);
}
}发布于 2017-12-14 17:51:13
身份验证/授权不提供自定义消息。任何你没有被授权或验证的迹象都是攻击者破解你的安全或获取他无权获得的信息的一种方式。
例如,说“您的密码是错误的”就表示用户名存在。那是很糟糕的。未经授权的请求永远不应获得此类信息作为响应。
如果您想查看哪里出了问题,请写入服务器管理员可以访问的日志。但不要向客户发送任何内容。永远不会。
所以总结一下:不,你不能得到一个自定义消息,这个设计是故意的。
https://stackoverflow.com/questions/47808804
复制相似问题