Domanda

Ho nella mia applicazione di SharePoint una fonte esterna a cui è necessario accedere da 2 parti della mia applicazione

La prima parte è una pagina, in cui gli utenti possono cercare su un modulo, i dati esterni. La seconda parte è un lavoro timer che sincronizza i dati esterni con alcuni siti di SharePoint.

Per fare ciò, ho aggiunto il seguente codice nel costruttore di connessione framework entity.

Funziona perfettamente per la pagina, ma non funziona per il lavoro del timer.

Come tutti sanno che la pagina dell'app viene eseguita nell'ambito del contesto dell'account Poool dell'applicazione, ho aggiunto tale account nell'amministratore di servizio Secure Store e anche nell'applicazione di destinazione.

Tuttavia, per il servizio timer che ho controllato su Servizi.MSC e viene eseguito nell'ambito dell'account azienda agricola, che dovrebbe avere già le autorizzazioni.

Controllando alcuni post, ho letto che il servizio timer viene eseguito in SharePoint \ System, ma questo non è un account che posso concedere l'accesso a, dice che l'account non esiste.

The specified user or domain group was not found.  or Claim is null on the resolved pickerentity.
.

Devo essere in grado di visualizzare il mio lavoro Timer che i dati.

/// <summary>
        /// Gets the database server and database name from the property bag
        /// </summary>
        /// <returns></returns>
        public static string GetDMSConnectionStringFromSecureStore()
        {
            var entityBuilder = new EntityConnectionStringBuilder();
            try
            {
                const string providerName = "System.Data.SqlClient";
                var dic = GetCredentialsFromSecureApp(Constants.SecureStore.ApplicationId);
                var serverName = string.Empty;
                var databaseName = string.Empty;
                var databaseUserName = string.Empty;
                var databasePassword = string.Empty;

                foreach (var item in dic)
                {
                    if (item.Key == Constants.SecureStore.DatabaseServerField)
                    {
                        serverName = item.Value;
                    }
                    if (item.Key == Constants.SecureStore.DatabaseNameField)
                    {
                        databaseName = item.Value;
                    }
                    if (item.Key == Constants.SecureStore.UserNameField)
                    {
                        databaseUserName = item.Value;
                    }
                    if (item.Key == Constants.SecureStore.PasswordField)
                    {
                        databasePassword = item.Value;
                    }
                }

                // Initialize the connection string builder for the underlying provider.
                var sqlBuilder = new SqlConnectionStringBuilder
                {
                    DataSource = serverName,
                    InitialCatalog = databaseName,
                    UserID = databaseUserName,
                    Password = databasePassword
                };

                // Build the SqlConnection connection string.
                var providerString = sqlBuilder.ToString();

                // Initialize the EntityConnectionStringBuilder.
                entityBuilder.Provider = providerName;
                entityBuilder.ProviderConnectionString = providerString;
                entityBuilder.Metadata = @"res://*/DMSModel.csdl|res://*/DMSModel.ssdl|res://*/DMSModel.msl";
            }
            catch (Exception ex)
            {
                LoggingService.LogError(LoggingCategory.Security, ex);
            }

            return entityBuilder.ToString();
        }

        private static SecureString CreateSecureString(string unsecureString)
        {
            var secureString = new SecureString();
            foreach (var c in unsecureString/*.ToCharArray()*/)
            {
                secureString.AppendChar(c);
            }
            return secureString;
        }

        public static SPSite GetCentralAdminSite()
        {
            var adminWebApp = SPAdministrationWebApplication.Local;
            if (adminWebApp == null)
            {
                throw new InvalidProgramException("Unable to get the admin web app");
            }

            SPSite adminSite;
            var adminSiteUri = adminWebApp.GetResponseUri(SPUrlZone.Default);
            if (adminSiteUri != null)
            {
                adminSite = adminWebApp.Sites[adminSiteUri.AbsoluteUri];
            }
            else
            {
                throw new InvalidProgramException("Unable to get Central Admin Site.");
            }

            return adminSite;
        }

        private static string GetStringFromSecureString(SecureString secStr)
        {
            if (secStr != null)
            {
                var pPlainText = IntPtr.Zero;
                try
                {
                    pPlainText = Marshal.SecureStringToBSTR(secStr);
                    return Marshal.PtrToStringBSTR(pPlainText);
                }
                finally
                {
                    if (pPlainText != IntPtr.Zero)
                    {
                        Marshal.FreeBSTR(pPlainText);
                    }
                }
            }

            return null;
        }
.

È stato utile?

Soluzione

The SharePoint System Account is the farm account. A quick way to identify this is in Central Admin. Goto Security > Configure Service Accounts. Select Farm Account. It will display which account is being used. Ensure that account has the appropriate permissions to the secure store entry.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top