You've already forked linux-packaging-mono
Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
parent
a569aebcfd
commit
e79aa3c0ed
@@ -0,0 +1,271 @@
|
||||
#region Using directives
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.DirectoryServices;
|
||||
using System.Security.Permissions;
|
||||
using System.Security.Principal;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
using System.Workflow.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace System.Workflow.Activities
|
||||
{
|
||||
[Serializable]
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public abstract class WorkflowRole
|
||||
{
|
||||
public abstract String Name { set; get; }
|
||||
|
||||
public abstract IList<String> GetIdentities();
|
||||
|
||||
public abstract bool IncludesIdentity(String identity);
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
sealed public class WorkflowRoleCollection : List<WorkflowRole>
|
||||
{
|
||||
public WorkflowRoleCollection()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public bool IncludesIdentity(String identity)
|
||||
{
|
||||
if (identity == null)
|
||||
return false;
|
||||
|
||||
foreach (WorkflowRole role in this)
|
||||
{
|
||||
if (role != null)
|
||||
{
|
||||
if (role.IncludesIdentity(identity))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
sealed public class ActiveDirectoryRole : WorkflowRole, ISerializable, IDisposable
|
||||
{
|
||||
private String m_name;
|
||||
private DirectoryEntry m_root;
|
||||
private List<IDirectoryOperation> m_operations;
|
||||
|
||||
internal ActiveDirectoryRole(DirectoryEntry rootEntry, IDirectoryOperation operation)
|
||||
{
|
||||
if (rootEntry == null)
|
||||
throw new ArgumentNullException("rootEntry");
|
||||
|
||||
this.m_root = rootEntry;
|
||||
|
||||
this.m_operations = new List<IDirectoryOperation>();
|
||||
if (operation != null)
|
||||
this.m_operations.Add(operation);
|
||||
}
|
||||
|
||||
internal ActiveDirectoryRole(DirectoryEntry rootEntry, ICollection<IDirectoryOperation> operations)
|
||||
{
|
||||
if (rootEntry == null)
|
||||
throw new ArgumentNullException("rootEntry");
|
||||
|
||||
this.m_root = rootEntry;
|
||||
|
||||
if (operations == null)
|
||||
this.m_operations = new List<IDirectoryOperation>();
|
||||
else
|
||||
this.m_operations = new List<IDirectoryOperation>(operations);
|
||||
}
|
||||
|
||||
private ActiveDirectoryRole(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
this.m_name = info.GetString("m_name");
|
||||
this.m_operations = (List<IDirectoryOperation>)info.GetValue("m_operations", typeof(List<IDirectoryOperation>));
|
||||
|
||||
String path = info.GetString("m_root\\path");
|
||||
|
||||
this.m_root = new DirectoryEntry(path);
|
||||
}
|
||||
|
||||
[SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
|
||||
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
info.AddValue("m_name", this.m_name);
|
||||
info.AddValue("m_operations", this.m_operations);
|
||||
|
||||
info.AddValue("m_root\\path", this.m_root.Path);
|
||||
}
|
||||
|
||||
public override String Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_name;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.m_name = value;
|
||||
}
|
||||
}
|
||||
|
||||
public DirectoryEntry RootEntry
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_root;
|
||||
}
|
||||
}
|
||||
|
||||
internal ICollection<IDirectoryOperation> Operations
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_operations;
|
||||
}
|
||||
}
|
||||
|
||||
public ActiveDirectoryRole GetManager()
|
||||
{
|
||||
List<IDirectoryOperation> queries = new List<IDirectoryOperation>(this.Operations);
|
||||
queries.Add(new DirectoryRedirect(ActiveDirectoryRoleFactory.Configuration.DistinguishedName, ActiveDirectoryRoleFactory.Configuration.DirectReports));
|
||||
|
||||
return new ActiveDirectoryRole(this.RootEntry, queries);
|
||||
}
|
||||
|
||||
public ActiveDirectoryRole GetManagerialChain()
|
||||
{
|
||||
List<IDirectoryOperation> queries = new List<IDirectoryOperation>(this.Operations);
|
||||
queries.Add(new DirectoryRedirect(ActiveDirectoryRoleFactory.Configuration.DistinguishedName, ActiveDirectoryRoleFactory.Configuration.DirectReports, true));
|
||||
|
||||
return new ActiveDirectoryRole(this.RootEntry, queries);
|
||||
}
|
||||
|
||||
public ActiveDirectoryRole GetDirectReports()
|
||||
{
|
||||
List<IDirectoryOperation> queries = new List<IDirectoryOperation>(this.Operations);
|
||||
queries.Add(new DirectoryRedirect(ActiveDirectoryRoleFactory.Configuration.DistinguishedName, ActiveDirectoryRoleFactory.Configuration.Manager));
|
||||
|
||||
return new ActiveDirectoryRole(this.RootEntry, queries);
|
||||
}
|
||||
|
||||
public ActiveDirectoryRole GetAllReports()
|
||||
{
|
||||
List<IDirectoryOperation> queries = new List<IDirectoryOperation>(this.Operations);
|
||||
queries.Add(new DirectoryRedirect(ActiveDirectoryRoleFactory.Configuration.DistinguishedName, ActiveDirectoryRoleFactory.Configuration.Manager, true));
|
||||
|
||||
return new ActiveDirectoryRole(this.RootEntry, queries);
|
||||
}
|
||||
|
||||
public ActiveDirectoryRole GetPeers()
|
||||
{
|
||||
ICollection<DirectoryEntry> entries = this.GetEntries();
|
||||
|
||||
List<IDirectoryOperation> queries = new List<IDirectoryOperation>(this.Operations);
|
||||
queries.Add(new DirectoryRedirect(ActiveDirectoryRoleFactory.Configuration.DistinguishedName, ActiveDirectoryRoleFactory.Configuration.DirectReports));
|
||||
queries.Add(new DirectoryRedirect(ActiveDirectoryRoleFactory.Configuration.DistinguishedName, ActiveDirectoryRoleFactory.Configuration.Manager));
|
||||
|
||||
foreach (DirectoryEntry entry in entries)
|
||||
{
|
||||
queries.Add(new DirectoryLocalQuery(ActiveDirectoryRoleFactory.Configuration.DistinguishedName, (String)entry.Properties[ActiveDirectoryRoleFactory.Configuration.DistinguishedName][0], DirectoryQueryOperation.NotEqual));
|
||||
}
|
||||
|
||||
return new ActiveDirectoryRole(this.RootEntry, queries);
|
||||
}
|
||||
|
||||
|
||||
public ICollection<DirectoryEntry> GetEntries()
|
||||
{
|
||||
List<DirectoryEntry> currentEntries = new List<DirectoryEntry>();
|
||||
currentEntries.Add(this.m_root);
|
||||
List<DirectoryEntry> newEntries = new List<DirectoryEntry>();
|
||||
|
||||
for (int i = 0; i < this.m_operations.Count; ++i)
|
||||
{
|
||||
for (int j = 0; j < currentEntries.Count; ++j)
|
||||
{
|
||||
this.m_operations[i].GetResult(this.m_root, currentEntries[j], newEntries);
|
||||
}
|
||||
|
||||
// Swap between new and current, as the for the new iteration the 'new' of
|
||||
// now will be the current. After the swap we clear out the 'new' list as to
|
||||
// reuse it.
|
||||
|
||||
List<DirectoryEntry> tempEntries = currentEntries;
|
||||
currentEntries = newEntries;
|
||||
newEntries = tempEntries;
|
||||
newEntries.Clear();
|
||||
}
|
||||
|
||||
// Remove duplicates
|
||||
|
||||
Dictionary<Guid, DirectoryEntry> dFinal = new Dictionary<Guid, DirectoryEntry>();
|
||||
for (int i = 0; i < currentEntries.Count; ++i)
|
||||
{
|
||||
if (!dFinal.ContainsKey(currentEntries[i].Guid))
|
||||
dFinal.Add(currentEntries[i].Guid, currentEntries[i]);
|
||||
}
|
||||
|
||||
return dFinal.Values;
|
||||
}
|
||||
|
||||
public IList<SecurityIdentifier> GetSecurityIdentifiers()
|
||||
{
|
||||
List<SecurityIdentifier> identifiers = new List<SecurityIdentifier>();
|
||||
|
||||
foreach (DirectoryEntry entry in this.GetEntries())
|
||||
{
|
||||
if (entry.Properties["objectSid"] != null &&
|
||||
entry.Properties["objectSid"].Count != 0)
|
||||
{
|
||||
identifiers.Add(new SecurityIdentifier((byte[])(entry.Properties["objectSid"][0]), 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Information, 0, "Unable to find 'objectSid' property for directory entry = {0}.", entry.Path);
|
||||
}
|
||||
}
|
||||
|
||||
return identifiers;
|
||||
}
|
||||
|
||||
public override IList<String> GetIdentities()
|
||||
{
|
||||
List<String> identityRefs = new List<String>();
|
||||
foreach (SecurityIdentifier entrySid in this.GetSecurityIdentifiers())
|
||||
{
|
||||
identityRefs.Add(entrySid.Translate(typeof(NTAccount)).ToString());
|
||||
}
|
||||
return identityRefs;
|
||||
}
|
||||
|
||||
public override bool IncludesIdentity(String identity)
|
||||
{
|
||||
if (identity == null)
|
||||
return false;
|
||||
|
||||
foreach (String roleIdentity in this.GetIdentities())
|
||||
{
|
||||
if (String.Compare(identity, roleIdentity, StringComparison.Ordinal) == 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
this.m_root.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
#region Using directives
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.DirectoryServices;
|
||||
using System.Security.Principal;
|
||||
using System.Configuration;
|
||||
using System.Workflow.Runtime.Configuration;
|
||||
using System.Workflow.Activities.Configuration;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace System.Workflow.Activities
|
||||
{
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public static class ActiveDirectoryRoleFactory
|
||||
{
|
||||
private static DirectoryGroupQuery s_directoryGroupQuery = new DirectoryGroupQuery();
|
||||
private static String s_configurationSectionName = "System.Workflow.Runtime.Hosting.ADRoleFactory";
|
||||
private static ActiveDirectoryRoleFactoryConfiguration s_configuration;
|
||||
private static DirectoryEntry s_rootEntry;
|
||||
|
||||
static ActiveDirectoryRoleFactory()
|
||||
{
|
||||
s_configuration = (ActiveDirectoryRoleFactoryConfiguration)ConfigurationManager.GetSection(s_configurationSectionName);
|
||||
if (s_configuration == null)
|
||||
s_configuration = new ActiveDirectoryRoleFactoryConfiguration();
|
||||
}
|
||||
|
||||
|
||||
public static ActiveDirectoryRole CreateFromAlias(String alias)
|
||||
{
|
||||
if (alias == null)
|
||||
throw new ArgumentNullException("alias");
|
||||
|
||||
ActiveDirectoryRole role = new ActiveDirectoryRole(GetRootEntry(), new DirectoryRootQuery("sAMAccountName", alias, DirectoryQueryOperation.Equal));
|
||||
role.Operations.Add(s_directoryGroupQuery);
|
||||
ValidateRole(role);
|
||||
return role;
|
||||
}
|
||||
|
||||
public static ActiveDirectoryRole CreateFromSecurityIdentifier(SecurityIdentifier sid)
|
||||
{
|
||||
if (sid == null)
|
||||
throw new ArgumentNullException("sid");
|
||||
|
||||
ActiveDirectoryRole role = new ActiveDirectoryRole(GetRootEntry(), new DirectoryRootQuery("objectSID", sid.ToString(), DirectoryQueryOperation.Equal));
|
||||
role.Operations.Add(s_directoryGroupQuery);
|
||||
ValidateRole(role);
|
||||
return role;
|
||||
}
|
||||
|
||||
public static ActiveDirectoryRole CreateFromEmailAddress(String emailAddress)
|
||||
{
|
||||
if (emailAddress == null)
|
||||
throw new ArgumentNullException("emailAddress");
|
||||
|
||||
ActiveDirectoryRole role = new ActiveDirectoryRole(GetRootEntry(), new DirectoryRootQuery("mail", emailAddress, DirectoryQueryOperation.Equal));
|
||||
role.Operations.Add(s_directoryGroupQuery);
|
||||
ValidateRole(role);
|
||||
return role;
|
||||
}
|
||||
|
||||
private static DirectoryEntry GetRootEntry()
|
||||
{
|
||||
if (s_rootEntry == null)
|
||||
{
|
||||
if (s_configuration == null ||
|
||||
s_configuration.RootPath == null ||
|
||||
s_configuration.RootPath.Length == 0)
|
||||
{
|
||||
s_rootEntry = new DirectoryEntry();
|
||||
}
|
||||
else
|
||||
{
|
||||
s_rootEntry = new DirectoryEntry(s_configuration.RootPath);
|
||||
}
|
||||
}
|
||||
|
||||
return s_rootEntry;
|
||||
}
|
||||
|
||||
public static ActiveDirectoryRoleFactoryConfiguration Configuration
|
||||
{
|
||||
get
|
||||
{
|
||||
return s_configuration;
|
||||
}
|
||||
}
|
||||
|
||||
private static void ValidateRole(ActiveDirectoryRole adRole)
|
||||
{
|
||||
if (adRole.GetEntries().Count == 0)
|
||||
throw new ArgumentException(SR.GetString(SR.Error_NoMatchingActiveDirectoryEntry));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
#region Using directives
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.DirectoryServices;
|
||||
using System.Configuration;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace System.Workflow.Activities.Configuration
|
||||
{
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
sealed public class ActiveDirectoryRoleFactoryConfiguration : ConfigurationSection
|
||||
{
|
||||
private const String _RootPath = "RootPath";
|
||||
private const String _Manager = "Manager";
|
||||
private const String _DistinguishedName = "DistiguishedName";
|
||||
private const String _DirectReports = "DirectReports";
|
||||
private const String _Group = "Group";
|
||||
private const String _Member = "Member";
|
||||
|
||||
[ConfigurationProperty(_RootPath, DefaultValue = "")]
|
||||
public string RootPath
|
||||
{
|
||||
get { return (string)base[_RootPath]; }
|
||||
set { base[_RootPath] = value; }
|
||||
}
|
||||
|
||||
[ConfigurationProperty(_Manager, DefaultValue = "manager")]
|
||||
public String Manager
|
||||
{
|
||||
get { return (string)base[_Manager]; }
|
||||
set { base[_Manager] = value; }
|
||||
}
|
||||
|
||||
[ConfigurationProperty(_DistinguishedName, DefaultValue = "distinguishedName")]
|
||||
public String DistinguishedName
|
||||
{
|
||||
get { return (string)base[_DistinguishedName]; }
|
||||
set { base[_DistinguishedName] = value; }
|
||||
}
|
||||
|
||||
[ConfigurationProperty(_DirectReports, DefaultValue = "directReports")]
|
||||
public String DirectReports
|
||||
{
|
||||
get { return (string)base[_DirectReports]; }
|
||||
set { base[_DirectReports] = value; }
|
||||
}
|
||||
|
||||
[ConfigurationProperty(_Group, DefaultValue = "group")]
|
||||
public String Group
|
||||
{
|
||||
get { return (string)base[_Group]; }
|
||||
set { base[_Group] = value; }
|
||||
}
|
||||
|
||||
[ConfigurationProperty(_Member, DefaultValue = "member")]
|
||||
public String Member
|
||||
{
|
||||
get { return (string)base[_Member]; }
|
||||
set { base[_Member] = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
#region Using directives
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Net;
|
||||
using System.DirectoryServices;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace System.Workflow.Activities
|
||||
{
|
||||
[Serializable]
|
||||
sealed internal class DirectoryGroupQuery : IDirectoryOperation
|
||||
{
|
||||
public DirectoryGroupQuery()
|
||||
{
|
||||
}
|
||||
|
||||
public void GetResult(DirectoryEntry rootEntry, DirectoryEntry currentEntry, List<DirectoryEntry> response)
|
||||
{
|
||||
if (response == null)
|
||||
throw new ArgumentNullException("response");
|
||||
|
||||
Stack<DirectoryEntry> entries = new Stack<DirectoryEntry>();
|
||||
entries.Push(currentEntry);
|
||||
|
||||
while (entries.Count != 0)
|
||||
{
|
||||
DirectoryEntry entry = entries.Pop();
|
||||
|
||||
bool isGroup = false;
|
||||
if (Contains(entry.Properties.PropertyNames, "objectClass"))
|
||||
{
|
||||
foreach (String value in entry.Properties["objectClass"])
|
||||
{
|
||||
if (String.Compare(value, ActiveDirectoryRoleFactory.Configuration.Group, StringComparison.Ordinal) == 0)
|
||||
{
|
||||
isGroup = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isGroup)
|
||||
{
|
||||
if (Contains(entry.Properties.PropertyNames, ActiveDirectoryRoleFactory.Configuration.Member))
|
||||
{
|
||||
foreach (String propValue in entry.Properties[ActiveDirectoryRoleFactory.Configuration.Member])
|
||||
{
|
||||
entries.Push(new DirectoryEntry(BuildUri(propValue)));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response.Add(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool Contains(ICollection propertyNames, String testPropertyName)
|
||||
{
|
||||
foreach (String propertyName in propertyNames)
|
||||
{
|
||||
if (String.Compare(propertyName, testPropertyName, StringComparison.Ordinal) == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static String BuildUri(String propValue)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("LDAP://");
|
||||
for (int i = 0; i < propValue.Length; ++i)
|
||||
{
|
||||
if (propValue[i] == '/')
|
||||
sb.Append("\\/");
|
||||
else
|
||||
sb.Append(propValue[i]);
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
#region Using directives
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.DirectoryServices;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace System.Workflow.Activities
|
||||
{
|
||||
[Serializable]
|
||||
sealed internal class DirectoryLocalQuery : IDirectoryOperation
|
||||
{
|
||||
internal String m_name;
|
||||
internal String m_value;
|
||||
internal DirectoryQueryOperation m_operation;
|
||||
|
||||
public DirectoryLocalQuery(String name, String value, DirectoryQueryOperation operation)
|
||||
{
|
||||
if (name == null)
|
||||
throw new ArgumentNullException("name");
|
||||
if (value == null)
|
||||
throw new ArgumentNullException("value");
|
||||
|
||||
this.m_name = name;
|
||||
this.m_value = value;
|
||||
this.m_operation = operation;
|
||||
}
|
||||
|
||||
public void GetResult(DirectoryEntry rootEntry, DirectoryEntry currentEntry, List<DirectoryEntry> response)
|
||||
{
|
||||
if (rootEntry == null)
|
||||
throw new ArgumentNullException("rootEntry");
|
||||
if (currentEntry == null)
|
||||
throw new ArgumentNullException("currentEntry");
|
||||
if (response == null)
|
||||
throw new ArgumentNullException("response");
|
||||
|
||||
using (DirectorySearcher searcher = new DirectorySearcher(currentEntry))
|
||||
{
|
||||
String strStart = "(";
|
||||
String strOperation = "";
|
||||
String strEnd = ")";
|
||||
|
||||
switch (this.m_operation)
|
||||
{
|
||||
case DirectoryQueryOperation.Equal:
|
||||
strOperation = "=";
|
||||
break;
|
||||
|
||||
case DirectoryQueryOperation.NotEqual:
|
||||
strStart = "(!(";
|
||||
strOperation = "=";
|
||||
strEnd = "))";
|
||||
break;
|
||||
|
||||
default:
|
||||
System.Diagnostics.Debug.Assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
searcher.Filter = strStart + this.m_name + strOperation + this.m_value + strEnd;
|
||||
|
||||
foreach (SearchResult result in searcher.FindAll())
|
||||
{
|
||||
response.Add(result.GetDirectoryEntry());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#region Using directives
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace System.Workflow.Activities
|
||||
{
|
||||
internal enum DirectoryQueryOperation
|
||||
{
|
||||
Equal,
|
||||
NotEqual,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
#region Using directives
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.DirectoryServices;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace System.Workflow.Activities
|
||||
{
|
||||
[Serializable]
|
||||
sealed internal class DirectoryRedirect : IDirectoryOperation
|
||||
{
|
||||
private String m_getPropertyName;
|
||||
private String m_searchPropertyName;
|
||||
private bool m_recursive;
|
||||
|
||||
public DirectoryRedirect(String getPropertyName, String searchPropertyName)
|
||||
: this(getPropertyName, searchPropertyName, false)
|
||||
{
|
||||
}
|
||||
|
||||
public DirectoryRedirect(String getPropertyName, String searchPropertyName, bool recursive)
|
||||
{
|
||||
if (getPropertyName == null)
|
||||
throw new ArgumentNullException("getPropertyName");
|
||||
if (searchPropertyName == null)
|
||||
throw new ArgumentNullException("searchPropertyName");
|
||||
|
||||
this.m_getPropertyName = getPropertyName;
|
||||
this.m_searchPropertyName = searchPropertyName;
|
||||
this.m_recursive = recursive;
|
||||
}
|
||||
|
||||
public void GetResult(DirectoryEntry rootEntry, DirectoryEntry currentEntry, List<DirectoryEntry> response)
|
||||
{
|
||||
if (rootEntry == null)
|
||||
throw new ArgumentNullException("rootEntry");
|
||||
if (currentEntry == null)
|
||||
throw new ArgumentNullException("currentEntry");
|
||||
if (response == null)
|
||||
throw new ArgumentNullException("response");
|
||||
|
||||
if (!this.m_recursive)
|
||||
{
|
||||
using (DirectorySearcher searcher = CreateSearcher(rootEntry, currentEntry))
|
||||
{
|
||||
foreach (SearchResult result in searcher.FindAll())
|
||||
{
|
||||
response.Add(result.GetDirectoryEntry());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Dictionary<Guid, DirectoryEntry> dResponse = new Dictionary<Guid, DirectoryEntry>();
|
||||
Stack<DirectoryEntry> stack = new Stack<DirectoryEntry>();
|
||||
stack.Push(currentEntry);
|
||||
|
||||
while (stack.Count != 0)
|
||||
{
|
||||
DirectoryEntry currentTop = stack.Pop();
|
||||
using (DirectorySearcher searcher = CreateSearcher(rootEntry, currentTop))
|
||||
{
|
||||
foreach (SearchResult result in searcher.FindAll())
|
||||
{
|
||||
DirectoryEntry newEntry = result.GetDirectoryEntry();
|
||||
if (!dResponse.ContainsKey(newEntry.Guid))
|
||||
dResponse.Add(newEntry.Guid, newEntry);
|
||||
stack.Push(newEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
response.AddRange(dResponse.Values);
|
||||
}
|
||||
}
|
||||
|
||||
private DirectorySearcher CreateSearcher(DirectoryEntry rootEntry, DirectoryEntry currentEntry)
|
||||
{
|
||||
DirectorySearcher searcher = new DirectorySearcher(rootEntry);
|
||||
|
||||
PropertyValueCollection values = currentEntry.Properties[this.m_getPropertyName];
|
||||
System.Diagnostics.Debug.Assert(values.Count == 1);
|
||||
|
||||
searcher.Filter = "(" + this.m_searchPropertyName + "=" + values[0] + ")";
|
||||
|
||||
return searcher;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
#region Using directives
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.DirectoryServices;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace System.Workflow.Activities
|
||||
{
|
||||
[Serializable]
|
||||
sealed internal class DirectoryRootQuery : IDirectoryOperation
|
||||
{
|
||||
private String m_name;
|
||||
private String m_value;
|
||||
private DirectoryQueryOperation m_operation;
|
||||
|
||||
public DirectoryRootQuery(String name, String value, DirectoryQueryOperation operation)
|
||||
{
|
||||
if (name == null)
|
||||
throw new ArgumentNullException("name");
|
||||
if (value == null)
|
||||
throw new ArgumentNullException("value");
|
||||
|
||||
this.m_name = name;
|
||||
this.m_value = value;
|
||||
this.m_operation = operation;
|
||||
}
|
||||
|
||||
public void GetResult(DirectoryEntry rootEntry, DirectoryEntry currentEntry, List<DirectoryEntry> response)
|
||||
{
|
||||
if (rootEntry == null)
|
||||
throw new ArgumentNullException("rootEntry");
|
||||
if (currentEntry == null)
|
||||
throw new ArgumentNullException("currentEntry");
|
||||
if (response == null)
|
||||
throw new ArgumentNullException("response");
|
||||
|
||||
using (DirectorySearcher searcher = new DirectorySearcher(rootEntry))
|
||||
{
|
||||
String strStart = "(";
|
||||
String strOperation = "";
|
||||
String strEnd = ")";
|
||||
|
||||
switch (this.m_operation)
|
||||
{
|
||||
case DirectoryQueryOperation.Equal:
|
||||
strOperation = "=";
|
||||
break;
|
||||
|
||||
case DirectoryQueryOperation.NotEqual:
|
||||
strStart = "(!(";
|
||||
strOperation = "=";
|
||||
strEnd = "))";
|
||||
break;
|
||||
|
||||
default:
|
||||
System.Diagnostics.Debug.Assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
searcher.Filter = strStart + this.m_name + strOperation + this.m_value + strEnd;
|
||||
|
||||
foreach (SearchResult result in searcher.FindAll())
|
||||
{
|
||||
response.Add(result.GetDirectoryEntry());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#region Using directives
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.DirectoryServices;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace System.Workflow.Activities
|
||||
{
|
||||
internal interface IDirectoryOperation
|
||||
{
|
||||
void GetResult(DirectoryEntry rootEntry, DirectoryEntry currentEntry, List<DirectoryEntry> response);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Security.Permissions;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Workflow;
|
||||
using System.Workflow.Runtime;
|
||||
using System.Workflow.ComponentModel;
|
||||
|
||||
namespace System.Workflow.Activities
|
||||
{
|
||||
[Serializable]
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public class WorkflowAuthorizationException : SystemException
|
||||
{
|
||||
public WorkflowAuthorizationException()
|
||||
: base() { }
|
||||
public WorkflowAuthorizationException(String activityName, String principalName)
|
||||
: base(SR.GetString(SR.WorkflowAuthorizationException, activityName, principalName))
|
||||
{
|
||||
}
|
||||
public WorkflowAuthorizationException(string message) : base(message) { }
|
||||
|
||||
public WorkflowAuthorizationException(string message, Exception innerException) : base(message, innerException) { }
|
||||
|
||||
[SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
|
||||
protected WorkflowAuthorizationException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Workflow.Runtime;
|
||||
using System.Workflow.Runtime.Hosting;
|
||||
|
||||
using System.Web.Security;
|
||||
using System.Security.Principal;
|
||||
using System.Configuration.Provider;
|
||||
|
||||
namespace System.Workflow.Activities
|
||||
{
|
||||
[Serializable]
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public class WebWorkflowRole : WorkflowRole
|
||||
{
|
||||
private string m_roleName;
|
||||
private string m_roleProvider;
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_roleName;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
throw new ArgumentNullException("value");
|
||||
this.m_roleName = value;
|
||||
}
|
||||
}
|
||||
public string RoleProvider
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_roleProvider;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.m_roleProvider = value;
|
||||
}
|
||||
}
|
||||
|
||||
public WebWorkflowRole(string roleName)
|
||||
{
|
||||
if (null == roleName)
|
||||
{
|
||||
throw new ArgumentNullException("roleName");
|
||||
}
|
||||
|
||||
this.m_roleName = roleName;
|
||||
this.m_roleProvider = null;
|
||||
}
|
||||
public WebWorkflowRole(string roleName, string provider)
|
||||
{
|
||||
if (null == roleName)
|
||||
{
|
||||
throw new ArgumentNullException("roleName");
|
||||
}
|
||||
|
||||
this.m_roleName = roleName;
|
||||
this.m_roleProvider = provider;
|
||||
}
|
||||
|
||||
public override IList<string> GetIdentities()
|
||||
{
|
||||
List<string> identities = new List<string>();
|
||||
System.Web.Security.RoleProvider rp = GetRoleProvider();
|
||||
|
||||
identities.AddRange(rp.GetUsersInRole(Name));
|
||||
|
||||
return identities;
|
||||
}
|
||||
|
||||
public override bool IncludesIdentity(string identity)
|
||||
{
|
||||
System.Web.Security.RoleProvider rp = GetRoleProvider();
|
||||
|
||||
return rp.IsUserInRole(identity, Name);
|
||||
}
|
||||
|
||||
private System.Web.Security.RoleProvider GetRoleProvider()
|
||||
{
|
||||
if (this.RoleProvider == null)
|
||||
return System.Web.Security.Roles.Provider;
|
||||
|
||||
RoleProvider rp = Roles.Providers[this.RoleProvider];
|
||||
if (rp == null)
|
||||
throw new ProviderException(SR.GetString(SR.Error_RoleProviderNotAvailableOrEnabled, this.RoleProvider));
|
||||
return rp;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user