Last active
December 21, 2017 04:43
-
-
Save Chirishman/91870e9740993583576dfbcb5d21c95f to your computer and use it in GitHub Desktop.
Test dashboard - Auth with LM or AD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-ADGroupMembership { | |
Param( | |
[Parameter( | |
Position = 0, | |
Mandatory = $true, | |
ValueFromPipelineByPropertyName = $true | |
)] | |
[Alias('UserName','UN')] | |
[String] | |
$User | |
) | |
Add-Type -AssemblyName System.DirectoryServices.AccountManagement | |
$AuthLookup = @{ | |
$true = 'machine' | |
$false = 'domain' | |
} | |
$DS = [System.DirectoryServices.AccountManagement.PrincipalContext]::new($AuthLookup[($env:USERDOMAIN -eq $env:COMPUTERNAME)]) | |
$UserObject = [System.DirectoryServices.AccountManagement.UserPrincipal]::FindByIdentity($DS, $User) | |
$Groups = $UserObject.GetAuthorizationGroups() | |
$Groups | select -ExpandProperty Name | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Test-ADCredential { | |
Param( | |
[Parameter( | |
Position=0, | |
Mandatory=$true, | |
ValueFromPipeline = $true)] | |
[pscredential]$Credential | |
) | |
Add-Type -AssemblyName System.DirectoryServices.AccountManagement | |
$AuthLookup = @{ | |
$true = 'machine' | |
$false = 'domain' | |
} | |
$DS = [System.DirectoryServices.AccountManagement.PrincipalContext]::new($AuthLookup[($env:USERDOMAIN -eq $env:COMPUTERNAME)]) | |
$Credential.GetNetworkCredential() | % { | |
$DS.ValidateCredentials($_.UserName, $_.Password) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Test-ADGroupMembership { | |
Param( | |
[Parameter( | |
Position = 0, | |
Mandatory = $true, | |
ValueFromPipelineByPropertyName = $true | |
)] | |
[Alias('UserName','UN')] | |
[String] | |
$User, | |
[Parameter( | |
Position=1, | |
Mandatory=$true, | |
ValueFromPipelineByPropertyName = $true | |
)] | |
[string]$TargetGroup | |
) | |
$Groups = Get-ADGroupMembership -User $User | |
$TargetGroup -in $Groups | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-Module UniversalDashboard | |
$FormLogin = New-UDAuthenticationMethod -Endpoint { | |
param([PSCredential]$Credentials) | |
$AuthorizedGroup = 'Users' | |
. ".\Test-ADGroupMembership.ps1" | |
. ".\Test-ADCredential.ps1" | |
. ".\Get-ADGroupMembership.ps1" | |
if ($Credentials | ? {$_ | Test-ADCredential} | Test-ADGroupMembership -TargetGroup $AuthorizedGroup) { | |
New-UDAuthenticationResult -Success -UserName $Credentials.UserName | |
} | |
New-UDAuthenticationResult -ErrorMessage "You aren't $($Credentials.UserName)!!!" | |
} | |
$LoginPage = New-UDLoginPage -AuthenticationMethod @($FormLogin) | |
$MyDashboardPage = New-UDPage -Url "/myDashboard" -Endpoint { | |
New-UDCard -Title "Welcome, $User" -Text "This is your custom dashboard." | |
} | |
$Dashboard = New-UDDashboard -LoginPage $LoginPage -Page @( | |
$MyDashboardPage | |
) | |
Start-UDDashboard -Dashboard $Dashboard -Port 8080 -Name 'TestDashboard' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment