Implement Get-IdnetitySource advanced function
This commit is contained in:
@@ -101,9 +101,9 @@ namespace VMware.vSphere.SsoAdminClient.Tests
|
||||
public void AddRemoveUserFromGroup() {
|
||||
// Arrange
|
||||
var ssoAdminClient = new SsoAdminClient(_vc, _user, _password, new AcceptAllX509CertificateValidator());
|
||||
|
||||
|
||||
var expectedUserName = "test-user5";
|
||||
var expectedPassword = "te$tPa$sW0rd";
|
||||
var expectedPassword = "te$tPa$sW0rd";
|
||||
var newUser = ssoAdminClient.CreateLocalUser(
|
||||
expectedUserName,
|
||||
expectedPassword);
|
||||
@@ -137,9 +137,9 @@ namespace VMware.vSphere.SsoAdminClient.Tests
|
||||
|
||||
// Act
|
||||
// Assert
|
||||
Assert.DoesNotThrow(() => {
|
||||
ssoAdminClient.ResetPersonUserPassword(newUser, updatePassword);
|
||||
});
|
||||
Assert.DoesNotThrow(() => {
|
||||
ssoAdminClient.ResetPersonUserPassword(newUser, updatePassword);
|
||||
});
|
||||
|
||||
|
||||
// Cleanup
|
||||
@@ -261,8 +261,21 @@ namespace VMware.vSphere.SsoAdminClient.Tests
|
||||
originalLockoutPolicy.Description,
|
||||
originalLockoutPolicy.AutoUnlockIntervalSec,
|
||||
originalLockoutPolicy.FailedAttemptIntervalSec,
|
||||
originalLockoutPolicy.MaxFailedAttempts
|
||||
originalLockoutPolicy.MaxFailedAttempts
|
||||
);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetDomains() {
|
||||
// Arrange
|
||||
var ssoAdminClient = new SsoAdminClient(_vc, _user, _password, new AcceptAllX509CertificateValidator());
|
||||
|
||||
// Act
|
||||
var actual = ssoAdminClient.GetDomains().ToArray<IdentitySource>();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.IsTrue(actual.Length >= 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// **************************************************************************
|
||||
// Copyright 2020 VMware, Inc.
|
||||
// **************************************************************************
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VMware.vSphere.SsoAdminClient.DataTypes
|
||||
{
|
||||
public class ActiveDirectoryIdentitySource : IdentitySource
|
||||
{
|
||||
public string Type { get; set; }
|
||||
public string Alias { get; set; }
|
||||
|
||||
public string AuthenticationType { get; set; }
|
||||
public string AuthenticationUsername { get; set; }
|
||||
|
||||
public string FriendlyName { get; set; }
|
||||
public string PrimaryUrl { get; set; }
|
||||
public string UserBaseDN { get; set; }
|
||||
public string GroupBaseDN { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// **************************************************************************
|
||||
// Copyright 2020 VMware, Inc.
|
||||
// **************************************************************************
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VMware.vSphere.SsoAdminClient.DataTypes
|
||||
{
|
||||
public class IdentitySource
|
||||
{
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// **************************************************************************
|
||||
// Copyright 2020 VMware, Inc.
|
||||
// **************************************************************************
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VMware.vSphere.SsoAdminClient.DataTypes
|
||||
{
|
||||
public class LocalOSIdentitySource : IdentitySource
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// **************************************************************************
|
||||
// Copyright 2020 VMware, Inc.
|
||||
// **************************************************************************
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VMware.vSphere.SsoAdminClient.DataTypes
|
||||
{
|
||||
public class SystemIdentitySource : IdentitySource
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -656,6 +656,45 @@ namespace VMware.vSphere.SsoAdminClient
|
||||
password = authenticationPassword
|
||||
})).Wait();
|
||||
}
|
||||
|
||||
public IEnumerable<IdentitySource> GetDomains() {
|
||||
var authorizedInvocationContext =
|
||||
CreateAuthorizedInvocationContext();
|
||||
|
||||
var domains = authorizedInvocationContext.
|
||||
InvokeOperation(() =>
|
||||
_ssoAdminBindingClient.GetDomainsAsync(
|
||||
new ManagedObjectReference {
|
||||
type = "SsoAdminDomainManagementService",
|
||||
Value = "domainManagementService"
|
||||
})).Result;
|
||||
|
||||
if (domains != null) {
|
||||
var localos = new LocalOSIdentitySource();
|
||||
localos.Name = domains.localOSDomainName;
|
||||
yield return localos;
|
||||
|
||||
var system = new SystemIdentitySource();
|
||||
system.Name = domains.systemDomainName;
|
||||
yield return system;
|
||||
|
||||
if (domains.externalDomains != null && domains.externalDomains.Length > 0) {
|
||||
foreach (var externalDomain in domains.externalDomains) {
|
||||
var extIdentitySource = new ActiveDirectoryIdentitySource();
|
||||
extIdentitySource.Name = externalDomain.name;
|
||||
extIdentitySource.Alias = externalDomain.alias;
|
||||
extIdentitySource.Type = externalDomain.type;
|
||||
extIdentitySource.AuthenticationType = externalDomain.authenticationDetails?.authenticationType;
|
||||
extIdentitySource.AuthenticationUsername = externalDomain.authenticationDetails?.username;
|
||||
extIdentitySource.FriendlyName = externalDomain.details?.friendlyName;
|
||||
extIdentitySource.PrimaryUrl = externalDomain.details?.primaryUrl;
|
||||
extIdentitySource.GroupBaseDN = externalDomain.details?.groupBaseDn;
|
||||
extIdentitySource.UserBaseDN = externalDomain.details?.userBaseDn;
|
||||
yield return extIdentitySource;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
# **************************************************************************
|
||||
# Copyright 2020 VMware, Inc.
|
||||
# **************************************************************************
|
||||
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]
|
||||
$VcAddress,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]
|
||||
$User,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]
|
||||
$Password
|
||||
)
|
||||
|
||||
# Import Vmware.vSphere.SsoAdmin Module
|
||||
$modulePath = Join-Path (Split-Path $PSScriptRoot | Split-Path) "VMware.vSphere.SsoAdmin.psd1"
|
||||
Import-Module $modulePath
|
||||
|
||||
Describe "Get-IdentitySource Tests" {
|
||||
BeforeEach {
|
||||
Connect-SsoAdminServer `
|
||||
-Server $VcAddress `
|
||||
-User $User `
|
||||
-Password $Password `
|
||||
-SkipCertificateCheck
|
||||
}
|
||||
|
||||
AfterEach {
|
||||
$connectionsToCleanup = $global:DefaultSsoAdminServers.ToArray()
|
||||
foreach ($connection in $connectionsToCleanup) {
|
||||
Disconnect-SsoAdminServer -Server $connection
|
||||
}
|
||||
}
|
||||
|
||||
Context "Get-IdentitySource" {
|
||||
It 'Gets all available identity sources' {
|
||||
# Act
|
||||
$actual = Get-IdentitySource
|
||||
|
||||
# Assert
|
||||
$actual | Should Not Be $null
|
||||
$actual.Count | Should BeGreaterThan 1
|
||||
$actual[0].NAme | Should Be 'localos'
|
||||
}
|
||||
|
||||
It 'Gets localos only identity source' {
|
||||
# Act
|
||||
$actual = Get-IdentitySource -Localos
|
||||
|
||||
# Assert
|
||||
$actual | Should Not Be $null
|
||||
$actual.Count | Should Be 1
|
||||
$actual[0].NAme | Should Be 'localos'
|
||||
}
|
||||
|
||||
It 'Gets all available identity sources' {
|
||||
# Act
|
||||
$actual = Get-IdentitySource -Localos -System
|
||||
|
||||
# Assert
|
||||
$actual | Should Not Be $null
|
||||
$actual.Count | Should Be 2
|
||||
$actual[0].Name | Should Be 'localos'
|
||||
$actual[0].Name | Should Not Be $null
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user