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
- CursorConverter.cs
- RtfControls.cs
- RemoteWebConfigurationHostStream.cs
- EventProviderTraceListener.cs
- EntityDataSourceDataSelectionPanel.cs
- isolationinterop.cs
- NavigationPropertyAccessor.cs
- CodeSubDirectory.cs
- ApplicationDirectoryMembershipCondition.cs
- MessageVersionConverter.cs
- WebConvert.cs
- ColumnHeader.cs
- CodeTypeDelegate.cs
- safex509handles.cs
- JsonEncodingStreamWrapper.cs
- CharAnimationUsingKeyFrames.cs
- WeakEventTable.cs
- ListViewInsertedEventArgs.cs
- DeadLetterQueue.cs
- VirtualPathProvider.cs
- DataGridBoolColumn.cs
- FontFamilyConverter.cs
- RelatedImageListAttribute.cs
- MappingMetadataHelper.cs
- ObjectListField.cs
- TimeIntervalCollection.cs
- PostBackOptions.cs
- UseLicense.cs
- ConversionContext.cs
- ChangeNode.cs
- UnsafeNativeMethods.cs
- SafeNativeMethodsCLR.cs
- ContentPlaceHolderDesigner.cs
- ThreadPoolTaskScheduler.cs
- ConnectionsZoneDesigner.cs
- XPathEmptyIterator.cs
- ItemsControl.cs
- ColorBlend.cs
- CompressStream.cs
- BuiltInPermissionSets.cs
- DataSourceProvider.cs
- TemplateAction.cs
- BindingsCollection.cs
- WorkItem.cs
- VisualBrush.cs
- CancellationHandler.cs
- AssemblyHash.cs
- PropertyOrder.cs
- HotCommands.cs
- ObjectFullSpanRewriter.cs
- HttpListenerResponse.cs
- TemplatePartAttribute.cs
- Source.cs
- CancelEventArgs.cs
- SQLInt16.cs
- StringCollectionEditor.cs
- ZoneLinkButton.cs
- DebugHandleTracker.cs
- DesignTimeParseData.cs
- Expressions.cs
- CompilerInfo.cs
- WebPermission.cs
- SecureEnvironment.cs
- GridView.cs
- ProtocolsConfiguration.cs
- EntityException.cs
- TypeUtil.cs
- TreeViewItemAutomationPeer.cs
- FormViewRow.cs
- linebase.cs
- InvalidDataContractException.cs
- MenuEventArgs.cs
- WebPartZoneBase.cs
- SQLUtility.cs
- StylusDevice.cs
- SplitterCancelEvent.cs
- CommandField.cs
- IconBitmapDecoder.cs
- ForeignKeyFactory.cs
- StorageTypeMapping.cs
- DbFunctionCommandTree.cs
- CancelEventArgs.cs
- XmlValidatingReaderImpl.cs
- CreateUserWizardStep.cs
- ModuleElement.cs
- InvokeBinder.cs
- ArrangedElement.cs
- UserInitiatedRoutedEventPermission.cs
- EmptyTextWriter.cs
- PenCursorManager.cs
- ExpressionPrefixAttribute.cs
- Accessible.cs
- TextParaClient.cs
- GeneralTransform2DTo3D.cs
- SocketElement.cs
- IdentifierCreationService.cs
- Control.cs
- DiscardableAttribute.cs
- Vector3D.cs
- Ppl.cs