Implement Get/Set-TokenLifetime
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
// **************************************************************************
|
||||
// Copyright (c) VMware, Inc. All rights reserved. -- VMware Confidential.
|
||||
// **************************************************************************
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VMware.vSphere.SsoAdminClient.DataTypes
|
||||
{
|
||||
public class TokenLifetime
|
||||
{
|
||||
SsoAdminClient _client;
|
||||
public TokenLifetime(SsoAdminClient client) {
|
||||
_client = client;
|
||||
}
|
||||
|
||||
public SsoAdminClient GetClient() {
|
||||
return _client;
|
||||
}
|
||||
|
||||
public long MaxHoKTokenLifetime { get; set; }
|
||||
public long MaxBearerTokenLifetime { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -556,6 +556,67 @@ namespace VMware.vSphere.SsoAdminClient
|
||||
|
||||
return GetLockoutPolicy();
|
||||
}
|
||||
|
||||
public TokenLifetime GetTokenLifetime() {
|
||||
|
||||
// Create Authorization Invocation Context
|
||||
var authorizedInvocationContext =
|
||||
CreateAuthorizedInvocationContext();
|
||||
|
||||
var maxHoKTokenLifetime = authorizedInvocationContext.
|
||||
InvokeOperation(() =>
|
||||
_ssoAdminBindingClient.GetMaximumHoKTokenLifetimeAsync(
|
||||
new ManagedObjectReference {
|
||||
type = "SsoAdminConfigurationManagementService",
|
||||
Value = "configurationManagementService"
|
||||
})).Result;
|
||||
|
||||
var maxBearerTokenLifetime = authorizedInvocationContext.
|
||||
InvokeOperation(() =>
|
||||
_ssoAdminBindingClient.GetMaximumBearerTokenLifetimeAsync(
|
||||
new ManagedObjectReference {
|
||||
type = "SsoAdminConfigurationManagementService",
|
||||
Value = "configurationManagementService"
|
||||
})).Result;
|
||||
|
||||
return new TokenLifetime(this) {
|
||||
MaxHoKTokenLifetime = maxHoKTokenLifetime,
|
||||
MaxBearerTokenLifetime = maxBearerTokenLifetime
|
||||
};
|
||||
}
|
||||
|
||||
public TokenLifetime SetTokenLifetime(
|
||||
long? maxHoKTokenLifetime,
|
||||
long? maxBearerTokenLifetime) {
|
||||
|
||||
var authorizedInvocationContext =
|
||||
CreateAuthorizedInvocationContext();
|
||||
|
||||
if (maxHoKTokenLifetime != null) {
|
||||
authorizedInvocationContext.
|
||||
InvokeOperation(() =>
|
||||
_ssoAdminBindingClient.SetMaximumHoKTokenLifetimeAsync(
|
||||
new ManagedObjectReference {
|
||||
type = "SsoAdminConfigurationManagementService",
|
||||
Value = "configurationManagementService"
|
||||
},
|
||||
maxHoKTokenLifetime.Value)).Wait();
|
||||
}
|
||||
|
||||
if (maxBearerTokenLifetime != null) {
|
||||
authorizedInvocationContext.
|
||||
InvokeOperation(() =>
|
||||
_ssoAdminBindingClient.SetMaximumBearerTokenLifetimeAsync(
|
||||
new ManagedObjectReference {
|
||||
type = "SsoAdminConfigurationManagementService",
|
||||
Value = "configurationManagementService"
|
||||
},
|
||||
maxBearerTokenLifetime.Value)).Wait();
|
||||
}
|
||||
|
||||
|
||||
return GetTokenLifetime();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user