WCF服务EntitySetRights.AllRead是否安全?

时间:2013-09-25 15:14:31

标签: security authentication devexpress odata wcf-security

我在MyDataService.svc.cs中有以下代码(这是DevExpress的一个例子):

namespace MyDataService {

    [System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]

    [JSONPSupportBehavior]
    public class DataService : DataService<TestDataEntities>, IServiceProvider {
        public static void InitializeService(DataServiceConfiguration config) {
            config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
        }

        public object GetService(Type serviceType) {
            if (serviceType == typeof(IDataServiceStreamProvider)) {
                return new ImageStreamProvider();
            }
            return null;
        }

        protected override void OnStartProcessingRequest(ProcessRequestArgs args) {
            CustomBasicAuth.Authenticate(HttpContext.Current);
            if (HttpContext.Current.User == null)
                throw new DataServiceException(401, "Invalid login or password");
            base.OnStartProcessingRequest(args);
        }
    }
}

因此,虽然这会检查实体的用户名和密码,但config.SetEntitySetAccessRule设置为AllRead的安全性如何。不会有人能够在网址上看到此信息,例如www.website.com/MyDataService.svc/Customer(其中Customer是表格)。如果不是这样,请有人填写我面临的概念差距。谢谢!

1 个答案:

答案 0 :(得分:1)

您在查询时将返回所有实体是正确的 - AllRead只是不允许插入更新和删除。

您需要使用Query Interceptor添加逻辑,以限制用户访问他们有权查看的数据集,例如向查询添加检查用户ID。