{"id":511,"date":"2012-03-20T09:00:26","date_gmt":"2012-03-20T08:00:26","guid":{"rendered":"http:\/\/blog.repsaj.nl\/?p=511"},"modified":"2013-04-18T18:29:22","modified_gmt":"2013-04-18T17:29:22","slug":"sp2010-creating-secure-store-target-applications-in-a-partitioned-service-app","status":"publish","type":"post","link":"http:\/\/blog.repsaj.nl\/index.php\/2012\/03\/sp2010-creating-secure-store-target-applications-in-a-partitioned-service-app\/","title":{"rendered":"SP2010: Creating Secure Store Target Applications in a partitioned service app"},"content":{"rendered":"<p>For our multitenant (partitioned) environment, I wanted to use the Secure Store Service Application to store credentials for a database. To be specific; I wanted those credentials to be available for BCS to gain access to the database.<\/p>\n<p>When you provision your Secure Store Service Application with the -Partitioned flag in Powershell, some things change. The biggest notable difference if the service application management page which now states:<\/p>\n<p>&#8220;This Secure Store Service Application is partitioned. Unable to display Secure Store Target Applications.&#8221;<\/p>\n<p>All options you would normally use to manage the application are greyed out, and that&#8217;s kind of it. No way to create a new target application whatsoever. Ok, so what now? Well, it&#8217;s Powershell to the rescue again! I&#8217;ll explain which steps to take to add a new target application for your tenant.<\/p>\n<p><strong>1. Setup some variables for easy use<\/strong><\/p>\n<p>Just to get started, we&#8217;ll create some variables which are used in the script. Change these to match your own preferences.<\/p>\n<p><code><br \/>\n$contextUrl = \"http:\/\/www.site.com\"<br \/>\n$ssta_name = \"AppName\"<br \/>\n$ssta_friendlyName = \"Friendly (display) app name\"<br \/>\n$ssta_contactEmail = \"contact@mail.com\"<br \/>\n$ssa_owner = \"CONTOSO\\sharepointadmin\"<br \/>\n$db_userName = \"CONTOSO\\dbuser\"<br \/>\n$db_password = \"p@ssw0rd1\"<br \/>\n<\/code><\/p>\n<p><strong>2. Create the Secure Store\u00a0Target Application<\/strong><br \/>\nThis is easy\u00a0enough, create a new object which holds the new target application. You will use this later on to create the actual application.<\/p>\n<p><code><br \/>\n$ssta = New-SPSecureStoreTargetApplication -Name $ssta_name -FriendlyName $ssta_friendlyName -ContactEmail $ssta_contactEmail -ApplicationType Group<br \/>\n<\/code><\/p>\n<p>Note that this creates a target application of type Group. If you need something else, change or parameterize the call.<\/p>\n<p><strong>3. Create the fields used in the application<\/strong><br \/>\nIn this example I configure two fields: username and password. In other cases you might need more, so extend when needed. Also notice that there are multiple types of fields you can create. I chose Windows to gain access to a SQL database in this example.<\/p>\n<p><code><br \/>\n$usernameField = New-SPSecureStoreApplicationField -name \"Username\" -Type WindowsUserName -Masked:$false<br \/>\n$passwordField = New-SPSecureStoreApplicationField -name \"Password\" -Type WindowsPassword -Masked:$true<br \/>\n$fields = $usernameField,$passwordField<br \/>\n<\/code><\/p>\n<p><strong>4. Create claim objects for principals<\/strong><br \/>\nProvide two types of credentials: the administrators of the Target Application (who can manage the credentials) and the owners of the credentials (which users may access them)<\/p>\n<p><code><br \/>\n$adminClaims = New-SPClaimsPrincipal -Identity $ssa_owner -IdentityType 1<br \/>\n$ownerClaims = New-SPClaimsPrincipal -EncodedClaim \"c:0(.s|true\"<br \/>\n<\/code><\/p>\n<p>The second line by the way, is the way to provide access to all of your users.<\/p>\n<p><strong>5. Create the secure store application<\/strong><br \/>\nNext we&#8217;ll actually create the application in the secure store, using the target application object, the fields and credentials setup earlier.<\/p>\n<p><code><br \/>\nNew-SPSecureStoreApplication -ServiceContext $contextUrl -TargetApplication $ssta -Fields $fields -Administrator $adminClaims -CredentialsOwnerGroup $ownerClaims<br \/>\n$ssa = Get-SPSecureStoreApplication -ServiceContext $contextUrl -Name $ssta.Name<br \/>\n<\/code><\/p>\n<p><strong>6. Add the actual application credentials<\/strong><br \/>\nNow we&#8217;ve got the application setup, we need to provide it with the credentials for our remote system (database or others).<\/p>\n<p><code><br \/>\n$db_secUser = ConvertTo-SecureString $db_userName -AsPlainText -Force<br \/>\n$db_secPass = ConvertTo-SecureString $db_password -AsPlainText -Force<br \/>\n$credentialValues = $db_secUser,$db_secPass<br \/>\nUpdate-SPSecureStoreGroupCredentialMapping -Identity $ssa -Values $credentialValues<br \/>\n<\/code><\/p>\n<p>That&#8217;s it! Now you&#8217;ve added a new application in your Secure Store Service which holds credentials and can be used by users of your SharePoint environment to gain access without having to worry about credentials.<\/p>\n<p>Here&#8217;s the script completely:<\/p>\n<p><code><br \/>\n$contextUrl = \"http:\/\/www.site.com\"<br \/>\n$ssta_name = \"AppName\"<br \/>\n$ssta_friendlyName = \"Friendly (display) app name\"<br \/>\n$ssta_contactEmail = \"contact@mail.com\"<br \/>\n$ssa_owner = \"CONTOSO\\sharepointadmin\"<br \/>\n$db_userName = \"CONTOSO\\dbuser\"<br \/>\n$db_password = \"p@ssw0rd1\"<\/code><\/p>\n<p><code><br \/>\n# Create a new Secure Store Target Application object<br \/>\n$ssta = New-SPSecureStoreTargetApplication -Name $ssta_name -FriendlyName $ssta_friendlyName -ContactEmail $ssta_contactEmail -ApplicationType Group<\/code><\/p>\n<p><code># Create the fields for username and password<br \/>\n$usernameField = New-SPSecureStoreApplicationField -name \"Username\" -Type WindowsUserName -Masked:$false<br \/>\n$passwordField = New-SPSecureStoreApplicationField -name \"Password\" -Type WindowsPassword -Masked:$true<br \/>\n$fields = $usernameField,$passwordField<\/code><\/p>\n<p><code># Create the claim object for the administrators of the application<br \/>\n$adminClaims = New-SPClaimsPrincipal -Identity $ssa_owner -IdentityType 1<br \/>\n$ownerClaims = New-SPClaimsPrincipal -EncodedClaim \"c:0(.s|true\"<\/code><\/p>\n<p><code># Create the secure store application and retrieve it afterwards<br \/>\nNew-SPSecureStoreApplication -ServiceContext $contextUrl -TargetApplication $ssta -Fields $fields -Administrator $adminClaims -CredentialsOwnerGroup $ownerClaims<br \/>\n$ssa = Get-SPSecureStoreApplication -ServiceContext $contextUrl -Name $ssta.Name<\/code><\/p>\n<p><code># Create the credentialset (username, password) for the DB<br \/>\n$db_secUser = ConvertTo-SecureString $db_userName -AsPlainText -Force<br \/>\n$db_secPass = ConvertTo-SecureString $db_password -AsPlainText -Force<br \/>\n$credentialValues = $db_secUser,$db_secPass<\/code><\/p>\n<p><code># Update the credentialmapping for the application<br \/>\nUpdate-SPSecureStoreGroupCredentialMapping -Identity $ssa -Values $credentialValues<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>For our multitenant (partitioned) environment, I wanted to use the Secure Store Service Application to store credentials for a database. To be specific; I wanted those credentials to be available for BCS to gain access to the database. When you provision your Secure Store Service Application with the -Partitioned flag in Powershell, some things change.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[34],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3KFR1-8f","_links":{"self":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/posts\/511"}],"collection":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/comments?post=511"}],"version-history":[{"count":0,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/posts\/511\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/media?parent=511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/categories?post=511"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/tags?post=511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}