예제 #1
0
        /// <summary>
        /// Ensures configuration is valid to proceed
        /// </summary>
        /// <returns></returns>
        public virtual ConfigStatus ValidatePrerequisite()
        {
            Status = ConfigStatus.AllGood;
            if (PersistedObject == null)
            {
                Status |= ConfigStatus.PersistedObjectNotFound;
            }
            if (CurrentTrustedLoginProvider == null)
            {
                CurrentTrustedLoginProvider = LDAPCP.GetSPTrustAssociatedWithCP(LDAPCP._ProviderInternalName);
                if (CurrentTrustedLoginProvider == null)
                {
                    Status |= ConfigStatus.NoSPTrustAssociation;
                }
            }
            if (IdentityClaim == null && Status == ConfigStatus.AllGood)
            {
                IdentityClaim = this.IdentityClaim = PersistedObject.AttributesListProp.Find(x => String.Equals(CurrentTrustedLoginProvider.IdentityClaimTypeInformation.MappedClaimType, x.ClaimType, StringComparison.InvariantCultureIgnoreCase) && !x.CreateAsIdentityClaim);
                if (IdentityClaim == null)
                {
                    Status |= ConfigStatus.NoIdentityClaimType;
                }
            }
            if (PersistedObjectVersion != PersistedObject.Version)
            {
                Status |= ConfigStatus.PersistedObjectStale;
            }

            if (Status != ConfigStatus.AllGood)
            {
                LdapcpLogging.Log(String.Format(MostImportantError), TraceSeverity.High, EventSeverity.Information, LdapcpLogging.Categories.Configuration);
            }
            return(Status);
        }
예제 #2
0
        protected void grdLDAPConnections_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            if (ValidatePrerequisite() != ConfigStatus.AllGood)
            {
                return;
            }
            if (PersistedObject.LDAPConnectionsProp == null)
            {
                return;
            }
            GridViewRow rowToDelete = grdLDAPConnections.Rows[e.RowIndex];

            Guid Id = new Guid(rowToDelete.Cells[0].Text);

            PersistedObject.LDAPConnectionsProp.Remove(PersistedObject.LDAPConnectionsProp.Find(x => x.Id == Id));

            // Update object in database
            CommitChanges();
            LdapcpLogging.Log(
                String.Format("Removed a LDAP connection in PersistedObject {0}", Constants.LDAPCPCONFIG_NAME),
                TraceSeverity.Medium,
                EventSeverity.Information,
                LdapcpLogging.Categories.Configuration);

            InitializeAugmentation();
            PopulateLdapConnectionGrid();
        }
예제 #3
0
 public virtual void CommitChanges()
 {
     PersistedObject.Update();
     PersistedObjectVersion = PersistedObject.Version;
     LdapcpLogging.Log(
         String.Format("Updated PersistedObject {0} to version {1}", PersistedObject.DisplayName, PersistedObject.Version),
         TraceSeverity.Medium,
         EventSeverity.Information,
         LdapcpLogging.Categories.Configuration);
 }
예제 #4
0
        /// <summary>
        /// Add new LDAP connection to collection in persisted object
        /// </summary>
        void AddLdapConnection()
        {
            if (ValidatePrerequisite() != ConfigStatus.AllGood)
            {
                return;
            }

            if (this.RbUseCustomConnection.Checked && (this.TxtLdapConnectionString.Text == String.Empty || this.TxtLdapUsername.Text == String.Empty || this.TxtLdapPassword.Text == String.Empty))
            {
                this.LabelErrorTestLdapConnection.Text = TextErrorLDAPFieldsMissing;
                return;
            }

            if (this.RbUseServerDomain.Checked)
            {
                PersistedObject.LDAPConnectionsProp.Add(new LDAPConnection {
                    UserServerDirectoryEntry = true
                });
            }
            else
            {
                AuthenticationTypes authNType = GetSelectedAuthenticationTypes(true);
                PersistedObject.LDAPConnectionsProp.Add(
                    new LDAPConnection
                {
                    UserServerDirectoryEntry = false,
                    Path                = this.TxtLdapConnectionString.Text,
                    Username            = this.TxtLdapUsername.Text,
                    Password            = this.TxtLdapPassword.Text,
                    AuthenticationTypes = authNType,
                }
                    );
            }

            // Update object in database
            CommitChanges();
            LdapcpLogging.Log(
                String.Format("Added a new LDAP connection in PersistedObject {0}", Constants.LDAPCPCONFIG_NAME),
                TraceSeverity.Medium,
                EventSeverity.Information,
                LdapcpLogging.Categories.Configuration);

            PopulateLdapConnectionGrid();
            InitializeAugmentation();
            ViewState["LDAPpwd"] = String.Empty;
            TxtLdapPassword.Attributes.Remove("value");
            this.TxtLdapUsername.Text         = this.TxtLdapPassword.Text = String.Empty;
            this.TxtLdapConnectionString.Text = "LDAP://";
        }
예제 #5
0
 protected void Page_Load(object sender, EventArgs e)
 {
     LdapcpLogging.LogDebug(ValidatePrerequisite().ToString());
     if (ValidatePrerequisite() != ConfigStatus.AllGood && Status != ConfigStatus.NoIdentityClaimType)
     {
         this.LabelErrorMessage.Text   = base.MostImportantError;
         this.HideAllContent           = true;
         this.BtnCreateNewItem.Visible = false;
         return;
     }
     if (!this.IsPostBack)
     {
         Initialize();
     }
     BuildAttributesListTable(this.IsPostBack);
 }
예제 #6
0
        protected void ValidateLdapConnection()
        {
            ViewState["ForceCheckCustomLdapConnection"] = true;
            if (this.TxtLdapConnectionString.Text == String.Empty || this.TxtLdapPassword.Text == String.Empty || this.TxtLdapUsername.Text == String.Empty)
            {
                this.LabelErrorTestLdapConnection.Text = TextErrorLDAPFieldsMissing;
                return;
            }

            DirectoryEntry    de       = null;
            DirectorySearcher deSearch = new DirectorySearcher();

            try
            {
                AuthenticationTypes authNTypes = GetSelectedAuthenticationTypes(false);
                de = new DirectoryEntry(this.TxtLdapConnectionString.Text, this.TxtLdapUsername.Text, this.TxtLdapPassword.Text, authNTypes);
                deSearch.SearchRoot = de;
                deSearch.FindOne();
                this.LabelTestLdapConnectionOK.Text = TextConnectionSuccessful;
            }
            catch (Exception ex)
            {
                LdapcpLogging.LogException(LDAPCP._ProviderInternalName, "while testing LDAP connection", LdapcpLogging.Categories.Configuration, ex);
                this.LabelErrorTestLdapConnection.Text = String.Format(TextErrorTestLdapConnection, ex.Message);
            }
            finally
            {
                if (deSearch != null)
                {
                    deSearch.Dispose();
                }
                if (de != null)
                {
                    de.Dispose();
                }
            }

            // Required to set radio buttons of LDAP connections correctly in UI
            PopulateLdapConnectionGrid();
        }