Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF ServiceAuthenticationManager扩展性_C#_Wcf_Wcf Security - Fatal编程技术网

C# WCF ServiceAuthenticationManager扩展性

C# WCF ServiceAuthenticationManager扩展性,c#,wcf,wcf-security,C#,Wcf,Wcf Security,我想将我的自定义安全性实现到wcf,我想使用ServiceAuthenticationManager,但我不知道它如何阻止消息。我试图引发异常,但那一次我无法获得异常详细信息,我在rest调用中只得到了“请求错误”和“服务未对调用方进行身份验证”在soap调用中,但我无法获取自定义错误消息,ServiceAuthenticationManager的正确用法是什么,或者我应该在哪里阻止消息 public class MyAuthenticationManager : ServiceAuthent

我想将我的自定义安全性实现到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);
    }
}
公共类MyAuthenticationManager:ServiceAuthenticationManager
{
公共覆盖ReadOnlyCollection身份验证(ReadOnlyCollection身份验证策略、Uri listenUri、ref消息)
{
//抛出新的AuthenticationException(“凭据已过期!”);
抛出新的SecurityException(“我的自定义消息:无效身份验证”);
返回base.Authenticate(authPolicy、listenUri、ref消息);
}
}

身份验证/授权不提供自定义消息。任何未授权或未经身份验证的指示都是攻击者破解您的安全性或获取其无权获取的信息的一种方式

例如,说“您的密码错误”表示用户名存在。这很糟糕。未经授权的请求不应获得响应等信息

如果要查看出现了什么问题,请写入服务器管理员可以访问的日志。但是不要向客户发送任何东西。永远


总而言之:不,您无法获取自定义消息,而且该设计是故意的。

您可能不应该向可疑客户提供有关其身份验证失败原因的详细信息。通常不需要自定义错误serviceauthenticationmanager的Rest返回消息与serviceauthenticationmanager不相同。因此,我想给出自定义错误消息,顺便问一下,serviceauthenticationmanager中的抛出异常是中断消息的正确方法吗?您的建议是什么?