Implement Get/Set-LockoutPolicy cmdlets
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
// **************************************************************************
|
||||
// Copyright (c) VMware, Inc. All rights reserved. -- VMware Confidential.
|
||||
// **************************************************************************
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.ServiceModel.Security;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VMware.vSphere.SsoAdminClient.DataTypes
|
||||
{
|
||||
public class LockoutPolicy
|
||||
{
|
||||
SsoAdminClient _client;
|
||||
public LockoutPolicy(SsoAdminClient client) {
|
||||
_client = client;
|
||||
}
|
||||
|
||||
public SsoAdminClient GetClient() {
|
||||
return _client;
|
||||
}
|
||||
|
||||
public string Description { get; set; }
|
||||
public long AutoUnlockIntervalSec { get; set; }
|
||||
public long FailedAttemptIntervalSec { get; set; }
|
||||
public int MaxFailedAttempts { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -483,6 +483,79 @@ namespace VMware.vSphere.SsoAdminClient
|
||||
|
||||
return GetPasswordPolicy();
|
||||
}
|
||||
|
||||
public LockoutPolicy GetLockoutPolicy() {
|
||||
LockoutPolicy result = null;
|
||||
// Create Authorization Invocation Context
|
||||
var authorizedInvocationContext =
|
||||
CreateAuthorizedInvocationContext();
|
||||
|
||||
// Invoke SSO Admin GetLockoutPolicyAsync operation
|
||||
var ssoAdminLockoutPolicy = authorizedInvocationContext.
|
||||
InvokeOperation(() =>
|
||||
_ssoAdminBindingClient.GetLockoutPolicyAsync(
|
||||
new ManagedObjectReference {
|
||||
type = "SsoAdminLockoutPolicyService",
|
||||
Value = "lockoutPolicyService"
|
||||
})).Result;
|
||||
|
||||
if (ssoAdminLockoutPolicy != null) {
|
||||
result = new LockoutPolicy(this) {
|
||||
Description = ssoAdminLockoutPolicy.description,
|
||||
AutoUnlockIntervalSec = ssoAdminLockoutPolicy.autoUnlockIntervalSec,
|
||||
FailedAttemptIntervalSec = ssoAdminLockoutPolicy.failedAttemptIntervalSec,
|
||||
MaxFailedAttempts = ssoAdminLockoutPolicy.maxFailedAttempts
|
||||
};
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public LockoutPolicy SetLockoutPolicy(
|
||||
string description,
|
||||
long? autoUnlockIntervalSec,
|
||||
long? failedAttemptIntervalSec,
|
||||
int? maxFailedAttempts) {
|
||||
|
||||
if (description != null ||
|
||||
autoUnlockIntervalSec != null ||
|
||||
failedAttemptIntervalSec != null ||
|
||||
maxFailedAttempts != null) {
|
||||
|
||||
var ssoAdminLockoutPolicy = new SsoAdminLockoutPolicy();
|
||||
|
||||
ssoAdminLockoutPolicy.description = description;
|
||||
|
||||
if (autoUnlockIntervalSec != null) {
|
||||
ssoAdminLockoutPolicy.autoUnlockIntervalSec = autoUnlockIntervalSec.Value;
|
||||
}
|
||||
|
||||
if (failedAttemptIntervalSec != null) {
|
||||
ssoAdminLockoutPolicy.failedAttemptIntervalSec = failedAttemptIntervalSec.Value;
|
||||
}
|
||||
|
||||
if (maxFailedAttempts != null) {
|
||||
ssoAdminLockoutPolicy.maxFailedAttempts = maxFailedAttempts.Value;
|
||||
}
|
||||
|
||||
// Create Authorization Invocation Context
|
||||
var authorizedInvocationContext =
|
||||
CreateAuthorizedInvocationContext();
|
||||
|
||||
// Invoke SSO Admin GetLockoutPolicyAsync operation
|
||||
authorizedInvocationContext.
|
||||
InvokeOperation(() =>
|
||||
_ssoAdminBindingClient.UpdateLockoutPolicyAsync(
|
||||
new ManagedObjectReference {
|
||||
type = "SsoAdminLockoutPolicyService",
|
||||
Value = "lockoutPolicyService"
|
||||
},
|
||||
ssoAdminLockoutPolicy)).Wait();
|
||||
|
||||
}
|
||||
|
||||
return GetLockoutPolicy();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user