示例#1
0
        /// <summary>
        /// DropClaimProvider method implmentation
        /// </summary>
        private void DropClaimProvider(ProxyClaimsProviderParameters prm)
        {
            SPClaimProviderManager    cpm = SPClaimProviderManager.Local;
            SPClaimProviderDefinition ppv = cpm.GetClaimProvider(prm.ClaimProviderName);

            if (ppv == null)
            {
                return;
            }
            if (ppv.TypeName.ToLower().Equals("sharepoint.identityservice.claimsprovider.identityserviceclaimsprovider"))
            {
                try
                {
                    cpm.DeleteClaimProvider(ppv);
                }
                finally
                {
                    cpm.Update(true);
                }

                if (prm.ClaimProviderMode == ProxyClaimsMode.Windows)
                {
                    ReCreateWindowsClaimProvider(prm);
                }

                /*  else
                 * {
                 *    ReCreateTrustedClaimProvider(prm);
                 * } it seem that it is not needed */
            }
        }
示例#2
0
        /// <summary>
        /// ReCreateWindowsClaimProvider method implementation
        /// </summary>
        private void ReCreateWindowsClaimProvider(ProxyClaimsProviderParameters prm)
        {
            SPClaimProviderManager cpm = SPClaimProviderManager.Local;

            try
            {
                SPClaimProviderDefinition ppva = new SPClaimProviderDefinition("AD", "Windows Claim Provider", "Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c", "Microsoft.SharePoint.Administration.Claims.SPActiveDirectoryClaimProvider");
                ppva.IsEnabled = true;
                ppva.IsVisible = true;
                cpm.AddClaimProvider(ppva);
            }
            finally
            {
                cpm.Update(true);
            }
        }
        /// <summary>
        /// SelectedTrustedIssuerChanged method implementation
        /// </summary>
        public void OnSelectedTrustedIssuerChanged(object sender, EventArgs e)
        {
            SPClaimProviderDefinition def = Utilities.GetClaimProvider(this.InputClaimProviderDropBox.SelectedValue);

            if (def != null)
            {
                this.txtInputFormDisplayClaimName.Text = string.Empty;
                this.txtInputFormTextClaimDesc.Text    = def.Description;
                this.visibilityCB.Checked = def.IsUsedByDefault;
            }
            else
            {
                this.txtInputFormDisplayClaimName.Text = string.Empty;
                this.txtInputFormTextClaimDesc.Text    = this.InputClaimProviderDropBox.SelectedValue;
                this.visibilityCB.Checked = false;
            }
        }
        /// <summary>
        /// OnLoad event override
        /// </summary>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!Page.IsPostBack)
            {
                Page.DataBind();
                if (ServiceApplicationId != Guid.Empty && ServiceApplication == null)
                {
                    throw new SPException("Unable to locate service application");
                }
                #region Update an existing Service Application
                if (ServiceApplicationId != Guid.Empty)
                {
                    // Check for permissions to access this page
                    if (!SPFarm.Local.CurrentUserIsAdministrator())
                    {
                        if (!ServiceApplication.CheckAdministrationAccess(SPCentralAdministrationRights.FullControl))
                        {
                            SPUtility.HandleAccessDenied(new UnauthorizedAccessException("You are not authorized to access this page."));
                        }
                    }

                    DialogMaster.OkButton.Text         = "OK";
                    DialogMaster.OkButton.Enabled      = true;
                    txtServiceApplicationName.ReadOnly = true;
                    txtServiceApplicationName.Enabled  = false;

                    _trustedproviderslist = Utilities.GetClaimProviderCandidates(false);
                    foreach (ClaimProviderDefinition current in TrustedProviderList)
                    {
                        InputClaimProviderDropBox.Items.Add(new ListItem(current.DisplayName, current.TrustedTokenIssuer));
                    }
                    //  InputClaimProviderDropBox.SelectedIndexChanged += OnSelectedTrustedIssuerChanged;

                    if (ServiceApplication.Database != null)
                    {
                        DatabaseSection.ConnectionString = ServiceApplication.Database.ConnectString();
                        if (ServiceApplication.Database.FailoverServer != null)
                        {
                            DatabaseSection.IncludeFailoverDatabaseServer = true;
                            DatabaseSection.FailoverDatabaseServer        = ServiceApplication.Database.FailoverServer.Name;
                        }
                        if (!string.IsNullOrEmpty(ServiceApplication.Database.Username))
                        {
                            DatabaseSection.UseWindowsAuthentication = false;
                            DatabaseSection.DatabaseUserName         = ServiceApplication.Database.Username;
                        }
                    }
                    ApplicationPoolSection.SetSelectedApplicationPool(ServiceApplication.ApplicationPool);
                    txtServiceApplicationName.Text = ServiceApplication.Name;
                    ProxyClaimsProviderParameters prm = null;
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        prm = ServiceApplication.FillClaimsProviderParameters();
                    });
                    try
                    {
                        if (prm != null)
                        {
                            if (((!string.IsNullOrEmpty(prm.TrustedLoginProviderName)) && (!string.IsNullOrEmpty(prm.ClaimProviderName))))
                            {   // Update of an existing Service application (Windows Or Trusted)
                                SPClaimProviderDefinition def = Utilities.GetClaimProvider(prm.ClaimProviderName);
                                this.txtInputFormDisplayClaimName.Text = prm.ClaimDisplayName;
                                this.InitialTrustedProviderName        = prm.TrustedLoginProviderName;
                                if (def != null)
                                {
                                    this.txtInputFormTextClaimDesc.Text = def.Description;
                                    this.visibilityCB.Checked           = def.IsUsedByDefault;
                                    //  this.InitialClaimProviderName = def.DisplayName;
                                    this.InputClaimProviderDropBox.SelectedValue = prm.TrustedLoginProviderName;
                                }
                                else
                                {
                                    this.InputClaimProviderDropBox.SelectedValue = "AD";
                                }
                                this.InputClaimProviderDropBox.Enabled = false;
                                this.IsNewClaimProvider = false;
                            }
                            else
                            {
                                throw new Exception("Cannot find essential parameters (TrustedLoginProviderName, ClaimProviderName) !");
                            }
                        }
                        else
                        {
                            throw new Exception("Cannot find essential parameters (TrustedLoginProviderName, ClaimProviderName) !");
                        }
                    }
                    catch (Exception ex)
                    {
                        RedirectToErrorPage(String.Format("Failed to create service applicaton {0} \n Execption : {1}", ServiceApplication.Name, ex.Message));
                    }
                }
                #endregion
                #region Create a New Service Application
                else // Creation of New Service Application
                {
                    // Check for permissions to access this page
                    if (!SPFarm.Local.CurrentUserIsAdministrator())
                    {
                        if (!ServiceApplication.CheckAdministrationAccess(SPCentralAdministrationRights.FullControl))
                        {
                            SPUtility.HandleAccessDenied(new UnauthorizedAccessException("You are not authorized to access this page."));
                        }
                    }

                    _trustedproviderslist = Utilities.GetClaimProviderCandidates(true);
                    InputClaimProviderDropBox.Items.Add(new ListItem("--Select--", "NONE"));
                    foreach (ClaimProviderDefinition current in TrustedProviderList)
                    {
                        InputClaimProviderDropBox.Items.Add(new ListItem(current.DisplayName, current.TrustedTokenIssuer));
                    }
                    //  InputClaimProviderDropBox.SelectedIndexChanged += OnSelectedTrustedIssuerChanged;

                    DialogMaster.OkButton.Text             = "OK";
                    DialogMaster.OkButton.Enabled          = true;
                    txtServiceApplicationName.ReadOnly     = false;
                    txtServiceApplicationName.Enabled      = true;
                    DatabaseSection.DatabaseServer         = SPWebService.ContentService.DefaultDatabaseInstance.NormalizedDataSource;
                    DatabaseSection.DatabaseName           = "IdentityServiceDatabase_" + Guid.NewGuid().ToString("D");
                    txtServiceApplicationName.Text         = litServiceApplicationTitle.Text + " (Name)";
                    litServiceApplicationTitle.Text        = "Créer " + litServiceApplicationTitle.Text;
                    this.txtInputFormDisplayClaimName.Text = "Windows";
                    this.txtInputFormTextClaimDesc.Text    = GetUIString("SVCTRUSTEDLABELAD");
                    this.visibilityCB.Checked = false;
                    //  this.InitialClaimProviderName = string.Empty;
                    this.InitialTrustedProviderName        = string.Empty;
                    this.InputClaimProviderDropBox.Enabled = true;
                    this.IsNewClaimProvider = true;
                    this.InputClaimProviderDropBox.SelectedValue = "AD";
                }
                #endregion
            }
        }