/// <summary>
        /// Constructs the object and sets values to default
        /// </summary>
        public PawnLDAPAccessor()
        {
            this.ldapConnection   = null;
            this.ldapServer       = string.Empty;
            this.state            = LDAPState.DISCONNECTED;
            this.errorMessage     = string.Empty;
            this.ldapLoginUsr     = string.Empty;
            this.ldapLoginPwd     = string.Empty;
            this.ldapUserSearchDN = string.Empty;
            this.ldapUserIdKey    = string.Empty;
            this.pwdPolicyData    = null;
            var    dNow     = DateTime.Now;
            var    yearStr  = dNow.Date.Year.ToString().PadLeft(4, '0');
            var    monthStr = dNow.Date.Month.ToString().PadLeft(2, '0');
            var    dayStr   = dNow.Date.Day.ToString().PadLeft(2, '0');
            var    hrStr    = dNow.Hour.ToString().PadLeft(2, '0');
            var    minStr   = dNow.Minute.ToString().PadLeft(2, '0');
            var    sb       = new StringBuilder(64);
            string curDir   = Directory.GetCurrentDirectory();

            sb.Append(curDir + @"\logs\ldap_details_");
            sb.AppendFormat("{0}_{1}_{2}-{3}_{4}.log", yearStr, monthStr, dayStr, hrStr, minStr);
            this.ldapLogger = new TempFileLogger(sb.ToString(),
                                                 DefaultLoggerHandlers.defaultLogLevelCheckHandler,
                                                 DefaultLoggerHandlers.defaultLogLevelGenerator,
                                                 DefaultLoggerHandlers.defaultLogMessageHandler,
                                                 DefaultLoggerHandlers.defaultLogMessageFormatHandler,
                                                 DefaultLoggerHandlers.defaultDateStampGenerator);
            this.ldapLogger.setLogLevel(LogLevel.DEBUG);
            this.ldapLogger.logMessage(LogLevel.INFO, this, "PAWNLDAPAccessor instance constructed");
        }
Пример #2
0
 public UserChangePassword(PasswordPolicyVO pwd, string origPwd)
 {
     InitializeComponent();
     if (string.IsNullOrEmpty(origPwd))
     {
         throw new ApplicationException("Cannot change password without the original");
     }
     if (pwd == null)
     {
         throw new ApplicationException("Cannot change password without a password policy");
     }
     this.OriginalCurrentPassword   = origPwd;
     this.EnteredConfirmNewPassword = string.Empty;
     this.EnteredNewPassword        = string.Empty;
     this.EnteredConfirmNewPassword = string.Empty;
     this.pwdPolicy = pwd;
 }
        /// <summary>
        ///
        /// </summary>
        private void getPwdPolicy()
        {
            if (this.state == LDAPState.DISCONNECTED)
            {
                return;
            }

            this.ldapLogger.logMessage(LogLevel.INFO, this, "Retrieving password policy");

            //Clear error message
            this.errorMessage = string.Empty;

            //Only fetch the password policy if it has not been populated
            if (this.pwdPolicyData == null)
            {
                try
                {
                    //Define search to retrieve password policy
                    var ldapSearch =
                        new SearchRequest(
                            this.ldapPwdPolicyCN,
                            OBJECT_CLASS_FILTER,
                            System.DirectoryServices.Protocols.SearchScope.Subtree);

                    //Execute actual search to retrieve password policy
                    var ldapResponse =
                        (SearchResponse)this.ldapConnection.SendRequest(ldapSearch);

                    if (ldapResponse == null || ldapResponse.Entries == null || ldapResponse.Entries.Count <= 0)
                    {
                        this.ldapLogger.logMessage(LogLevel.FATAL, this, "Could not find password policy");
                        this.Disconnect();
                        this.ldapLogger.Dispose();
                        return;
                    }


                    //Retreive all password policy settings
                    SearchResultEntry ldapSearchEntry = ldapResponse.Entries[0];
                    this.pwdPolicyData = new PasswordPolicyVO();
                    Dictionary <PWD_POLICY_ATTRIBS, object> attribMap;
                    if (getAllPasswordDirectoryAttributes(ldapSearchEntry, out attribMap))
                    {
                        this.pwdPolicyData.AllowUserChange =
                            Utilities.GetBooleanValue(
                                attribMap[PWD_POLICY_ATTRIBS.PWDALLOWUSERCHANGE], false);
                        this.pwdPolicyData.AttributeName =
                            Utilities.GetStringValue(
                                attribMap[PWD_POLICY_ATTRIBS.PWDATTRIBUTE], string.Empty);
                        this.pwdPolicyData.CheckSyntax =
                            (short)Utilities.GetIntegerValue(
                                attribMap[PWD_POLICY_ATTRIBS.PWDCHECKSYNTAX], 0);
                        this.pwdPolicyData.ExpireWarningSeconds =
                            Utilities.GetLongValue(
                                attribMap[PWD_POLICY_ATTRIBS.PWDEXPIREWARNING], 0L);
                        this.pwdPolicyData.FailureCountIntervalSeconds =
                            Utilities.GetLongValue(
                                attribMap[PWD_POLICY_ATTRIBS.PWDFAILUREACCTINTERVAL], 0L);
                        this.pwdPolicyData.GraceLoginLimit =
                            Utilities.GetLongValue(
                                attribMap[PWD_POLICY_ATTRIBS.PWDGRACELOGINLIMIT], 0L);
                        this.pwdPolicyData.InHistoryCount =
                            (short)Utilities.GetIntegerValue(
                                attribMap[PWD_POLICY_ATTRIBS.PWDINHISTORY], 0);
                        this.pwdPolicyData.LockoutDurationMillis =
                            Utilities.GetLongValue(
                                attribMap[PWD_POLICY_ATTRIBS.PWDLOCKOUTDURATION], 0L);
                        this.pwdPolicyData.LockoutEnabled =
                            Utilities.GetBooleanValue(
                                attribMap[PWD_POLICY_ATTRIBS.PWDLOCKOUT], false);
                        this.pwdPolicyData.MaxAgeSeconds =
                            Utilities.GetLongValue(
                                attribMap[PWD_POLICY_ATTRIBS.PWDMAXAGE], 0L);
                        this.pwdPolicyData.MaxFailedLoginAttempts =
                            (short)Utilities.GetIntegerValue(
                                attribMap[PWD_POLICY_ATTRIBS.PWDMAXFAILURE], 0);
                        this.pwdPolicyData.MaxRepeatedChars =
                            (short)Utilities.GetIntegerValue(
                                attribMap[PWD_POLICY_ATTRIBS.PWDMAXREPCHARS], 0);
                        this.pwdPolicyData.MinAgeSeconds =
                            Utilities.GetLongValue(
                                attribMap[PWD_POLICY_ATTRIBS.PWDMINAGE], 0L);
                        this.pwdPolicyData.MinAlphaChars =
                            (short)Utilities.GetIntegerValue(
                                attribMap[PWD_POLICY_ATTRIBS.PWDMINALPHACHARS], 0);
                        this.pwdPolicyData.MinDiffChars =
                            (short)Utilities.GetIntegerValue(
                                attribMap[PWD_POLICY_ATTRIBS.PWDMINDIFFCHARS], 0);
                        this.pwdPolicyData.MinLength =
                            (short)Utilities.GetIntegerValue(
                                attribMap[PWD_POLICY_ATTRIBS.PWDMINLENGTH], 0);
                        this.pwdPolicyData.MinOtherChars =
                            (short)Utilities.GetIntegerValue(
                                attribMap[PWD_POLICY_ATTRIBS.PWDMINOTHERCHARS], 0);
                        this.pwdPolicyData.MustChange =
                            Utilities.GetBooleanValue(
                                attribMap[PWD_POLICY_ATTRIBS.PWDMUSTCHANGE], false);
                        this.pwdPolicyData.SafeModify =
                            Utilities.GetBooleanValue(
                                attribMap[PWD_POLICY_ATTRIBS.PWDSAFEMODIFY], false);
                    }
                }
                catch (Exception eX)
                {
                    this.pwdPolicyData = null;
                    this.ldapLogger.logMessage(LogLevel.FATAL, "Could not find the password policy: {0}", eX.Message);
                }
                finally
                {
                    if (this.pwdPolicyData == null)
                    {
                        this.ldapLogger.logMessage(LogLevel.FATAL, this, "Could not populate the password policy object");
                        this.Disconnect();
                        this.ldapLogger.Dispose();
                    }
                }
            }
        }
Пример #4
0
        private void testLDAPCxnButton_Click(object sender, EventArgs e)
        {
            if (!(((infoFlag & (uint)REQINFOFLAGS.LOGIN) > 0) &&
                  ((infoFlag & (uint)REQINFOFLAGS.PASSPOLICY) > 0) &&
                  ((infoFlag & (uint)REQINFOFLAGS.PASSWORD) > 0) &&
                  ((infoFlag & (uint)REQINFOFLAGS.PORT) > 0) &&
                  ((infoFlag & (uint)REQINFOFLAGS.SERVER) > 0) &&
                  ((infoFlag & (uint)REQINFOFLAGS.USERDN) > 0) &&
                  (infoFlag & (uint)REQINFOFLAGS.USERIDKEY) > 0))
            {
                MessageBox.Show("Please enter all required data for LDAP connection.",
                                "PawnStoreSetup Alert",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
                return;
            }

            //Ensure LDAP login field is properly
            //formatted
            string login = LDAPLogin;

            if (LDAPLogin.IndexOf("cn=", StringComparison.OrdinalIgnoreCase) == -1)
            {
                login = "******" + LDAPLogin;
            }

            //Call LDAP connection class
            if (PawnLDAPAccessor.Instance.State == PawnLDAPAccessor.LDAPState.DISCONNECTED)
            {
                PawnLDAPAccessor.Instance.InitializeConnection(
                    this.LDAPServer,
                    this.LDAPPort,
                    login,
                    LDAPPassword,
                    LDAPPassPolicyDN,
                    LDAPUserDN,
                    LDAPUserIdKey);
            }

            LDAPCxnSuccess = false;
            if (PawnLDAPAccessor.Instance.State == PawnLDAPAccessor.LDAPState.CONNECTED)
            {
                this.LDAPPwdPolicy = PawnLDAPAccessor.Instance.PasswordPolicy;
                LDAPCxnSuccess     = true;
            }

            if (!LDAPCxnSuccess)
            {
                MessageBox.Show(
                    "LDAP Connection Failed. Please change the field values and try again.");
                return;
            }

            //Show message box that LDAP is now connected
            MessageBox.Show("LDAP Connection Successful", "PawnStoreSetup Alert");

            //Enable test user search and done button
            this.testSearchButton.Enabled          = false;
            this.testSearchUserTextBox.Enabled     = true;
            this.testPasswordSearchTextBox.Enabled = true;
            this.doneButton.Enabled = true;

            //Disable test connection button
            this.testLDAPCxnButton.Enabled = false;
        }