Esempio n. 1
0
        private void ExecBaseFeatureActivated(SPFeatureReceiverProperties properties)
        {
            // Wrapper function for base FeatureActivated.
            // Used because base keywork can lead to unverifiable code inside lambda expression
            base.FeatureActivated(properties);
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                try
                {
                    ClaimsProviderLogging svc = ClaimsProviderLogging.Local;
                    ClaimsProviderLogging.Log($"[{LDAPCP._ProviderInternalName}] Activating farm-scoped feature for claims provider \"{LDAPCP._ProviderInternalName}\"", TraceSeverity.High, EventSeverity.Information, ClaimsProviderLogging.TraceCategory.Configuration);

                    var spTrust = LDAPCP.GetSPTrustAssociatedWithCP(LDAPCP._ProviderInternalName);
                    if (spTrust != null)
                    {
                        LDAPCPConfig existingConfig = LDAPCPConfig.GetConfiguration(ClaimsProviderConstants.CONFIG_NAME);
                        if (existingConfig == null)
                        {
                            LDAPCPConfig.CreateConfiguration(ClaimsProviderConstants.CONFIG_ID, ClaimsProviderConstants.CONFIG_NAME, spTrust.Name);
                        }
                        else
                        {
                            ClaimsProviderLogging.Log($"[{LDAPCP._ProviderInternalName}] Use configuration \"{ClaimsProviderConstants.CONFIG_NAME}\" found in the configuration database", TraceSeverity.High, EventSeverity.Information, ClaimsProviderLogging.TraceCategory.Configuration);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ClaimsProviderLogging.LogException(LDAPCP._ProviderInternalName, $"activating farm-scoped feature for {LDAPCP._ProviderInternalName}", ClaimsProviderLogging.TraceCategory.Configuration, ex);
                }
            });
        }
Esempio n. 2
0
        public static LDAPCPConfig GetFromConfigDB()
        {
            SPPersistedObject parent = SPFarm.Local;

            try
            {
                LDAPCPConfig persistedObject = parent.GetChild <LDAPCPConfig>(Constants.LDAPCPCONFIG_NAME);
                if (persistedObject != null)
                {
                    if (persistedObject.LDAPConnectionsProp == null)
                    {
                        // persistedObject.LDAPConnections introduced in v2.1 (SP2013)
                        // This can happen if LDAPCP was migrated from a previous version and LDAPConnections didn't exist yet in persisted object
                        persistedObject.LDAPConnectionsProp = GetDefaultLDAPConnection();
                        LdapcpLogging.Log(
                            String.Format("LDAP connections array is missing in the persisted object {0} and default connection was used. Visit LDAPCP admin page and validate it to create the array.", Constants.LDAPCPCONFIG_NAME),
                            TraceSeverity.High,
                            EventSeverity.Information,
                            LdapcpLogging.Categories.Configuration);
                    }
                }
                return(persistedObject);
            }
            catch (Exception ex)
            {
                LdapcpLogging.LogException(LDAPCP._ProviderInternalName, String.Format("Error while retrieving SPPersistedObject {0}", Constants.LDAPCPCONFIG_NAME), LdapcpLogging.Categories.Core, ex);
            }
            return(null);
        }
Esempio n. 3
0
        private void RemovePersistedObject()
        {
            var PersistedObject = LDAPCPConfig.GetFromConfigDB();

            if (PersistedObject != null)
            {
                PersistedObject.Delete();
            }
        }
Esempio n. 4
0
        public static void DeleteLDAPCPConfig()
        {
            LDAPCPConfig LdapcpConfig = LDAPCPConfig.GetFromConfigDB();

            if (LdapcpConfig != null)
            {
                LdapcpConfig.Delete();
            }
        }
Esempio n. 5
0
 public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
 {
     SPSecurity.RunWithElevatedPrivileges(delegate()
     {
         try
         {
             ClaimsProviderLogging.Log($"[{LDAPCP._ProviderInternalName}] Uninstalling farm-scoped feature for claims provider \"{LDAPCP._ProviderInternalName}\": Deleting configuration from the farm", TraceSeverity.High, EventSeverity.Information, ClaimsProviderLogging.TraceCategory.Configuration);
             LDAPCPConfig.DeleteConfiguration(ClaimsProviderConstants.CONFIG_NAME);
             ClaimsProviderLogging.Unregister();
         }
         catch (Exception ex)
         {
             ClaimsProviderLogging.LogException(LDAPCP._ProviderInternalName, $"deactivating farm-scoped feature for claims provider \"{LDAPCP._ProviderInternalName}\"", ClaimsProviderLogging.TraceCategory.Configuration, ex);
         }
     });
 }
Esempio n. 6
0
        public static void ResetClaimsList()
        {
            LDAPCPConfig persistedObject = GetFromConfigDB();

            if (persistedObject != null)
            {
                persistedObject.AttributesListProp.Clear();
                persistedObject.AttributesListProp = GetDefaultAttributesList();
                persistedObject.Update();

                LdapcpLogging.Log(
                    String.Format("Claims list of PersistedObject {0} was successfully reset to default relationship table", Constants.LDAPCPCONFIG_NAME),
                    TraceSeverity.High, EventSeverity.Information, LdapcpLogging.Categories.Core);
            }
            return;
        }
Esempio n. 7
0
        /// <summary>
        /// Creates a persisted object with default LDAPCP configuration. It won't be saved in configuration database unless Update() is called, but property Id should be set with a unique Guid before.
        /// </summary>
        /// <returns></returns>
        public static LDAPCPConfig GetDefaultConfiguration()
        {
            LDAPCPConfig PersistedObject = new LDAPCPConfig(SPFarm.Local);

            PersistedObject.AttributesList            = GetDefaultAttributesList();
            PersistedObject.LDAPConnections           = GetDefaultLDAPConnection();
            PersistedObject.PickerEntityGroupName     = "Results";
            PersistedObject.AlwaysResolveUserInput    = false;
            PersistedObject.AddWildcardInFrontOfQuery = false;
            PersistedObject.FilterEnabledUsersOnly    = false;
            PersistedObject.FilterSecurityGroupsOnly  = false;
            //PersistedObject.LDAPCPIssuerType = SPOriginalIssuerType.TrustedProvider;
            PersistedObject.FilterExactMatchOnly = false;
            PersistedObject.Timeout               = Constants.LDAPCPCONFIG_TIMEOUT;
            PersistedObject.AugmentationEnabled   = false;
            PersistedObject.AugmentationClaimType = String.Empty;
            return(PersistedObject);
        }
Esempio n. 8
0
        /// <summary>
        /// Create the persisted object that contains default configuration of LDAPCP.
        /// It should be created only in central administration with application pool credentials
        /// because this is the only place where we are sure user has the permission to write in the config database
        /// </summary>
        public static LDAPCPConfig CreatePersistedObject()
        {
            LDAPCPConfig PersistedObject = GetDefaultConfiguration();

            PersistedObject.Id = new Guid(Constants.LDAPCPCONFIG_ID);
            try
            {
                PersistedObject.Update();
            }
            catch (NullReferenceException nullex)
            {
                // This exception occurs if an older version of the persisted object lives in the config database with a schema that doesn't match current one
                string stsadmcmd = String.Format("SELECT * FROM Objects WHERE Id LIKE '{0}'", Constants.LDAPCPCONFIG_ID);
                string error     = String.Format("Unable to create PersistedObject {0}. This usually occurs because a persisted object with the same Id is used by another assembly (could be a previous version). Object is impossible to update or delete from Object Model unless you add the missing assembly to the GAC. You can see this object by running this query: \"{1}\"", PersistedObject.Name, stsadmcmd);

                LdapcpLogging.Log(error, TraceSeverity.Unexpected, EventSeverity.Error, LdapcpLogging.Categories.Core);

                // Tyy to delete it... but OM doesn't manage to get the object
                SPPersistedObject staleObject = SPFarm.Local.GetObject(new Guid(Constants.LDAPCPCONFIG_ID));
                if (staleObject != null)
                {
                    staleObject.Delete();
                    PersistedObject.Update();
                }
                else
                {
                    throw new Exception(error, nullex);
                }
            }

            LdapcpLogging.Log(
                String.Format("Created PersistedObject {0} with Id {1}", PersistedObject.Name, PersistedObject.Id),
                TraceSeverity.Medium, EventSeverity.Information, LdapcpLogging.Categories.Core);

            return(PersistedObject);
        }