Esempio n. 1
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. 2
0
 public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, IDictionary <string, string> parameters)
 {
     SPSecurity.RunWithElevatedPrivileges(delegate()
     {
         //this.RemovePersistedObject();
         LdapcpLogging svc = LdapcpLogging.Local;
     });
 }
Esempio n. 3
0
 private void ExecBaseFeatureActivated(Microsoft.SharePoint.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()
     {
         LdapcpLogging svc = LdapcpLogging.Local;
     });
 }
Esempio n. 4
0
        public static AttributeHelper FindAttribute(List <AttributeHelper> processedAttributes, string claimType)
        {
            var Attributes = processedAttributes.FindAll(x =>
                                                         String.Equals(x.ClaimType, claimType, StringComparison.InvariantCultureIgnoreCase) &&
                                                         !x.CreateAsIdentityClaim);

            if (Attributes.Count != 1)
            {
                // Should always find only 1 attribute at this stage
                LdapcpLogging.Log(String.Format("[{0}] Found {1} attributes that match the claim type \"{2}\", but exactly 1 is expected. Verify that there is no duplicate claim type. Aborting operation.", LDAPCP._ProviderInternalName, Attributes.Count.ToString(), claimType), TraceSeverity.Unexpected, EventSeverity.Error, LdapcpLogging.Categories.Claims_Picking);
                return(null);
            }
            return(Attributes.First());
        }
Esempio n. 5
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. 6
0
 public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
 {
     SPSecurity.RunWithElevatedPrivileges(delegate()
     {
         //using (StreamWriter outfile = new StreamWriter(@"c:\temp\featurereceiver.txt", true))
         //{
         //    outfile.WriteLine(DateTime.Now.ToString() + " - FeatureDeactivating called");
         //}
         base.RemoveClaimProvider(LDAPCP._ProviderInternalName);
         //var trust = LDAPCP.GetSPTrustAssociatedWithCP(LDAPCP._ProviderInternalName);
         //if (trust != null)
         //{
         //    trust.ClaimProviderName = null;
         //    trust.Update();
         //}
         this.RemovePersistedObject();
         LdapcpLogging.Unregister();
     });
 }
Esempio n. 7
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);
        }