6

The challenge I am trying to solve is to create dynamic roles for an SXA site, knowing that my client will be creating multiple SXA sites over time, and thinking that possibly the best way to accomplish this is to tap into the Powershell scripts that are being fired when the "Setup Security" option is selected under a given site. If anyone has a perspective about solving this in general, or if they could direct me to where I can find those Powershell scripts to modify them, I would be very appreciative!

5

David, you've come to the right place! When we rolled out an SXA site (v 1.3) there was no supplied examples to manage security.

SPE provides some simple commands to do what you are asking.

Script Samples

Example: Create a new editor user for your domain and add to an existing domain role. $editor = New-User -Identity "company\Editor-Eddie" -Password "Sitecore!" -Email "editor-eddie@company.demo" -FullName "Editor Eddie" -Enabled Add-RoleMember -Identity "company\editor" -Members $editor

Example: Assign security to the Virtual Data Item template so that everyone has access to create local page data. A helper function was used because you may have to do this for several roles on several items.

function New-AccessRuleList {
    [CmdletBinding()]
    [OutputType("System.Collections.Generic.List[Sitecore.Security.AccessControl.AccessRule]")]
    param(
        [string]$Identity,
        [string[]]$AccessRule,
        [Sitecore.Security.AccessControl.PropagationType]$PropagationType,
        [Sitecore.Security.AccessControl.SecurityPermission]$SecurityPermission
    )

    $list = New-Object "System.Collections.Generic.List[Sitecore.Security.AccessControl.AccessRule]"
    foreach($rule in $accessrule) {
        $list.Add((New-ItemAcl -Identity $Identity -AccessRight $rule -PropagationType $PropagationType -SecurityPermission $SecurityPermission))
    }
    @(,$list)
}

$allowItemProps = @{
    PropagationType = [Sitecore.Security.AccessControl.PropagationType]::Entity
    SecurityPermission = [Sitecore.Security.AccessControl.SecurityPermission]::AllowAccess
}

function Setup-SystemEveryoneSecurity {
    Write-Host "[System Settings Security]" -Foreground Yellow
    $realEveryone = "\Everyone"

    $virtualDataItem = Get-Item -Path "master:" -ID "{9700DC24-8969-4638-ACC3-34D54335829E}"
    $accessRules = New-Object Sitecore.Security.AccessControl.AccessRuleCollection
    $accessRules.AddRange((New-AccessRuleList -Identity $realEveryone -AccessRule item:create @allowItemProps))
    $virtualDataItem | Add-ItemAcl -AccessRules $accessRules
}

Documentation

Start with the book here and work your way to viewing all of the security commands.

The module also comes with some examples for building dialogs. Check out the Getting Started module for examples on the use of Read-Variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.