Example #1
0
 public UserService(IDirectoryContext directoryContext)
 {
     if (_directoryContext == null)
     {
         _directoryContext = directoryContext;
     }
 }
Example #2
0
        /// <summary>
        /// LDAPサーバへ接続する
        /// </summary>
        /// <param name="dn">接続先の一意名</param>
        /// <param name="password">パスワード</param>
        public void Connect(string dn = null, string password = null)
        {
            try
            {
                //一意名が未指定の場合、システム用一意名・パスワードを取得
                if (dn == null)
                {
                    dn       = LdapConfig.SystemDn;
                    password = LdapConfig.SystemPassword;
                }

                //設定情報の生成
                LdapConfiguration config = new LdapConfiguration();
                config
                .MaxPageSizeIs(10000)
                .AddMapping(new LdapUserMapper())
                .AddMapping(new LdapUserPasswordMapper())
                .ConfigureFactory(LdapConfig.Server)
                .AuthenticateBy(AuthType.Basic)
                .AuthenticateAs(new NetworkCredential(dn, password))
                .ProtocolVersion(3)
                .UsePort(LdapConfig.Port);

                //接続
                this.Context = new DirectoryContext(config);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #3
0
        /// <summary>
        /// LDAPサーバへ接続する
        /// </summary>
        /// <param name="dn">接続先の一意名</param>
        /// <param name="password">パスワード</param>
        public void Connect(string dn = null, string password = null)
        {
            try
            {
                //一意名が未指定の場合、システム用一意名・パスワードを取得
                if (dn == null)
                {
                    dn = LdapConfig.SystemDn;
                    password = LdapConfig.SystemPassword;
                }

                //設定情報の生成
                LdapConfiguration config = new LdapConfiguration();
                config
                    .MaxPageSizeIs(10000)
                    .AddMapping(new LdapUserMapper())
                    .AddMapping(new LdapUserPasswordMapper())
                    .ConfigureFactory(LdapConfig.Server)
                    .AuthenticateBy(AuthType.Basic)
                    .AuthenticateAs(new NetworkCredential(dn, password))
                    .ProtocolVersion(3)
                    .UsePort(LdapConfig.Port);

                //接続
                this.Context = new DirectoryContext(config);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public ServerInfoViewModel(IMessenger messenger, IDirectoryContext context)
        {
            _messenger = messenger;
            _context   = context;

            ServerSettings = new ObservableCollection <KeyValueViewModel>();
            PopulateData();
        }
        public ServerInfoViewModel(IMessenger messenger, IDirectoryContext context)
        {
            _messenger = messenger;
            _context = context;

            ServerSettings = new ObservableCollection<KeyValueViewModel>();
            PopulateData();
        }
        public override void Cleanup()
        {
            _messenger = null;
            _context.Dispose();
            _context = null;

            base.Cleanup();
        }
        public override void Cleanup()
        {
            _messenger = null;
            _context.Dispose();
            _context = null;

            base.Cleanup();
        }
        public UsersViewModel(IMessenger messenger, IDirectoryContext context)
        {
            _messenger = messenger;
            _context = context;

            Users = new ObservableCollection<UserListViewModel>();

            SearchCommand = new RelayCommand(() => { if (!_isBusy) LoadUsers(); });
            LoadUsers();
        }
        public override void Cleanup()
        {
            _messenger = null;
            _context.Dispose();
            _context = null;
            if (CurrentContent != null && CurrentContent != this)
            {
                CurrentContent.Cleanup();
            }

            base.Cleanup();
        }
        public UsersViewModel(IMessenger messenger, IDirectoryContext context)
        {
            _messenger = messenger;
            _context   = context;

            Users = new ObservableCollection <UserListViewModel>();

            SearchCommand = new RelayCommand(() => { if (!_isBusy)
                                                     {
                                                         LoadUsers();
                                                     }
                                             });
            LoadUsers();
        }
Example #11
0
        public void SetUp()
        {
            _configuration = new LdapConfiguration()
                             .AddMapping(new IntegrationUserTestMapping(), IntegrationUserTest.NamingContext, new[] { "user" })
                             .AddMapping(new AttributeClassMap <IntegrationGroupTest>(), IntegrationGroupTest.NamingContext, new[] { "top", "group" }, true, "group")
                             .AddMapping(new AttributeClassMap <PersonInheritanceTest>())
                             .AddMapping(new AttributeClassMap <OrgPersonInheritanceTest>())
                             .AddMapping(new AttributeClassMap <UserInheritanceTest>())
                             .AddMapping(new AttributeClassMap <PersonCatchAllTest>())
                             .AddMapping(new AttributeClassMap <OrgPersonCatchAllTest>())
                             .MaxPageSizeIs(1000)
                             .LogTo(new SimpleTextLogger(Console.Out));

            _configuration.ConfigureFactory(ServerName)
            //.AuthenticateBy(AuthType.Basic)
            //.AuthenticateAs(new NetworkCredential("CN=AlphaUser,CN=Users,CN=Employees,DC=Northwind,DC=local", "test"))
            .AuthenticateBy(AuthType.Negotiate)
            ;

            _context = _configuration.CreateContext();
        }
Example #12
0
 public ActiveDirectoryService(IDirectoryContext context)
 {
     db = context;
 }
Example #13
0
 public AdLdsUserAuthenticationService(IDirectoryContextFactory contextFactory, DirectoryConnectionConfig connectionConfig)
 {
     this.directoryContext = contextFactory.CreateDirectoryContext(connectionConfig);
 }
Example #14
0
        private static IDirectoryAttributes AddEntryIfNecessary(string dn, string objectClass, IDirectoryContext context)
        {
            IDirectoryAttributes entry = null;

            try
            {
                entry = context.GetByDN(dn);
            }
            catch (DirectoryOperationException ex)
            {
                if (ex.Message.IndexOf("object does not exist", StringComparison.OrdinalIgnoreCase) == -1)
                {
                    throw;
                }
            }

            if (entry == null)
            {
                entry = new DirectoryAttributes(dn);
                entry.Set("objectClass", objectClass);

                Console.WriteLine("Adding {0}", dn);
                return(context.AddAndGet(entry));
            }

            Console.WriteLine("{0} already exists", dn);
            return(entry);
        }
 /// <summary>
 /// Executes <see cref="DirectoryContext.DeleteAttribute"/> within a <see cref="Task"/>.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="distinguishedName">The entry</param>
 /// <param name="attributeName">The name of the attribute</param>
 /// <param name="controls">Any <see cref="DirectoryControl"/>s to be sent with the request</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="distinguishedName"/> or <paramref name="attributeName"/> is null, empty or white space.</exception>
 /// <exception cref="DirectoryOperationException">Thrown if the operation fails.</exception>
 /// <exception cref="LdapConnection">Thrown if the operation fails.</exception>
 public static Task DeleteAttributeAsync(this IDirectoryContext context, string distinguishedName, string attributeName,
                                         params DirectoryControl[] controls)
 {
     return(Task.Factory.StartNew(() => context.DeleteAttribute(distinguishedName, attributeName, controls)));
 }
 public AdLdsUserAuthenticationService(IDirectoryContextFactory contextFactory, DirectoryConnectionConfig connectionConfig)
 {
     this.directoryContext = contextFactory.CreateDirectoryContext(connectionConfig);
 }
Example #17
0
 public AdLdsUserManagementService(IDirectoryContextFactory contextFactory, DirectoryConnectionConfig connectionConfig)
 {
     this.directoryContext = contextFactory.CreateDirectoryContext(connectionConfig);
 }
 /// <summary>
 /// Executes <see cref="DirectoryContext.GetByDN"/> within a <see cref="Task"/>.
 /// </summary>
 /// <param name="context">The <see cref="DirectoryContext"/>.</param>
 /// <param name="distinguishedName">The distinguished name to look for.</param>
 /// <param name="attributes">The attributes to load.</param>
 /// <returns></returns>
 public static Task <IDirectoryAttributes> GetByDNAsync(this IDirectoryContext context, string distinguishedName, params string[] attributes)
 {
     return(Task.Factory.StartNew(() => context.GetByDN(distinguishedName, attributes)));
 }
 /// <summary>
 /// Executes <see cref="DirectoryContext.UpdateAndGet(DirectoryAttributes)"/> within a <see cref="Task"/>.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="entry">The attributes for the entry.</param>
 /// <returns></returns>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="entry"/> is null.
 /// </exception>
 /// <exception cref="DirectoryOperationException">Thrown if the operation fails</exception>
 /// <exception cref="LdapException">Thrown if the operation fails</exception>
 public static Task <IDirectoryAttributes> UpdateAndGetAsync(this IDirectoryContext context, DirectoryAttributes entry)
 {
     return(Task.Factory.StartNew(() => context.UpdateAndGet(entry)));
 }
 /// <summary>
 /// Executes <see cref="DirectoryContext.Add(DirectoryAttributes)"/>
 /// </summary>
 /// <param name="context">The <see cref="DirectoryContext"/>.</param>
 /// <param name="entry">The attributes for the entry</param>
 public static Task AddAsync(this IDirectoryContext context, DirectoryAttributes entry)
 {
     return(Task.Factory.StartNew(() => context.Add(entry)));
 }
 public DirectoryAPIController(IDirectoryContext context)
 {
     _context = context;
 }
 /// <summary>
 /// Executes <see cref="DirectoryContext.Add{T}(T,string,DirectoryControl[])"/>
 /// </summary>
 /// <typeparam name="T">The type of entry.</typeparam>
 /// <param name="context">The <see cref="DirectoryContext"/>.</param>
 /// <param name="entry">The object to save.</param>
 /// <param name="distinguishedName">The distinguished name for the entry.</param>
 /// <param name="controls">Any <see cref="DirectoryControl"/>s to be sent with the request</param>
 public static Task AddAsync <T>(this IDirectoryContext context, T entry, string distinguishedName = null,
                                 DirectoryControl[] controls = null) where T : class
 {
     return(Task.Factory.StartNew(() => context.Add(entry, distinguishedName, controls)));
 }
 /// <summary>
 /// Executes <see cref="DirectoryContext.RetrieveRanges{TValue}"/> within a <see cref="Task"/>.
 /// </summary>
 /// <typeparam name="TValue">The type of the attribute.  Must be <see cref="string"/> or <see cref="Array"/> of <see cref="byte"/>.</typeparam>
 /// <param name="context">The context.</param>
 /// <param name="distinguishedName">The distinguished name of the entry.</param>
 /// <param name="attributeName">The attribute to load.</param>
 /// <param name="start">The starting point for the range. Defaults to 0.</param>
 /// <exception cref="ArgumentNullException">
 /// Thrown if <paramref name="distinguishedName"/> or <paramref name="attributeName"/> is null, empty or white space.
 /// </exception>
 /// <returns></returns>
 public static Task <IList <TValue> > RetrieveRangesAsync <TValue>(this IDirectoryContext context, string distinguishedName,
                                                                   string attributeName, int start = 0)
 {
     return(Task.Factory.StartNew(() => context.RetrieveRanges <TValue>(distinguishedName, attributeName, start)));
 }
 /// <summary>
 /// Executes <see cref="DirectoryContext.RenameEntry"/> within a <see cref="Task"/>.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="currentDistinguishedName">The entry's current distinguished name</param>
 /// <param name="newName">The new name of the entry</param>
 /// <param name="deleteOldRDN">Maps to <see cref="P:System.DirectoryServices.Protocols.ModifyDNRequest.DeleteOldRdn"/>. Defaults to null to use default behavior from <see cref="P:System.DirectoryServices.Protocols.ModifyDNRequest.DeleteOldRdn"/>.</param>
 /// <param name="controls">Any <see cref="DirectoryControl"/>s to be sent with the request</param>
 /// <exception cref="ArgumentException">
 /// Thrown if <paramref name="currentDistinguishedName"/> has an invalid format.
 /// </exception>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="currentDistinguishedName"/>
 /// or <paramref name="newName"/> are null, empty or white space.
 /// </exception>
 /// <exception cref="DirectoryOperationException">Thrown if the operation fails.</exception>
 /// <exception cref="LdapConnection">Thrown if the operation fails.</exception>
 public static Task <string> RenameEntryAsync(this IDirectoryContext context, string currentDistinguishedName, string newName,
                                              bool?deleteOldRDN = null, params DirectoryControl[] controls)
 {
     return(Task.Factory.StartNew(() => context.RenameEntry(currentDistinguishedName, newName, deleteOldRDN, controls)));
 }
        public override void Cleanup()
        {
            _messenger = null;
            _context.Dispose();
            _context = null;
            if (CurrentContent != null && CurrentContent != this) CurrentContent.Cleanup();

            base.Cleanup();
        }
 public UsersController(IDirectoryContext context)
 {
     _context = context;
 }
 /// <summary>
 /// Executes <see cref="DirectoryContext.Update(IDirectoryAttributes,DirectoryControl[])"/> within a <see cref="Task"/>.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="entry">The attributes for the entry.</param>
 /// <param name="controls">Any <see cref="DirectoryControl"/>s to be sent with the request</param>
 /// <returns></returns>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="entry"/> is null.
 /// </exception>
 /// <exception cref="DirectoryOperationException">Thrown if the operation fails</exception>
 /// <exception cref="LdapException">Thrown if the operation fails</exception>
 public static Task UpdateAsync(this IDirectoryContext context, IDirectoryAttributes entry,
                                DirectoryControl[] controls)
 {
     return(Task.Factory.StartNew(() => context.Update(entry, controls)));
 }
 /// <summary>
 /// Executes <see cref="DirectoryContext.AddAndGet(DirectoryAttributes,DirectoryControl[])"/>
 /// </summary>
 /// <param name="context">The <see cref="DirectoryContext"/>.</param>
 /// <param name="entry">The attributes for the entry</param>
 /// <param name="controls">Any <see cref="DirectoryControl"/>s to be sent with the request</param>
 public static Task <IDirectoryAttributes> AddAndGetAsync(this IDirectoryContext context, DirectoryAttributes entry,
                                                          DirectoryControl[] controls)
 {
     return(Task.Factory.StartNew(() => context.AddAndGet(entry, controls)));
 }
 /// <summary>
 /// Executes <see cref="DirectoryContext.GetByDN{T}"/> within a <see cref="Task"/>.
 /// </summary>
 /// <param name="context">The <see cref="DirectoryContext"/>.</param>
 /// <param name="distinguishedName">The distinguished name to look for.</param>
 /// <typeparam name="T">The type of mapped object</typeparam>
 /// <returns></returns>
 public static Task <T> GetByDNAsync <T>(this IDirectoryContext context, string distinguishedName) where T : class
 {
     return(Task.Factory.StartNew(() => context.GetByDN <T>(distinguishedName)));
 }
 /// <summary>
 /// Executes <see cref="DirectoryContext.ListServerAttributes"/> within a <see cref="Task"/>.
 /// </summary>
 /// <returns></returns>
 public static Task <IDirectoryAttributes> ListServerAttributesAsync(this IDirectoryContext context, params string[] attributes)
 {
     return(Task.Factory.StartNew(() => context.ListServerAttributes(attributes)));
 }
 public UsersController(IDirectoryContext context)
 {
     _context = context;
 }
 public ServerInfoController(IDirectoryContext context)
 {
     _context = context;
 }
Example #33
0
 public DirectoryService(IDirectoryContext context)
 {
     _context = context;
 }
Example #34
0
 public UserService(IDirectoryContext directoryContext)
 {
     if (_directoryContext == null)
         _directoryContext = directoryContext;
 }
 public ServerInfoController(IDirectoryContext context)
 {
     _context = context;
 }
 /// <summary>
 /// Executes <see cref="DirectoryContext.AddAttribute"/> within a <see cref="Task"/>.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="distinguishedName">The entry</param>
 /// <param name="attributeName">The name of the attribute</param>
 /// <param name="value">The value for the entry.</param>
 /// <param name="controls">Any <see cref="DirectoryControl"/>s to be sent with the request</param>
 /// <exception cref="DirectoryOperationException">Thrown if the operation fails.</exception>
 /// <exception cref="LdapConnection">Thrown if the operation fails.</exception>
 public static Task AddAttributeAsync(this IDirectoryContext context, string distinguishedName, string attributeName, object value = null,
                                      DirectoryControl[] controls = null)
 {
     return(Task.Factory.StartNew(() => context.AddAttribute(distinguishedName, attributeName, value, controls)));
 }