remoting中怎么对客户端进行身份验证? 网上竟然找不到一篇详细的文章,都是一笔概过.
用TcpChannel通道,我的理解是:
让用户提交用户名和密码,如果正确,把用户信息绑定到当前线程:Thread.CurrentPrincipal.然后在每个远程对象的方法或属性开头都进行验证该用户是不是合法的(通过数据库或文件保存合法用户信息). 是不是这样?
那用CallContext绑定用户信息也可以吧?
标准做法是怎么样的?
用TcpChannel通道,我的理解是:
让用户提交用户名和密码,如果正确,把用户信息绑定到当前线程:Thread.CurrentPrincipal.然后在每个远程对象的方法或属性开头都进行验证该用户是不是合法的(通过数据库或文件保存合法用户信息). 是不是这样?
那用CallContext绑定用户信息也可以吧?
标准做法是怎么样的?
这个是可以的。
但要记住远程对象和一般的本地对象不一样。
通常远程访问可以用Facade模式来实现,这样只需要在Facade对象中验证就可以。
对本地的业务对象没有影响。
"在每个远程对象的方法或属性开头都进行验证" 是不是有点麻烦? 能不能把某个类限定给指定角色? 用什么特性.这里的Facade也是远程的吗? 本地是不是不安全?
namespace RemoteServer
{
public class Scoop : MarshalByRefObject
{
public Scoop()
{
} public string GetTheScoop(string name)
{
return "Here's the scoop, "
+ Thread.CurrentPrincipal.Identity.Name + "!";
}
}
}
配制文件:
<configuration>
<system.runtime.remoting>
<application>
<service>
<wellknown mode="SingleCall"
type="RemoteServer.Scoop,RemoteServer"
objectUri="Scoop.soap" />
</service>
</application>
</system.runtime.remoting>
<system.web>
<authentication mode="None" />
<authorization>
<deny users="?" />
</authorization>
</system.web></configuration>客户端:
static void Main(string[] args)
{
ChannelServices.RegisterChannel(new HttpClientChannel());
RemotingConfiguration.RegisterWellKnownClientType(
typeof(RemoteServer.Scoop),
"http://localhost/ScoopRemoting/Scoop.soap"); Scoop srv = new Scoop(); IDictionary props = ChannelServices.GetChannelSinkProperties(srv);
props["username"] = "test";
props["password"] = "test"; string s = srv.GetTheScoop("Greg");
Console.WriteLine(s);
}如果这样做的话,别人写个客户端不是可以随便模仿一下登录?
如果限制角色:
<authorization>
<allow role="aaaa" />
<deny users="*" />
</authorization>别人如果知道你的角色是什么, 也可以写个客户端模仿吧?
.NET Remoting Security Solution, Part 1:
.NET Remoting Security Solution, Part 2: