/// <summary>
 /// CheckReadAccess method implementation
 /// </summary>
 internal bool CheckReadAccess()
 {
     return(ServiceApplication.CheckAdministrationAccess(SPCentralAdministrationRights.Read) || ServiceApplication.CheckAdministrationAccess(SPCentralAdministrationRights.FullControl));
 }
Exemplo n.º 2
0
        /// <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
            }
        }
 /// <summary>
 /// CheckModifyAccess method implementation
 /// </summary>
 internal bool CheckModifyAccess()
 {
     return(ServiceApplication.CheckAdministrationAccess(IdentityServiceCentralAdministrationRights.Write) || ServiceApplication.CheckAdministrationAccess(SPCentralAdministrationRights.FullControl));
 }