public static IEnumerable <string> GetSiteUrls(SPWebApplication webApplication) { foreach (string sc in webApplication.Sites.Names) { yield return (string.IsNullOrEmpty(sc) ? SPUrlUtility.CombineUrl(webApplication.GetResponseUri(SPUrlZone.Default).AbsoluteUri, "/") : SPUrlUtility.CombineUrl(webApplication.GetResponseUri(SPUrlZone.Default).AbsoluteUri, sc)); } }
public override string ToString() { string str = application.GetResponseUri(SPUrlZone.Default).ToString(); if (application.IsAdministrationWebApplication) { str += (" — " + res.CentralAdmin); } else if (IsSRP) { str += (" — " + res.SharedResourceProvider); } else if (!String.IsNullOrEmpty(application.DisplayName)) { str += " — \'" + application.DisplayName + "\'"; } else if (!String.IsNullOrEmpty(application.Name)) { str += " — \'" + application.Name + "\'"; } int numSiteCollections = application.Sites.Count; str += String.Format(" — " + res.Sites, numSiteCollections); return(str); }
public static Location ToLocation(this SPWebApplication webApp, string parentId) { var id = webApp.Id; var uri = webApp.GetResponseUri(SPUrlZone.Default); string url; if (uri != null) { url = uri.ToString(); } else { url = "No ResponseUri in default zone found."; } var location = LocationFactory.GetLocation( id, webApp.DisplayName, parentId, Scope.WebApplication, url, webApp.Sites.Count); return(location); }
public override string ToString() { string str = application.GetResponseUri(SPUrlZone.Default).ToString(); if (application.IsAdministrationWebApplication) { str += " (Central Administration)"; } else if (IsSRP) { str += " (Shared Resource Provider)"; } else if (!String.IsNullOrEmpty(application.DisplayName)) { str += " (" + application.DisplayName + ")"; } else if (!String.IsNullOrEmpty(application.Name)) { str += " (" + application.Name + ")"; } int numSiteCollections = application.Sites.Count; str += String.Format(" ({0} site collection{1})", numSiteCollections, (numSiteCollections > 1) ? "s" : String.Empty); return(str); }
public static SPListItem GetClaimProvider(SPWebApplication webApp, SPUrlZone zone) { SPAdministrationWebApplication adminWebApp = SPAdministrationWebApplication.Local; using (SPSite siteCollection = new SPSite(adminWebApp.Sites[0].Url)) { using (SPWeb site = siteCollection.OpenWeb()) { SPList list = site.Lists.TryGetList("Nauplius.ADLDS.FBA - WebApplicationSettings"); if (list != null) { if (list.ItemCount >= 1) { foreach (SPListItem item in list.Items) { if (item["WebApplicationUrl"].ToString() == webApp.GetResponseUri(zone).AbsoluteUri) { return(item); } } } } } } return(null); }
public IisSettingNode(SPWebApplication app, KeyValuePair<SPUrlZone, SPIisSettings> iisSettings) { this.Tag = iisSettings.Value; this.Name = iisSettings.Key.ToString(); this.Text = iisSettings.Key.ToString(); this.ToolTipText = iisSettings.Key.ToString(); this.BrowserUrl = app.GetResponseUri(iisSettings.Key).ToString(); this.Setup(); }
public IisSettingNode(SPWebApplication app, KeyValuePair <SPUrlZone, SPIisSettings> iisSettings) { this.Tag = iisSettings.Value; this.Name = iisSettings.Key.ToString(); this.Text = iisSettings.Key.ToString(); this.ToolTipText = iisSettings.Key.ToString(); this.BrowserUrl = app.GetResponseUri(iisSettings.Key).ToString(); this.Setup(); }
protected void SaveOrUpdateList(SPWebApplication selectedWebApp) { using (SPSite siteCollection = new SPSite(SPContext.Current.Site.ID)) { using (SPWeb site = siteCollection.OpenWeb()) { try { SPList list = site.Lists.TryGetList("Nauplius.ADLDS.UserProfiles - WebAppSettings"); if (list != null) { if (selectedWebApp != null) { string webAppUrl = selectedWebApp.GetResponseUri(SPUrlZone.Default).AbsoluteUri; SPListItemCollection items = list.Items; foreach (SPListItem item in items) { if (item["WebApplicationUrl"].ToString() == webAppUrl) { SPListItem updateItem = list.Items[item.UniqueId]; updateItem["WebApplicationUrl"] = webAppUrl; updateItem["ADLDSServer"] = tBSN.Text; updateItem["ADLDSPort"] = tBPrtNo.Text; updateItem["ADLDSDN"] = tBDNPath.Text; updateItem["ADLDSUseSSL"] = cBUseSSL.Checked; updateItem["ADLDSLoginAttrib"] = tBLoginAttrib.Text; updateItem.Update(); return; } } SPListItem newItem = list.Items.Add(); newItem["WebApplicationUrl"] = webAppUrl; newItem["ADLDSServer"] = tBSN.Text; newItem["ADLDSPort"] = tBPrtNo.Text; newItem["ADLDSDN"] = tBDNPath.Text; newItem["ADLDSUseSSL"] = cBUseSSL.Checked; newItem["ADLDSLoginAttrib"] = tBLoginAttrib.Text; newItem.Update(); } } } catch (Exception) { } } } }
public static FeatureParent GetFeatureParent(SPWebApplication webApp, string name = "") { FeatureParent p = null; string locationUrl = string.Empty; try { if (webApp == null) { return(GetFeatureParentUndefined()); } locationUrl = webApp.GetResponseUri(SPUrlZone.Default).ToString(); p = new FeatureParent() { DisplayName = string.IsNullOrEmpty(name) ? webApp.Name : name, // + " (" + web.Name + ")", Url = locationUrl, Id = webApp.Id, Scope = SPFeatureScope.WebApplication }; } catch (Exception ex) { Log.Error( string.Format( "Error when trying to get web app {0}.", locationUrl ), ex); return(GetFeatureParentUndefined(ex.Message)); } try { var features = webApp.Features; p.ActivatedFeatures = ActivatedFeature.MapSpFeatureToActivatedFeature(features, p); } catch (Exception ex) { Log.Error( string.Format( "Error when trying to load features from web app {0}.", locationUrl ), ex); } return(p); }
public static string GetWebApplicationZoneUrl(SPWebApplication webApplication, SPUrlZone urlZone = SPUrlZone.Default) { if (webApplication == null) { return(string.Empty); } try { return(webApplication.GetResponseUri(urlZone).AbsoluteUri); } catch { return(string.Empty); } }
public override string ToString() { string str = application.GetResponseUri(SPUrlZone.Default).ToString(); if (application.IsAdministrationWebApplication) { str += " (Central Administration)"; } else if (IsSRP) { str += " (Shared Resource Provider)"; } else if (!String.IsNullOrEmpty(application.DisplayName)) { str += " (" + application.DisplayName + ")"; } else if (!String.IsNullOrEmpty(application.Name)) { str += " (" + application.Name + ")"; } return(str); }
public static FeatureParent GetFeatureParent(SPWebApplication webApp, string name = "") { try { if (webApp == null) { return(GetFeatureParentUndefined()); } var p = new FeatureParent() { DisplayName = string.IsNullOrEmpty(name) ? webApp.Name : name, // + " (" + web.Name + ")", Url = webApp.GetResponseUri(SPUrlZone.Default).ToString(), Id = webApp.Id, Scope = SPFeatureScope.WebApplication }; return(p); } catch (Exception ex) { return(GetFeatureParentUndefined(ex.Message)); } }
protected void FillItems(SPWebApplication selectedWebApp) { using (SPSite siteCollection = new SPSite(SPContext.Current.Site.ID)) { using (SPWeb site = siteCollection.OpenWeb()) { try { SPList list = site.Lists.TryGetList("Nauplius.ADLDS.UserProfiles - WebAppSettings"); if (list != null) { if (selectedWebApp != null) { string webAppUrl = selectedWebApp.GetResponseUri(SPUrlZone.Default).AbsoluteUri; SPListItemCollection items = list.Items; foreach (SPListItem item in items) { if (item["WebApplicationUrl"].ToString() == webAppUrl) { tBSN.Text = item["ADLDSServer"].ToString(); tBPrtNo.Text = item["ADLDSPort"].ToString(); tBDNPath.Text = item["ADLDSDN"].ToString(); cBUseSSL.Checked = (bool)item["ADLDSUseSSL"]; tBLoginAttrib.Text = item["ADLDSLoginAttrib"].ToString(); } } } } } catch (Exception) { } } } }
public static void InitializeSiteCollection() { #if DEBUG TestSiteCollUri = new Uri("http://spsites/sites/" + TestContext.Parameters["TestSiteCollectionName"]); return; // Uncommented when debugging LDAPCP code from unit tests #endif logFileListener = new TextWriterTraceListener(TestContext.Parameters["TestLogFileName"]); Trace.Listeners.Add(logFileListener); Trace.AutoFlush = true; Trace.TraceInformation($"{DateTime.Now.ToString("s")} Start integration tests of {ClaimsProviderName} {FileVersionInfo.GetVersionInfo(Assembly.GetAssembly(typeof(ldapcp.LDAPCP)).Location).FileVersion}."); Trace.WriteLine($"{DateTime.Now.ToString("s")} DataFile_AllAccounts_Search: {DataFile_AllAccounts_Search}"); Trace.WriteLine($"{DateTime.Now.ToString("s")} DataFile_AllAccounts_Validate: {DataFile_AllAccounts_Validate}"); Trace.WriteLine($"{DateTime.Now.ToString("s")} TestSiteCollectionName: {TestContext.Parameters["TestSiteCollectionName"]}"); if (SPTrust == null) { Trace.TraceError($"{DateTime.Now.ToString("s")} SPTrust: is null"); } else { Trace.WriteLine($"{DateTime.Now.ToString("s")} SPTrust: {SPTrust.Name}"); } LDAPCPConfig config = LDAPCPConfig.GetConfiguration(UnitTestsHelper.ClaimsProviderConfigName, UnitTestsHelper.SPTrust.Name); if (config == null) { LDAPCPConfig.CreateConfiguration(ClaimsProviderConstants.CONFIG_ID, ClaimsProviderConstants.CONFIG_NAME, SPTrust.Name); } var service = SPFarm.Local.Services.GetValue <SPWebService>(String.Empty); SPWebApplication wa = service.WebApplications.FirstOrDefault(); if (wa != null) { Trace.WriteLine($"{DateTime.Now.ToString("s")} Web application {wa.Name} found."); SPClaimProviderManager claimMgr = SPClaimProviderManager.Local; string encodedClaim = claimMgr.EncodeClaim(TrustedGroup); SPUserInfo userInfo = new SPUserInfo { LoginName = encodedClaim, Name = TrustedGroupToAdd_ClaimValue }; // The root site may not exist, but it must be present for tests to run Uri rootWebAppUri = wa.GetResponseUri(0); if (!SPSite.Exists(rootWebAppUri)) { Trace.WriteLine($"{DateTime.Now.ToString("s")} Creating root site collection {rootWebAppUri.AbsoluteUri}..."); SPSite spSite = wa.Sites.Add(rootWebAppUri.AbsoluteUri, "root", "root", 1033, "STS#1", FarmAdmin, String.Empty, String.Empty); spSite.RootWeb.CreateDefaultAssociatedGroups(FarmAdmin, FarmAdmin, spSite.RootWeb.Title); SPGroup membersGroup = spSite.RootWeb.AssociatedMemberGroup; membersGroup.AddUser(userInfo.LoginName, userInfo.Email, userInfo.Name, userInfo.Notes); spSite.Dispose(); } if (!Uri.TryCreate(rootWebAppUri, TestSiteRelativePath, out TestSiteCollUri)) { Trace.TraceError($"{DateTime.Now.ToString("s")} Unable to generate Uri of test site collection from Web application Uri {rootWebAppUri.AbsolutePath} and relative path {TestSiteRelativePath}."); } if (!SPSite.Exists(TestSiteCollUri)) { Trace.WriteLine($"{DateTime.Now.ToString("s")} Creating site collection {TestSiteCollUri.AbsoluteUri}..."); SPSite spSite = wa.Sites.Add(TestSiteCollUri.AbsoluteUri, ClaimsProviderName, ClaimsProviderName, 1033, "STS#1", FarmAdmin, String.Empty, String.Empty); spSite.RootWeb.CreateDefaultAssociatedGroups(FarmAdmin, FarmAdmin, spSite.RootWeb.Title); SPGroup membersGroup = spSite.RootWeb.AssociatedMemberGroup; membersGroup.AddUser(userInfo.LoginName, userInfo.Email, userInfo.Name, userInfo.Notes); spSite.Dispose(); } else { using (SPSite spSite = new SPSite(TestSiteCollUri.AbsoluteUri)) { SPGroup membersGroup = spSite.RootWeb.AssociatedMemberGroup; membersGroup.AddUser(userInfo.LoginName, userInfo.Email, userInfo.Name, userInfo.Notes); } } } else { Trace.TraceError($"{DateTime.Now.ToString("s")} Web application was NOT found."); } }
protected void RemoveFbaSettings(SPWebApplication webApp, SPFeatureReceiverProperties properties) { using (SPSite siteCollection = new SPSite(SPContext.Current.Site.ID)) { using (SPWeb site = siteCollection.OpenWeb()) { try { SPList list = site.Lists.TryGetList("Nauplius.ADLDS.FBA - WebApplicationSettings"); if (list != null) { SPListItemCollection items = list.Items; foreach (SPListItem item in items) { var zone = GetZone(item); if (item["WebApplicationUrl"].ToString() == webApp.GetResponseUri(zone).AbsoluteUri) { //Remove the Forms Authentication provider for the Web Application try { foreach (var provider in webApp.IisSettings[zone].ClaimsAuthenticationProviders) { if (provider.ClaimProviderName == "Forms") { webApp.IisSettings[zone].DeleteClaimsAuthenticationProvider(provider); webApp.Update(); webApp.ProvisionGlobally(); break; } } } catch (ArgumentNullException) { //Forms provider already removed } catch (ArgumentException) { //Claims provider is null } finally { webApp.IisSettings[zone].ClaimsAuthenticationRedirectionUrl = null; webApp.Update(); webApp.ProvisionGlobally(); } WebModifications.CreateWildcardNode(true, webApp, zone); WebModifications.CreateProviderNode(true, webApp, zone); WebModifications.CreateStsProviderNode(true, properties, zone); WebModifications.CreateAdminWildcardNode(true, webApp, zone); WebModifications.CreateAdminProviderNode(true, webApp, zone); var local = SPFarm.Local; var services = from s in local.Services where s.Name == "SPTimerV4" select s; var service = services.First(); foreach (var job in service.JobDefinitions) { if (job.Name == tJobName) { if (job.IsDisabled) { job.IsDisabled = false; } job.Update(); job.RunNow(); } } } } } } catch (SPException ex) { Logging.LogMessage(951, Logging.LogCategories.STSXML, TraceSeverity.Unexpected, String.Format("Unable to update the WebApplicationSettings List in Central Administration. {0}", ex.StackTrace), new object[] { null }); throw new SPException(@"Unable to update the WebApplicationSettings List in Central Administration. Validate the list exists."); } } } }
protected void SaveOrUpdateList(SPWebApplication selectedWebApp) { using (SPSite siteCollection = new SPSite(SPContext.Current.Site.ID)) { using (SPWeb site = siteCollection.OpenWeb()) { try { SPList list = site.Lists.TryGetList("Nauplius.ADLDS.FBA - WebApplicationSettings"); if (list != null) { if (selectedWebApp != null) { string webAppUrl = selectedWebApp.GetResponseUri(SPUrlZone.Default).AbsoluteUri; //Amerstands can't be passed directly to XML string grpUsrFilter = Regex.Replace(txtGrpUsrFilter.Text, "&(?!amp;)", "&"); string grpFilter = Regex.Replace(txtGrpFilter.Text, "&(?!amp;)", "&"); SPListItemCollection items = list.Items; foreach (SPListItem item in items) { if (item["WebApplicationUrl"].ToString() == webAppUrl) { SPListItem updateItem = list.Items[item.UniqueId]; //Web Application updateItem["WebApplicationUrl"] = webAppUrl; updateItem["WebApplicationZone"] = "Default"; updateItem["WebApplicationMembershipProvider"] = txtMemProv.Text; updateItem["WebApplicationRoleProvider"] = txtRoleProv.Text; updateItem["CustomUrl"] = txtCustomUrl.Text; //AD LDS Server updateItem["ADLDSServer"] = tBSN.Text; updateItem["ADLDSPort"] = tBPrtNo.Text; updateItem["ADLDSUseSSL"] = cBUseSSL.Checked; //User updateItem["ADLDSLoginAttrib"] = tBLoginAttrib.Text; updateItem["ADLDSUserDNAttrib"] = txtUsrDNAttrib.Text; updateItem["ADLDSUserContainer"] = txtUsrContainer.Text; updateItem["ADLDSUserObjectClass"] = txtUsrObjClass.Text; updateItem["ADLDSUserFilter"] = txtUsrFilter.Text; updateItem["ADLDSUserScope"] = txtUsrScope.Text; updateItem["ADLDSUserOtherReqAttrib"] = txtUsrOtherAttribs.Text; //Group updateItem["ADLDSGroupContainer"] = txtGrpContainer.Text; updateItem["ADLDSGroupNameAttrib"] = txtGrpNameAttrib.Text; updateItem["ADLDSGroupNameAltSearchAttrib"] = txtGrpAltSearchAttrib.Text; updateItem["ADLDSGroupMemAttrib"] = txtGrpMemAttrib.Text; updateItem["ADLDSGroupDNAttrib"] = txtGrpDNAttrib.Text; updateItem["ADLDSGroupUserFilter"] = grpUsrFilter; updateItem["ADLDSGroupFilter"] = grpFilter; updateItem["ADLDSGroupScope"] = txtGrpScope.Text; updateItem.Update(); return; } } SPListItem newItem = list.Items.Add(); newItem["WebApplicationUrl"] = webAppUrl; newItem["WebApplicationZone"] = "Default"; newItem["WebApplicationMembershipProvider"] = txtMemProv.Text; newItem["WebApplicationRoleProvider"] = txtRoleProv.Text; newItem["CustomUrl"] = txtCustomUrl.Text; //AD LDS Server newItem["ADLDSServer"] = tBSN.Text; newItem["ADLDSPort"] = tBPrtNo.Text; newItem["ADLDSUseSSL"] = cBUseSSL.Checked; //User newItem["ADLDSLoginAttrib"] = tBLoginAttrib.Text; newItem["ADLDSUserDNAttrib"] = txtUsrDNAttrib.Text; newItem["ADLDSUserContainer"] = txtUsrContainer.Text; newItem["ADLDSUserObjectClass"] = txtUsrObjClass.Text; newItem["ADLDSUserFilter"] = txtUsrFilter.Text; newItem["ADLDSUserScope"] = txtUsrScope.Text; newItem["ADLDSUserOtherReqAttrib"] = txtUsrOtherAttribs.Text; //Group newItem["ADLDSGroupContainer"] = txtGrpContainer.Text; newItem["ADLDSGroupNameAttrib"] = txtGrpNameAttrib.Text; newItem["ADLDSGroupNameAltSearchAttrib"] = txtGrpAltSearchAttrib.Text; newItem["ADLDSGroupMemAttrib"] = txtGrpMemAttrib.Text; newItem["ADLDSGroupDNAttrib"] = txtGrpDNAttrib.Text; newItem["ADLDSGroupUserFilter"] = grpUsrFilter; newItem["ADLDSGroupFilter"] = grpFilter; newItem["ADLDSGroupScope"] = txtGrpScope.Text; newItem.Update(); } } } catch (Exception) { } } } }
protected void FillItems(SPWebApplication selectedWebApp) { using (SPSite siteCollection = new SPSite(SPContext.Current.Site.ID)) { using (SPWeb site = siteCollection.OpenWeb()) { try { SPList list = site.Lists.TryGetList("Nauplius.ADLDS.FBA - WebApplicationSettings"); if (list != null) { if (selectedWebApp != null) { string webAppUrl = selectedWebApp.GetResponseUri(SPUrlZone.Default).AbsoluteUri; SPListItemCollection items = list.Items; foreach (SPListItem item in items) { if (item["WebApplicationUrl"].ToString() == webAppUrl) { //txtWebAppZone.text = item["WebApplicationZone"].ToString(); txtMemProv.Text = item["WebApplicationMembershipProvider"].ToString(); txtRoleProv.Text = item["WebApplicationRoleProvider"].ToString(); try { txtCustomUrl.Text = item["CustomUrl"].ToString(); } catch (Exception) { //CustomUrl is null } //AD LDS Server tBSN.Text = item["ADLDSServer"].ToString(); tBPrtNo.Text = item["ADLDSPort"].ToString(); cBUseSSL.Checked = (bool)item["ADLDSUseSSL"]; //User tBLoginAttrib.Text = item["ADLDSLoginAttrib"].ToString(); txtUsrDNAttrib.Text = item["ADLDSUserDNAttrib"].ToString(); txtUsrContainer.Text = item["ADLDSUserContainer"].ToString(); txtUsrObjClass.Text = item["ADLDSUserObjectClass"].ToString(); txtUsrFilter.Text = item["ADLDSUserFilter"].ToString(); txtUsrScope.Text = item["ADLDSUserScope"].ToString(); txtUsrOtherAttribs.Text = item["ADLDSUserOtherReqAttrib"].ToString(); //Group txtGrpContainer.Text = item["ADLDSGroupContainer"].ToString(); txtGrpNameAttrib.Text = item["ADLDSGroupNameAttrib"].ToString(); txtGrpAltSearchAttrib.Text = item["ADLDSGroupNameAltSearchAttrib"].ToString(); txtGrpMemAttrib.Text = item["ADLDSGroupMemAttrib"].ToString(); txtGrpDNAttrib.Text = item["ADLDSGroupDNAttrib"].ToString(); txtGrpUsrFilter.Text = item["ADLDSGroupUserFilter"].ToString(); txtGrpFilter.Text = item["ADLDSGroupFilter"].ToString(); txtGrpScope.Text = item["ADLDSGroupScope"].ToString(); } } } } } catch (Exception) { } } } }
public static string GetWebAppUrl(SPWebApplication webApp) { return webApp.GetResponseUri(SPUrlZone.Default).AbsoluteUri; }
public static string GetWebAppUrl(SPWebApplication webApp) { return(webApp.GetResponseUri(SPUrlZone.Default).AbsoluteUri); }
/// <summary> /// Activates or deactivates the web application scoped feature. /// </summary> /// <param name="application">The application.</param> /// <param name="featureId">The feature id.</param> /// <param name="activate">if set to <c>true</c> [activate].</param> /// <param name="force">if set to <c>true</c> [force].</param> /// <param name="ignoreNonActive">if set to <c>true</c> [ignore non active].</param> /// <returns></returns> public SPFeature ActivateDeactivateFeatureAtWebApplication(SPWebApplication application, Guid featureId, bool activate, bool force, bool ignoreNonActive) { return(ActivateDeactivateFeature(application.Features, activate, featureId, application.GetResponseUri(SPUrlZone.Default).ToString(), force, ignoreNonActive)); }
/// <summary> /// Activates or deactivates the web application scoped feature. /// </summary> /// <param name="application">The application.</param> /// <param name="featureId">The feature id.</param> /// <param name="activate">if set to <c>true</c> [activate].</param> /// <param name="force">if set to <c>true</c> [force].</param> /// <param name="ignoreNonActive">if set to <c>true</c> [ignore non active].</param> /// <returns></returns> public SPFeature ActivateDeactivateFeatureAtWebApplication(SPWebApplication application, Guid featureId, bool activate, bool force, bool ignoreNonActive) { return ActivateDeactivateFeature(application.Features, activate, featureId, application.GetResponseUri(SPUrlZone.Default).ToString(), force, ignoreNonActive); }
public static void Create(SearchResultCollection users, string loginAttribute, SPWebApplication webApplication, string serverName, int portNumber, SPUrlZone zone) { foreach (SearchResult user in users) { DirectoryEntry de2 = user.GetDirectoryEntry(); SPSite site = null; try { site = new SPSite(WebApplication.GetResponseUri(zone).AbsoluteUri); SPIisSettings iisSettings = webApplication.GetIisSettingsWithFallback(zone); foreach (SPAuthenticationProvider provider in iisSettings.ClaimsAuthenticationProviders) { if (provider is SPFormsAuthenticationProvider) { SPFormsAuthenticationProvider formsProvider = provider as SPFormsAuthenticationProvider; SPServiceContext serviceContext = SPServiceContext.GetContext(site); UserProfileManager uPM = new UserProfileManager(serviceContext); SPSecurity.RunWithElevatedPrivileges(delegate() { if (de2.Properties[loginAttribute].Value != null) { if (!uPM.UserExists(ClaimsIdentifier + "|" + formsProvider.MembershipProvider + "|" + de2.Properties[loginAttribute].Value.ToString())) { Department = (de2.Properties[DepartmentAttrib].Value == null) ? String.Empty : de2.Properties[DepartmentAttrib].Value.ToString(); DistinguishedName = de2.Properties[DistinguishedNameAttrib].Value.ToString(); FirstName = (de2.Properties[FirstNameAttrib].Value == null) ? String.Empty : de2.Properties[FirstNameAttrib].Value.ToString(); LastName = (de2.Properties[LastNameAttrib].Value == null) ? String.Empty : de2.Properties[LastNameAttrib].Value.ToString(); Office = (de2.Properties[OfficeAttrib].Value == null) ? String.Empty : de2.Properties[OfficeAttrib].Value.ToString(); PreferredName = (de2.Properties[PreferredNameAttrib].Value == null) ? String.Empty : de2.Properties[PreferredNameAttrib].Value.ToString(); UserTitle = (de2.Properties[UserTitleAttrib].Value == null) ? String.Empty : de2.Properties[UserTitleAttrib].Value.ToString(); WebSite = (de2.Properties[WebSiteAttrib].Value == null) ? String.Empty : de2.Properties[WebSiteAttrib].Value.ToString(); WorkEmail = (de2.Properties[WorkEmailAttrib].Value == null) ? String.Empty : de2.Properties[WorkEmailAttrib].Value.ToString(); WorkPhone = (de2.Properties[WorkPhoneAttrib].Value == null) ? String.Empty : de2.Properties[WorkPhoneAttrib].Value.ToString(); UserProfile newProfile = uPM.CreateUserProfile(ClaimsIdentifier + "|" + formsProvider.MembershipProvider + "|" + de2.Properties[loginAttribute].Value.ToString(), PreferredName); newProfile[PropertyConstants.Department].Add(Department); newProfile[PropertyConstants.DistinguishedName].Add(DistinguishedName); newProfile[PropertyConstants.FirstName].Add(FirstName); newProfile[PropertyConstants.LastName].Add(LastName); newProfile[PropertyConstants.Office].Add(Office); newProfile[PropertyConstants.Title].Add(UserTitle); newProfile[PropertyConstants.WebSite].Add(WebSite); newProfile[PropertyConstants.WorkEmail].Add(WorkEmail); newProfile[PropertyConstants.WorkPhone].Add(WorkPhone); try { newProfile.Commit(); Logging.LogMessage(210, Logging.LogCategories.Profiles, TraceSeverity.Verbose, "Created profile " + DistinguishedName, new object[] { null }); } catch (Exception ex) { Logging.LogMessage(510, Logging.LogCategories.Profiles, TraceSeverity.Unexpected, "Failed to create profile " + DistinguishedName + " " + ex.Message, new object[] { null }); } } else if (uPM.UserExists(ClaimsIdentifier + "|" + formsProvider.MembershipProvider + "|" + de2.Properties[loginAttribute].Value.ToString())) { UserProfile updateProfile = uPM.GetUserProfile(ClaimsIdentifier + "|" + formsProvider.MembershipProvider + "|" + de2.Properties[loginAttribute].Value.ToString()); updateProfile[PropertyConstants.Department].Value = (de2.Properties[DepartmentAttrib].Value == null) ? String.Empty : de2.Properties[DepartmentAttrib].Value.ToString(); updateProfile[PropertyConstants.DistinguishedName].Value = de2.Properties[DistinguishedNameAttrib].Value.ToString(); updateProfile[PropertyConstants.FirstName].Value = (de2.Properties[FirstNameAttrib].Value == null) ? String.Empty : de2.Properties[FirstNameAttrib].Value.ToString(); updateProfile[PropertyConstants.LastName].Value = (de2.Properties[LastNameAttrib].Value == null) ? String.Empty : de2.Properties[LastNameAttrib].Value.ToString(); updateProfile[PropertyConstants.Office].Value = (de2.Properties[OfficeAttrib].Value == null) ? String.Empty : de2.Properties[OfficeAttrib].Value.ToString(); updateProfile[PropertyConstants.PreferredName].Value = (de2.Properties[PreferredNameAttrib].Value == null) ? String.Empty : de2.Properties[PreferredNameAttrib].Value.ToString(); updateProfile[PropertyConstants.Title].Value = (de2.Properties[UserTitleAttrib].Value == null) ? String.Empty : de2.Properties[UserTitleAttrib].Value.ToString(); updateProfile[PropertyConstants.WebSite].Value = (de2.Properties[WebSiteAttrib].Value == null) ? String.Empty : de2.Properties[WebSiteAttrib].Value.ToString(); updateProfile[PropertyConstants.WorkEmail].Value = (de2.Properties[WorkEmailAttrib].Value == null) ? String.Empty : de2.Properties[WorkEmailAttrib].Value.ToString(); updateProfile[PropertyConstants.WorkPhone].Value = (de2.Properties[WorkPhoneAttrib].Value == null) ? String.Empty : de2.Properties[WorkPhoneAttrib].Value.ToString(); try { updateProfile.Commit(); Logging.LogMessage(211, Logging.LogCategories.Profiles, TraceSeverity.Verbose, "Updated profile " + updateProfile[PropertyConstants.DistinguishedName].Value, new object[] { null }); } catch (Exception ex) { Logging.LogMessage(511, Logging.LogCategories.Profiles, TraceSeverity.Unexpected, "Failed to update profile " + updateProfile[PropertyConstants.DistinguishedName].Value + " " + ex.Message, new object[] { null }); } } } }); } } } catch (Exception ex) { Logging.LogMessage(502, Logging.LogCategories.Profiles, TraceSeverity.Unexpected, ex.Message, new object[] { null }); } finally { if (site != null) { site.Dispose(); } } } }
protected override void InternalProcessRecord() { bool test = false; ShouldProcessReason reason; if (!base.ShouldProcess(null, null, null, out reason)) { if (reason == ShouldProcessReason.WhatIf) { test = true; } } if (test) { Logger.Verbose = true; } Regex regex = null; string replaceString = null; if (!string.IsNullOrEmpty(RegexSearchString)) { regex = new Regex(RegexSearchString); replaceString = RegexReplaceString; } string pageName = null; SPFile page = null; try { if (Page != null) { page = Page.Read(); pageName = page.Name; } } catch { if (page != null) { page.Web.Dispose(); page.Web.Site.Dispose(); } throw; } try { if (WebApplication != null) { SPWebApplication webApp = WebApplication.Read(); Logger.Write("Progress: Begin processing web application '{0}'.", webApp.GetResponseUri(SPUrlZone.Default).ToString()); foreach (SPSite site in webApp.Sites) { Logger.Write("Progress: Begin processing site '{0}'.", site.ServerRelativeUrl); try { foreach (SPWeb web in site.AllWebs) { Logger.Write("Progress: Begin processing web '{0}'.", web.ServerRelativeUrl); try { PublishingWeb pubweb = PublishingWeb.GetPublishingWeb(web); Common.Pages.FixPublishingPagesPageLayoutUrl.FixPages(pubweb, pageName, GetPageLayout(pubweb, page), regex, replaceString, FixContact.IsPresent, test); } finally { Logger.Write("Progress: Finished processing web '{0}'.", web.ServerRelativeUrl); web.Dispose(); } } } finally { Logger.Write("Progress: Finished processing site '{0}'.", site.ServerRelativeUrl); site.Dispose(); } } Logger.Write("Progress: Finished processing web application '{0}'.", webApp.GetResponseUri(SPUrlZone.Default).ToString()); } else if (Site != null) { using (SPSite site = new SPSite(Site.SiteGuid)) { Logger.Write("Progress: Begin processing site '{0}'.", site.ServerRelativeUrl); foreach (SPWeb web in site.AllWebs) { Logger.Write("Progress: Begin processing web '{0}'.", web.ServerRelativeUrl); try { PublishingWeb pubweb = PublishingWeb.GetPublishingWeb(web); Common.Pages.FixPublishingPagesPageLayoutUrl.FixPages(pubweb, pageName, GetPageLayout(pubweb, page), regex, replaceString, FixContact.IsPresent, test); } finally { Logger.Write("Progress: Finished processing web '{0}'.", web.ServerRelativeUrl); web.Dispose(); } } Logger.Write("Progress: Finished processing site '{0}'.", site.ServerRelativeUrl); } } else if (Web != null) { using (SPWeb web = Web.Read()) { Logger.Write("Progress: Begin processing web '{0}'.", web.Url); PublishingWeb pubweb = PublishingWeb.GetPublishingWeb(web); Common.Pages.FixPublishingPagesPageLayoutUrl.FixPages(pubweb, pageName, GetPageLayout(pubweb, page), regex, replaceString, FixContact.IsPresent, test); Logger.Write("Progress: Finished processing web '{0}'.", web.Url); } } else if (Page != null) { try { PublishingWeb pubweb = PublishingWeb.GetPublishingWeb(page.Web); Common.Pages.FixPublishingPagesPageLayoutUrl.FixPages(pubweb, pageName, GetPageLayout(pubweb, page), regex, replaceString, FixContact.IsPresent, test); } finally { page.Web.Dispose(); page.Web.Site.Dispose(); } } } finally { if (page != null) { page.Web.Dispose(); page.Web.Site.Dispose(); } } }
protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { return; } if (_webApplication == null) { return; } var servers = SPFarm.Local.Servers; if (servers.Count == 1 && Debugger.IsAttached != true) { SPUtility.TransferToErrorPage("There is only one server in the farm. Please add additional servers to use this feature."); } PopulateGridView(); btnAdd.Attributes.Add("onClick", "SP.SOD.execute( 'sp.ui.dialog.js', 'NewCrawlTarget', '" + _webApplication.GetResponseUri(SPUrlZone.Default).AbsoluteUri + "' ); return false;"); }
protected override void InternalProcessRecord() { bool test = false; ShouldProcessReason reason; if (!base.ShouldProcess(null, null, null, out reason)) { if (reason == ShouldProcessReason.WhatIf) { test = true; } } if (test) { Logger.Verbose = true; } bool force = Force; bool haltOnError = HaltOnError.IsPresent; switch (ParameterSetName) { case "SPFile": SPFile file = File.Read(); try { if (!file.Exists) { throw new FileNotFoundException(string.Format("File '{0}' not found.", File.FileUrl), File.FileUrl); } Common.Pages.ReGhostFile.Reghost(file.Web.Site, file.Web, file, force, haltOnError); } finally { if (file != null) { file.Web.Dispose(); file.Web.Site.Dispose(); } } break; case "SPList": SPList list = null; SPWeb web1 = null; try { if (Web != null) { web1 = Web.Read(); if (web1 == null) { throw new FileNotFoundException(string.Format("The specified site could not be found. {0}", Web.WebUrl), Web.WebUrl); } list = List.Read(web1); } else { list = List.Read(); } if (list == null) { throw new FileNotFoundException(string.Format("The specified list could not be found. {0}", List.ListUrl), List.ListUrl); } Common.Pages.ReGhostFile.ReghostFilesInList(list.ParentWeb.Site, list.ParentWeb, list, force, haltOnError); } finally { if (web1 != null) { web1.Dispose(); web1.Site.Dispose(); } } break; case "SPWeb": bool recurseWebs = Recurse.IsPresent; SPWeb web2 = Web.Read(); if (web2 == null) { throw new FileNotFoundException(string.Format("The specified site could not be found. {0}", Web.WebUrl), Web.WebUrl); } try { Common.Pages.ReGhostFile.ReghostFilesInWeb(web2.Site, web2, recurseWebs, force, haltOnError); } finally { if (web2 != null) { web2.Dispose(); web2.Site.Dispose(); } } break; case "SPSite": SPSite site1 = Site.Read(); if (site1 == null) { throw new FileNotFoundException(string.Format("The specified site collection could not be found. {0}", Site.SiteUrl), Site.SiteUrl); } try { Common.Pages.ReGhostFile.ReghostFilesInSite(site1, force, haltOnError); } finally { if (site1 != null) { site1.Dispose(); } } break; case "SPWebApplication": SPWebApplication webApp = WebApplication.Read(); if (webApp == null) { throw new FileNotFoundException("The specified web application could not be found."); } Logger.Write("Progress: Analyzing files in web application '{0}'.", webApp.GetResponseUri(SPUrlZone.Default).ToString()); foreach (SPSite site2 in webApp.Sites) { try { Common.Pages.ReGhostFile.ReghostFilesInSite(site2, force, haltOnError); } finally { site2.Dispose(); } } break; } }
protected void FillItems(SPWebApplication selectedWebApp, SPUrlZone zone) { using (var siteCollection = new SPSite(SPContext.Current.Site.ID)) { using (var site = siteCollection.OpenWeb()) { try { var list = site.Lists.TryGetList("Nauplius.ADLDS.FBA - WebApplicationSettings"); if (list != null) { if (selectedWebApp != null) { string webAppUrl = selectedWebApp.GetResponseUri(zone).AbsoluteUri; var items = list.Items; foreach (SPListItem item in items) { if (item["WebApplicationUrl"].ToString() == webAppUrl) { try { ddlZonePicker.SelectedValue = item["WebApplicationZone"].ToString(); } catch (Exception) { //In case someone manually modified the SPUrlZone in the list ddlZonePicker.SelectedValue = "Default"; } txtMemProv.Text = (item["WebApplicationMembershipProvider"] == null) ? String.Empty : item["WebApplicationMembershipProvider"].ToString(); txtRoleProv.Text = (item["WebApplicationRoleProvider"] == null) ? String.Empty : item["WebApplicationRoleProvider"].ToString(); txtCustomUrl.Text = (item["CustomUrl"] == null) ? String.Empty : item["CustomUrl"].ToString(); //AD LDS Server tBSN.Text = (item["ADLDSServer"] == null) ? String.Empty : item["ADLDSServer"].ToString(); tBPrtNo.Text = (item["ADLDSPort"] == null) ? String.Empty : item["ADLDSPort"].ToString(); cBUseSSL.Checked = (bool)item["ADLDSUseSSL"]; //User tBLoginAttrib.Text = (item["ADLDSLoginAttrib"] == null) ? String.Empty : item["ADLDSLoginAttrib"].ToString(); txtUsrDNAttrib.Text = (item["ADLDSUserDNAttrib"] == null) ? string.Empty : item["ADLDSUserDNAttrib"].ToString(); txtUsrContainer.Text = (item["ADLDSUserContainer"] == null) ? string.Empty : item["ADLDSUserContainer"].ToString(); txtUsrObjClass.Text = (item["ADLDSUserObjectClass"] == null) ? string.Empty : item["ADLDSUserObjectClass"].ToString(); txtUsrFilter.Text = (item["ADLDSUserFilter"] == null) ? string.Empty : item["ADLDSUserFilter"].ToString(); txtUsrScope.Text = (item["ADLDSUserScope"] == null) ? string.Empty : item["ADLDSUserScope"].ToString(); txtUsrOtherAttribs.Text = (item["ADLDSUserOtherReqAttrib"] == null) ? string.Empty : item["ADLDSUserOtherReqAttrib"].ToString(); //Group txtGrpContainer.Text = (item["ADLDSGroupContainer"] == null) ? string.Empty : item["ADLDSGroupContainer"].ToString(); txtGrpNameAttrib.Text = (item["ADLDSGroupNameAttrib"] == null) ? string.Empty : item["ADLDSGroupNameAttrib"].ToString(); txtGrpAltSearchAttrib.Text = (item["ADLDSGroupNameAltSearchAttrib"] == null) ? string.Empty : item["ADLDSGroupNameAltSearchAttrib"] .ToString(); txtGrpMemAttrib.Text = (item["ADLDSGroupMemAttrib"] == null) ? string.Empty : item["ADLDSGroupMemAttrib"].ToString(); txtGrpDNAttrib.Text = (item["ADLDSGroupDNAttrib"] == null) ? string.Empty : item["ADLDSGroupDNAttrib"].ToString(); txtGrpUsrFilter.Text = (item["ADLDSGroupUserFilter"] == null) ? string.Empty : item["ADLDSGroupUserFilter"].ToString(); txtGrpFilter.Text = (item["ADLDSGroupFilter"] == null) ? string.Empty : item["ADLDSGroupFilter"].ToString(); txtGrpScope.Text = (item["ADLDSGroupScope"] == null) ? string.Empty : item["ADLDSGroupScope"].ToString(); txtGrpUsrDnAttrib.Text = (item["ADLDSGroupUserDNAttrib"] == null) ? string.Empty : item["ADLDSGroupUserDNAttrib"].ToString(); } else { txtMemProv.Text = string.Empty; txtRoleProv.Text = string.Empty; txtCustomUrl.Text = string.Empty; tBSN.Text = string.Empty; tBPrtNo.Text = string.Empty; cBUseSSL.Checked = false; tBLoginAttrib.Text = string.Empty; txtUsrDNAttrib.Text = "distinguishedName"; txtUsrContainer.Text = string.Empty; txtUsrObjClass.Text = "user"; txtUsrFilter.Text = "(ObjectClass=*)"; txtUsrScope.Text = "Subtree"; txtUsrOtherAttribs.Text = "sn,givenname,cn"; txtGrpContainer.Text = string.Empty; txtGrpNameAttrib.Text = "cn"; txtGrpAltSearchAttrib.Text = "cn"; txtGrpMemAttrib.Text = "member"; txtGrpDNAttrib.Text = "distinguishedName"; txtGrpUsrFilter.Text = @"&(objectCategory=Group)(objectClass=group)"; txtGrpScope.Text = "Subtree"; txtGrpUsrDnAttrib.Text = "distinguishedName"; } } } } } catch (SPException) { } } } }
/// <summary> /// Feature Search /// </summary> private void fm_search_Click(object sender, EventArgs e) { featuresToDisplay.Clear(); fm_grid.Rows.Clear(); featuresDisplayed = 0; SPWebApplication webApp = GetSelectedWebApplication(); if (webApp == null) { return; } try { if (fm_search_textbox.Text == "<GUID / Feature Name>") { fm_search_textbox.Clear(); } progressBar1.Value = 0; collectionLabel.Text = "Feature Occurences: Loading...Please Wait"; this.Invalidate(); this.Update(); // Farm Features if (fm_scope_Farm.Checked) { SPWebServiceCollection webServices = new SPWebServiceCollection(SPFarm.Local); foreach (SPWebService webService in webServices) { foreach (SPFeature feature in webService.Features) { AddFeature(fm_search_textbox.Text, feature, FeatureScope.Farm, "N/A", fm_type_Custom.Checked); } } } // Web Application Features if (fm_scope_WebApplication.Checked) { foreach (SPFeature feature in webApp.Features) { AddFeature(fm_search_textbox.Text, feature, FeatureScope.WebApplication, webApp.GetResponseUri(SPUrlZone.Default).AbsoluteUri, fm_type_Custom.Checked); } } foreach (SPSite site in webApp.Sites) { // Site Collection features.. if (fm_scope_SiteCollection.Checked) { foreach (SPFeature feature in site.Features) { AddFeature(fm_search_textbox.Text, feature, FeatureScope.SiteCollection, site.Url, fm_type_Custom.Checked); } } // Site features.. if (fm_scope_Site.Checked) { foreach (SPWeb web in site.AllWebs) { foreach (SPFeature feature in web.Features) { AddFeature(fm_search_textbox.Text, feature, FeatureScope.Site, web.Url, fm_type_Custom.Checked); } web.Dispose(); } } site.Dispose(); } DisplayFeatures(); collectionLabel.Text = "Feature Occurences: " + (fm_grid.Rows.Count - 1); progressBar1.Value = 0; } catch (Exception ex) { if (DEBUG_MODE.Checked) { MessageBox.Show(ex.ToString()); } } }