Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / Activities / Role / ADRole.cs / 1305376 / ADRole.cs
#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] public abstract class WorkflowRole { public abstract String Name { set; get; } public abstract IListGetIdentities(); public abstract bool IncludesIdentity(String identity); } [Serializable] sealed public class WorkflowRoleCollection : List { 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] sealed public class ActiveDirectoryRole : WorkflowRole, ISerializable, IDisposable { private String m_name; private DirectoryEntry m_root; private List m_operations; internal ActiveDirectoryRole(DirectoryEntry rootEntry, IDirectoryOperation operation) { if (rootEntry == null) throw new ArgumentNullException("rootEntry"); this.m_root = rootEntry; this.m_operations = new List (); if (operation != null) this.m_operations.Add(operation); } internal ActiveDirectoryRole(DirectoryEntry rootEntry, ICollection operations) { if (rootEntry == null) throw new ArgumentNullException("rootEntry"); this.m_root = rootEntry; if (operations == null) this.m_operations = new List (); else this.m_operations = new List (operations); } private ActiveDirectoryRole(SerializationInfo info, StreamingContext context) { this.m_name = info.GetString("m_name"); this.m_operations = (List )info.GetValue("m_operations", typeof(List )); 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 Operations { get { return this.m_operations; } } public ActiveDirectoryRole GetManager() { List queries = new List (this.Operations); queries.Add(new DirectoryRedirect(ActiveDirectoryRoleFactory.Configuration.DistinguishedName, ActiveDirectoryRoleFactory.Configuration.DirectReports)); return new ActiveDirectoryRole(this.RootEntry, queries); } public ActiveDirectoryRole GetManagerialChain() { List queries = new List (this.Operations); queries.Add(new DirectoryRedirect(ActiveDirectoryRoleFactory.Configuration.DistinguishedName, ActiveDirectoryRoleFactory.Configuration.DirectReports, true)); return new ActiveDirectoryRole(this.RootEntry, queries); } public ActiveDirectoryRole GetDirectReports() { List queries = new List (this.Operations); queries.Add(new DirectoryRedirect(ActiveDirectoryRoleFactory.Configuration.DistinguishedName, ActiveDirectoryRoleFactory.Configuration.Manager)); return new ActiveDirectoryRole(this.RootEntry, queries); } public ActiveDirectoryRole GetAllReports() { List queries = new List (this.Operations); queries.Add(new DirectoryRedirect(ActiveDirectoryRoleFactory.Configuration.DistinguishedName, ActiveDirectoryRoleFactory.Configuration.Manager, true)); return new ActiveDirectoryRole(this.RootEntry, queries); } public ActiveDirectoryRole GetPeers() { ICollection entries = this.GetEntries(); List queries = new List (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 GetEntries() { List currentEntries = new List (); currentEntries.Add(this.m_root); List newEntries = new List (); 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 tempEntries = currentEntries; currentEntries = newEntries; newEntries = tempEntries; newEntries.Clear(); } // Remove duplicates Dictionary dFinal = new Dictionary (); 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 GetSecurityIdentifiers() { List identifiers = new List (); 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 GetIdentities() { List identityRefs = new List (); 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(); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. #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] public abstract class WorkflowRole { public abstract String Name { set; get; } public abstract IList GetIdentities(); public abstract bool IncludesIdentity(String identity); } [Serializable] sealed public class WorkflowRoleCollection : List { 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] sealed public class ActiveDirectoryRole : WorkflowRole, ISerializable, IDisposable { private String m_name; private DirectoryEntry m_root; private List m_operations; internal ActiveDirectoryRole(DirectoryEntry rootEntry, IDirectoryOperation operation) { if (rootEntry == null) throw new ArgumentNullException("rootEntry"); this.m_root = rootEntry; this.m_operations = new List (); if (operation != null) this.m_operations.Add(operation); } internal ActiveDirectoryRole(DirectoryEntry rootEntry, ICollection operations) { if (rootEntry == null) throw new ArgumentNullException("rootEntry"); this.m_root = rootEntry; if (operations == null) this.m_operations = new List (); else this.m_operations = new List (operations); } private ActiveDirectoryRole(SerializationInfo info, StreamingContext context) { this.m_name = info.GetString("m_name"); this.m_operations = (List )info.GetValue("m_operations", typeof(List )); 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 Operations { get { return this.m_operations; } } public ActiveDirectoryRole GetManager() { List queries = new List (this.Operations); queries.Add(new DirectoryRedirect(ActiveDirectoryRoleFactory.Configuration.DistinguishedName, ActiveDirectoryRoleFactory.Configuration.DirectReports)); return new ActiveDirectoryRole(this.RootEntry, queries); } public ActiveDirectoryRole GetManagerialChain() { List queries = new List (this.Operations); queries.Add(new DirectoryRedirect(ActiveDirectoryRoleFactory.Configuration.DistinguishedName, ActiveDirectoryRoleFactory.Configuration.DirectReports, true)); return new ActiveDirectoryRole(this.RootEntry, queries); } public ActiveDirectoryRole GetDirectReports() { List queries = new List (this.Operations); queries.Add(new DirectoryRedirect(ActiveDirectoryRoleFactory.Configuration.DistinguishedName, ActiveDirectoryRoleFactory.Configuration.Manager)); return new ActiveDirectoryRole(this.RootEntry, queries); } public ActiveDirectoryRole GetAllReports() { List queries = new List (this.Operations); queries.Add(new DirectoryRedirect(ActiveDirectoryRoleFactory.Configuration.DistinguishedName, ActiveDirectoryRoleFactory.Configuration.Manager, true)); return new ActiveDirectoryRole(this.RootEntry, queries); } public ActiveDirectoryRole GetPeers() { ICollection entries = this.GetEntries(); List queries = new List (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 GetEntries() { List currentEntries = new List (); currentEntries.Add(this.m_root); List newEntries = new List (); 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 tempEntries = currentEntries; currentEntries = newEntries; newEntries = tempEntries; newEntries.Clear(); } // Remove duplicates Dictionary dFinal = new Dictionary (); 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 GetSecurityIdentifiers() { List identifiers = new List (); 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 GetIdentities() { List identityRefs = new List (); 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(); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- MessagePropertyVariants.cs
- _PooledStream.cs
- ConfigXmlCDataSection.cs
- NameValueFileSectionHandler.cs
- Suspend.cs
- VirtualPathUtility.cs
- ObjectFactoryCodeDomTreeGenerator.cs
- FlowLayoutSettings.cs
- ObjectViewListener.cs
- XmlSerializerFactory.cs
- ViewStateModeByIdAttribute.cs
- StylusPlugin.cs
- MemberAccessException.cs
- Filter.cs
- XmlSchema.cs
- XsltLibrary.cs
- TouchPoint.cs
- CachedCompositeFamily.cs
- AttributeCollection.cs
- _DynamicWinsockMethods.cs
- ISFClipboardData.cs
- XmlSchemaCollection.cs
- Barrier.cs
- ListViewTableRow.cs
- ProxyFragment.cs
- SeekStoryboard.cs
- SchemaNames.cs
- StringUtil.cs
- Screen.cs
- SQLInt64.cs
- AspNetSynchronizationContext.cs
- TripleDESCryptoServiceProvider.cs
- SslStreamSecurityBindingElement.cs
- LoginView.cs
- ExpanderAutomationPeer.cs
- PowerModeChangedEventArgs.cs
- OracleDataReader.cs
- UnsafeNativeMethodsPenimc.cs
- MiniConstructorInfo.cs
- LexicalChunk.cs
- MiniAssembly.cs
- CookieHandler.cs
- DataGridRow.cs
- ObjectTypeMapping.cs
- DrawingVisualDrawingContext.cs
- SqlLiftIndependentRowExpressions.cs
- XsltOutput.cs
- DropDownButton.cs
- ValidatorCollection.cs
- StyleBamlTreeBuilder.cs
- TemplateBaseAction.cs
- PlanCompiler.cs
- ProfilePropertyNameValidator.cs
- XmlSecureResolver.cs
- DateTimeFormatInfoScanner.cs
- EmptyStringExpandableObjectConverter.cs
- TextSearch.cs
- ValueTypeFieldReference.cs
- FilterableAttribute.cs
- ToolBarPanel.cs
- BrowserCapabilitiesCompiler.cs
- TableLayoutPanelCellPosition.cs
- tooltip.cs
- HandlerWithFactory.cs
- TreePrinter.cs
- SafeEventLogWriteHandle.cs
- XmlDataSourceNodeDescriptor.cs
- ToolTip.cs
- XPathSelfQuery.cs
- TextBoxRenderer.cs
- ChannelDispatcherBase.cs
- UnsafeNativeMethods.cs
- ColorMatrix.cs
- SelectionWordBreaker.cs
- WasAdminWrapper.cs
- MexHttpBindingCollectionElement.cs
- CodeExporter.cs
- LowerCaseStringConverter.cs
- TraceXPathNavigator.cs
- ExtensionDataObject.cs
- TypeBuilderInstantiation.cs
- ClrPerspective.cs
- PackWebRequestFactory.cs
- DataGridViewRowConverter.cs
- XmlValidatingReader.cs
- SoapHeader.cs
- SmiRecordBuffer.cs
- MetadataArtifactLoader.cs
- _TransmitFileOverlappedAsyncResult.cs
- XsltConvert.cs
- RecommendedAsConfigurableAttribute.cs
- CFGGrammar.cs
- Parsers.cs
- RC2CryptoServiceProvider.cs
- FacetValues.cs
- BaseCollection.cs
- Ref.cs
- RegularExpressionValidator.cs
- InternalMappingException.cs
- Attributes.cs