Taylohtio/AlertManager/SPSolutions.SharePoint.Aler.../SPSolutions.SharePoint/SPSolutions.SharePoint.Secu.../SPRoles.cs

105 lines
2.1 KiB
C#

using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System;
using System.Collections.Generic;
using System.Web.Security;
namespace SPSolutions.SharePoint.Security
{
public class SPRoles
{
private SPContext m_context;
private SPWebApplication m_webApplication;
private SPUrlZone? m_urlZone;
private RoleProvider m_roleProvider;
public SPContext Context
{
get
{
if (this.m_context != null)
{
return this.m_context;
}
return SPContext.Current;
}
set
{
this.m_context = value;
}
}
public SPUrlZone Zone
{
get
{
if (this.m_urlZone.HasValue)
{
return this.m_urlZone.Value;
}
if (this.Context != null)
{
return this.Context.Site.Zone;
}
return 0;
}
set
{
this.m_urlZone = new SPUrlZone?(value);
}
}
public SPWebApplication WebApplication
{
get
{
if (this.m_webApplication == null && this.Context != null)
{
return this.Context.Site.WebApplication;
}
return this.m_webApplication;
}
set
{
this.m_webApplication = value;
}
}
public RoleProvider RoleProvider
{
get
{
if (this.m_roleProvider == null)
{
this.m_roleProvider = SPRoles.GetRoleProvider(this.WebApplication, this.Zone);
}
return this.m_roleProvider;
}
}
public string RoleProviderName
{
get
{
return SPRoles.GetRoleProviderName(this.WebApplication, this.Zone);
}
}
public static RoleProvider GetRoleProvider(SPWebApplication webApp, SPUrlZone zone)
{
return Roles.Providers[SPRoles.GetRoleProviderName(webApp, zone)];
}
public static string GetRoleProviderName(SPWebApplication webApp, SPUrlZone zone)
{
SPIisSettings iisSettingsWithFallback = webApp.GetIisSettingsWithFallback(zone);
return iisSettingsWithFallback.RoleManager;
}
public string[] GetUsersNotInRole(string[] users, string roleName)
{
List<string> list = new List<string>();
for (int i = 0; i < users.Length; i++)
{
string text = users[i];
if (!this.RoleProvider.IsUserInRole(text, roleName))
{
list.Add(text);
}
}
return list.ToArray();
}
}
}