Exemple #1
0
        /// <summary>
        /// Initializes an instance of this object.
        /// </summary>
        public User()
        {
            store = Store.GetStore();
            if (store.DefaultDomain == null)
            {
                throw new SimiasException(User.missingDomainMessage);
            }

            // Is the default domain always the correct domain?
            domain = store.GetDomain(store.DefaultDomain);
            if (domain == null)
            {
                throw new SimiasException(User.missingDomainMessage);
            }

            if (domain.IsType("Enterprise") == false)
            {
                throw new SimiasException(User.missingDomainMessage);
            }

            ldapSettings = LdapSettings.Get(Store.StorePath);


            // Make sure the password is set on the admin
            SetAdminPassword();
        }
Exemple #2
0
        /// <summary>
        /// Process the users, groups and container through this ldap connection
        /// </summary>
        /// <param name="conn">ldap connection</param>
        /// <param name="settings">ldapsettings</param>
        private void ProcessSearchObjects(LdapConnection conn, LdapSettings settings)
        {
            foreach (string searchContext in settings.SearchContexts)
            {
                string[] searchAttributes = { "objectClass" };

                log.Debug("SearchObject: " + searchContext);

                try
                {
                    LdapEntry     ldapEntry       = conn.Read(searchContext, searchAttributes);
                    LdapAttribute attrObjectClass = ldapEntry.getAttribute("objectClass");
                    String[]      values          = attrObjectClass.StringValueArray;

                    if (IsUser(values) == true)
                    {
                        // Process SearchDN as
                        log.Debug("Processing User Object...");
                        ProcessSearchUser(conn, searchContext);
                    }
                    else if (IsGroup(values) == true)
                    {
                        // Process SearchDN as
                        log.Debug("Processing Group Object...");
                        ProcessSearchGroup(conn, searchContext);
                    }
                    else if (IsContainer(values) == true)
                    {
                        // Process SearchDN as Container
                        log.Debug("Processing Container Object...");
                        ProcessSearchContainer(conn, searchContext);
                    }
                    else
                    {
                        log.Debug("Invalid objectClass: " + values[0]);
                        log.Debug(attrObjectClass.ToString());
                    }
                }
                catch (SimiasShutdownException s)
                {
                    log.Error("ProcessSearchObjects SimiasShutdownException");
                    log.Error(s.Message);
                    throw s;
                }
                catch (LdapException e)
                {
                    log.Error("ProcessSearchObjects LdapException");
                    log.Error(e.LdapErrorMessage);
                    log.Error(e.StackTrace);
                    throw e;
                }
                catch (Exception e)
                {
                    log.Error("ProcessSearchObjects Exception");
                    log.Error(e.Message);
                    log.Error(e.StackTrace);
                    throw e;
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Call to inform a provider to start a synchronization cycle
        /// </summary>
        /// <returns> True - provider successfully finished a sync cycle,
        /// False - provider failed the sync cycle
        /// </returns>
        public bool Start(Simias.IdentitySynchronization.State State)
        {
            log.Debug("Start called");
            int MaxConnectRetry = 5;

            bool status = false;

            abort = false;
            try
            {
                this.state = State;

                try
                {
                    ldapSettings = LdapSettings.Get(Store.StorePath);
                    log.Debug("new LdapConnection");
                    conn = new LdapConnection();

                    log.Debug("Connecting to: " + ldapSettings.Host + " on port: " + ldapSettings.Port.ToString());
                    conn.SecureSocketLayer = ldapSettings.SSL;
                    for (int i = 1; i <= MaxConnectRetry; i++)
                    {
                        try
                        {
                            conn.Connect(ldapSettings.Host, ldapSettings.Port);
                        }
                        catch (Exception ex)
                        {
                            log.Debug("Failed to connect to : " + ldapSettings.Host + ", retry count: " + i.ToString() + ", Error Message : " + ex.Message);
                            continue;
                        }
                        break;
                    }


                    ProxyUser proxy = new ProxyUser();

                    log.Debug("Binding as: " + proxy.UserDN);
                    conn.Bind(proxy.UserDN, proxy.Password);

                    ProcessSimiasAdmin(conn);
                    ProcessSearchObjects(conn, ldapSettings);
                }
                catch (SimiasShutdownException s)
                {
                    log.Error(s.Message);
                    syncException = s;
                    syncStatus    = Status.SyncThreadDown;
                }
                catch (LdapException e)
                {
                    log.Error(e.LdapErrorMessage);
                    log.Error(e.StackTrace);
                    syncException = e;
                    syncStatus    =
                        (conn == null)
                                                        ? Status.LdapConnectionFailure
                                                        : Status.LdapAuthenticationFailure;

                    state.ReportError(e.LdapErrorMessage);
                }
                catch (Exception e)
                {
                    log.Error(e.Message);
                    log.Error(e.StackTrace);
                    syncException = e;
                    syncStatus    = Status.InternalException;

                    state.ReportError(e.Message);
                }
                finally
                {
                    if (conn != null)
                    {
                        log.Debug("Disconnecting Ldap connection");
                        try{
                            conn.Disconnect();
                        }catch {}
                        conn = null;
                    }
                }
                status = true;
            }
            catch (Exception e)
            {
                log.Error(e.Message);
                log.Error(e.StackTrace);
                State.ReportError(e.Message);
            }

            return(status);
        }