0
在我的WCF web服務的web.config我已經下serviceBehaviors如下:在WCF服務與UseAspNetRoles主要權限模式擴展的IPrincipal
<serviceAuthorization principalPermissionMode="UseAspNetRoles" roleProviderName="RoleProvider" />
這讓我使用asp.net角色提供和控制訪問Web服務具有以下屬性要求:
[PrincipalPermission(SecurityAction.Demand, Role = "Admin")]
我想知道我怎麼可以用上面的,並且也將自定義的主要定義如下。
public class UserPrincipal : IPrincipal
{
List<string> roleList = null;
public const string ROLE_ADMIN = "Admin";
public const string ROLE_DATAENTRY = "DataEntry";
public const string ROLE_READONLY = "ReadOnly";
public UserPrincipal(IIdentity identity, string[] roles)
{
Identity = identity;
roleList = new List<string>(roles);
}
public IIdentity Identity
{
get { return identity; }
}
public bool IsInRole(string role)
{
return roleList.Contains(role);
}
public bool CanEdit()
{
if (IsInRole(ROLE_ADMIN))
return true;
else if (IsInRole(ROLE_DATAENTRY))
return true;
else
return false;
}
public bool CanView()
{
if (IsInRole(ROLE_ADMIN))
return true;
else if (IsInRole(ROLE_DATAENTRY))
return true;
else if (IsInRole(ROLE_READONLY))
return true;
else
return false;
}
}
我想在服務方法中使用CanView和CanEdit調用。
在WCF服務中,我可以用我的擴展用戶主體替換默認主體?