feat: ensure missing NTFS permission groups
This commit is contained in:
@@ -10,16 +10,17 @@ using Matrix42.Workflows.Contracts;
|
||||
using System.Linq;
|
||||
using Matrix42.Contracts.Platform.General;
|
||||
using System.Json;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using Matrix42.Workflows.Activities.Common.Data;
|
||||
using System.Activities.Validation;
|
||||
using System.Threading.Tasks;
|
||||
using LiamWorkflowActivities;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Security.Principal;
|
||||
using static LiamAD.ADServiceGroupCreator;
|
||||
using C4IT.LIAM;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using Matrix42.Workflows.Activities.Common.Data;
|
||||
using System.Activities.Validation;
|
||||
using System.Threading.Tasks;
|
||||
using LiamWorkflowActivities;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Security.Principal;
|
||||
using static LiamAD.ADServiceGroupCreator;
|
||||
using C4IT.LIAM;
|
||||
using C4IT_IAM_Engine;
|
||||
|
||||
namespace C4IT.LIAM.Activities
|
||||
{
|
||||
@@ -38,13 +39,13 @@ namespace C4IT.LIAM.Activities
|
||||
[DisplayName("Success")]
|
||||
public OutArgument<bool> Success { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Message")]
|
||||
public OutArgument<string> Message { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Error Code")]
|
||||
public OutArgument<string> ErrorCode { get; set; }
|
||||
[Category("Output")]
|
||||
[DisplayName("Message")]
|
||||
public OutArgument<string> Message { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Error Code")]
|
||||
public OutArgument<string> ErrorCode { get; set; }
|
||||
|
||||
protected override void Execute(NativeActivityContext context)
|
||||
{
|
||||
@@ -56,14 +57,14 @@ namespace C4IT.LIAM.Activities
|
||||
{
|
||||
LogEntry($"Executing activity '{GetType().Name}':", LogLevels.Info);
|
||||
LogEntry($" Local server name: {Environment.MachineName}", LogLevels.Info);
|
||||
LogEntry($" Activity input string: {ConfigID.Get(context)}", LogLevels.Info);
|
||||
|
||||
EnsureDataProviders(context);
|
||||
ErrorCode.Set(context, string.Empty);
|
||||
Message.Set(context, string.Empty);
|
||||
|
||||
SecureData secureData = Password.Get(context);
|
||||
var configEOID = ConfigID.Get(context);
|
||||
LogEntry($" Activity input string: {ConfigID.Get(context)}", LogLevels.Info);
|
||||
|
||||
EnsureDataProviders(context);
|
||||
ErrorCode.Set(context, string.Empty);
|
||||
Message.Set(context, string.Empty);
|
||||
|
||||
SecureData secureData = Password.Get(context);
|
||||
var configEOID = ConfigID.Get(context);
|
||||
|
||||
var dataMain = dataProvider.GetDataList(constFragmentNameConfigProviderMain,
|
||||
"ID, [Expression-ObjectId] as EOID, GCCDomain, GCCTarget, GCCMaxDepth, " +
|
||||
@@ -82,31 +83,31 @@ namespace C4IT.LIAM.Activities
|
||||
"NamingConvention.Name as Name, NamingConvention.NamingTemplate as NamingTemplate, NamingConvention.Wildcard as Wildcard",
|
||||
$"[Expression-ObjectID] = '{configEOID}'");
|
||||
|
||||
var DataProvider = createProvider(dataMain.First(), dataBase.First(), dataAdditional, dataNamingConvention, dataCustomTag, secureData);
|
||||
|
||||
var validLogon = DataProvider.LogonAsync().GetAwaiter().GetResult();
|
||||
if (validLogon)
|
||||
{
|
||||
AddCache(ConfigClassId, configEOID, DataProvider);
|
||||
}
|
||||
else
|
||||
{
|
||||
Message.Set(context, DataProvider.GetLastErrorMessage());
|
||||
if (DataProvider is cLiamProviderExchange exProvider)
|
||||
ErrorCode.Set(context, exProvider.GetLastErrorCode());
|
||||
else
|
||||
ErrorCode.Set(context, "WF_PROVIDER_LOGON_FAILED");
|
||||
}
|
||||
|
||||
Success.Set(context, validLogon);
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
LogException(E);
|
||||
Success.Set(context, false);
|
||||
ErrorCode.Set(context, "WF_ACTIVITY_EXCEPTION");
|
||||
Message.Set(context, E.Message);
|
||||
}
|
||||
var DataProvider = createProvider(dataMain.First(), dataBase.First(), dataAdditional, dataNamingConvention, dataCustomTag, secureData);
|
||||
|
||||
var validLogon = DataProvider.LogonAsync().GetAwaiter().GetResult();
|
||||
if (validLogon)
|
||||
{
|
||||
AddCache(ConfigClassId, configEOID, DataProvider);
|
||||
}
|
||||
else
|
||||
{
|
||||
Message.Set(context, DataProvider.GetLastErrorMessage());
|
||||
if (DataProvider is cLiamProviderExchange exProvider)
|
||||
ErrorCode.Set(context, exProvider.GetLastErrorCode());
|
||||
else
|
||||
ErrorCode.Set(context, "WF_PROVIDER_LOGON_FAILED");
|
||||
}
|
||||
|
||||
Success.Set(context, validLogon);
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
LogException(E);
|
||||
Success.Set(context, false);
|
||||
ErrorCode.Set(context, "WF_ACTIVITY_EXCEPTION");
|
||||
Message.Set(context, E.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(CM);
|
||||
@@ -131,21 +132,21 @@ namespace C4IT.LIAM.Activities
|
||||
[RequiredArgument]
|
||||
public InArgument<Guid> ConfigID { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("DataAreas")]
|
||||
public OutArgument<JsonArray> DataAreas { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Success")]
|
||||
public OutArgument<bool> Success { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Error Code")]
|
||||
public OutArgument<string> ErrorCode { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Error Message")]
|
||||
public OutArgument<string> ErrorMessage { get; set; }
|
||||
[Category("Output")]
|
||||
[DisplayName("DataAreas")]
|
||||
public OutArgument<JsonArray> DataAreas { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Success")]
|
||||
public OutArgument<bool> Success { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Error Code")]
|
||||
public OutArgument<string> ErrorCode { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Error Message")]
|
||||
public OutArgument<string> ErrorMessage { get; set; }
|
||||
|
||||
protected override void Execute(NativeActivityContext context)
|
||||
{
|
||||
@@ -157,32 +158,32 @@ namespace C4IT.LIAM.Activities
|
||||
{
|
||||
LogEntry($"Executing activity '{GetType().Name}':", LogLevels.Info);
|
||||
LogEntry($" Local server name: {Environment.MachineName}", LogLevels.Info);
|
||||
LogEntry($" Activity input string: {ConfigID.Get(context)}", LogLevels.Info);
|
||||
|
||||
EnsureDataProviders(context);
|
||||
Success.Set(context, false);
|
||||
ErrorCode.Set(context, string.Empty);
|
||||
ErrorMessage.Set(context, string.Empty);
|
||||
|
||||
var dataAreas = getDataAreasFromProvider(ConfigID.Get(context)).GetAwaiter().GetResult() ?? Enumerable.Empty<DataAreaEntry>();
|
||||
var dataAreaJson = dataAreas.Select(da => JsonValue.Parse(JsonConvert.SerializeObject(da)));
|
||||
DataAreas.Set(context, new JsonArray(dataAreaJson));
|
||||
Success.Set(context, true);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(LastOperationErrorCode))
|
||||
{
|
||||
Success.Set(context, false);
|
||||
ErrorCode.Set(context, LastOperationErrorCode);
|
||||
ErrorMessage.Set(context, LastOperationErrorMessage);
|
||||
}
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
LogException(E);
|
||||
Success.Set(context, false);
|
||||
ErrorCode.Set(context, "WF_ACTIVITY_EXCEPTION");
|
||||
ErrorMessage.Set(context, E.Message);
|
||||
}
|
||||
LogEntry($" Activity input string: {ConfigID.Get(context)}", LogLevels.Info);
|
||||
|
||||
EnsureDataProviders(context);
|
||||
Success.Set(context, false);
|
||||
ErrorCode.Set(context, string.Empty);
|
||||
ErrorMessage.Set(context, string.Empty);
|
||||
|
||||
var dataAreas = getDataAreasFromProvider(ConfigID.Get(context)).GetAwaiter().GetResult() ?? Enumerable.Empty<DataAreaEntry>();
|
||||
var dataAreaJson = dataAreas.Select(da => JsonValue.Parse(JsonConvert.SerializeObject(da)));
|
||||
DataAreas.Set(context, new JsonArray(dataAreaJson));
|
||||
Success.Set(context, true);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(LastOperationErrorCode))
|
||||
{
|
||||
Success.Set(context, false);
|
||||
ErrorCode.Set(context, LastOperationErrorCode);
|
||||
ErrorMessage.Set(context, LastOperationErrorMessage);
|
||||
}
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
LogException(E);
|
||||
Success.Set(context, false);
|
||||
ErrorCode.Set(context, "WF_ACTIVITY_EXCEPTION");
|
||||
ErrorMessage.Set(context, E.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(CM);
|
||||
@@ -207,21 +208,21 @@ namespace C4IT.LIAM.Activities
|
||||
[RequiredArgument]
|
||||
public InArgument<Guid> ConfigID { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("SecurityGroups")]
|
||||
public OutArgument<JsonArray> SecurityGroups { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Success")]
|
||||
public OutArgument<bool> Success { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Error Code")]
|
||||
public OutArgument<string> ErrorCode { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Error Message")]
|
||||
public OutArgument<string> ErrorMessage { get; set; }
|
||||
[Category("Output")]
|
||||
[DisplayName("SecurityGroups")]
|
||||
public OutArgument<JsonArray> SecurityGroups { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Success")]
|
||||
public OutArgument<bool> Success { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Error Code")]
|
||||
public OutArgument<string> ErrorCode { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Error Message")]
|
||||
public OutArgument<string> ErrorMessage { get; set; }
|
||||
|
||||
protected override void Execute(NativeActivityContext context)
|
||||
{
|
||||
@@ -233,32 +234,32 @@ namespace C4IT.LIAM.Activities
|
||||
{
|
||||
LogEntry($"Executing activity '{GetType().Name}':", LogLevels.Info);
|
||||
LogEntry($" Local server name: {Environment.MachineName}", LogLevels.Info);
|
||||
LogEntry($" Activity input string: {ConfigID.Get(context)}", LogLevels.Info);
|
||||
|
||||
EnsureDataProviders(context);
|
||||
Success.Set(context, false);
|
||||
ErrorCode.Set(context, string.Empty);
|
||||
ErrorMessage.Set(context, string.Empty);
|
||||
|
||||
var securityGroups = getSecurityGroupsFromProvider(ConfigID.Get(context)).GetAwaiter().GetResult() ?? Enumerable.Empty<SecurityGroupEntry>();
|
||||
var securityGroupJson = securityGroups.Select(sg => JsonValue.Parse(JsonConvert.SerializeObject(sg)));
|
||||
SecurityGroups.Set(context, new JsonArray(securityGroupJson));
|
||||
Success.Set(context, true);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(LastOperationErrorCode))
|
||||
{
|
||||
Success.Set(context, false);
|
||||
ErrorCode.Set(context, LastOperationErrorCode);
|
||||
ErrorMessage.Set(context, LastOperationErrorMessage);
|
||||
}
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
LogException(E);
|
||||
Success.Set(context, false);
|
||||
ErrorCode.Set(context, "WF_ACTIVITY_EXCEPTION");
|
||||
ErrorMessage.Set(context, E.Message);
|
||||
}
|
||||
LogEntry($" Activity input string: {ConfigID.Get(context)}", LogLevels.Info);
|
||||
|
||||
EnsureDataProviders(context);
|
||||
Success.Set(context, false);
|
||||
ErrorCode.Set(context, string.Empty);
|
||||
ErrorMessage.Set(context, string.Empty);
|
||||
|
||||
var securityGroups = getSecurityGroupsFromProvider(ConfigID.Get(context)).GetAwaiter().GetResult() ?? Enumerable.Empty<SecurityGroupEntry>();
|
||||
var securityGroupJson = securityGroups.Select(sg => JsonValue.Parse(JsonConvert.SerializeObject(sg)));
|
||||
SecurityGroups.Set(context, new JsonArray(securityGroupJson));
|
||||
Success.Set(context, true);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(LastOperationErrorCode))
|
||||
{
|
||||
Success.Set(context, false);
|
||||
ErrorCode.Set(context, LastOperationErrorCode);
|
||||
ErrorMessage.Set(context, LastOperationErrorMessage);
|
||||
}
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
LogException(E);
|
||||
Success.Set(context, false);
|
||||
ErrorCode.Set(context, "WF_ACTIVITY_EXCEPTION");
|
||||
ErrorMessage.Set(context, E.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(CM);
|
||||
@@ -301,10 +302,10 @@ namespace C4IT.LIAM.Activities
|
||||
|
||||
EnsureDataProviders(context);
|
||||
|
||||
var ownersInfo = getOwnerInfosFromDataArea(DataAreaID.Get(context)).GetAwaiter().GetResult() ?? new List<cLiamUserInfo>();
|
||||
var owners = getPersonsFromUsers(ownersInfo) ?? new List<Guid>();
|
||||
var ownerJson = owners.Select(user => JsonValue.Parse(JsonConvert.SerializeObject(user)));
|
||||
OwnerUserIDs.Set(context, new JsonArray(ownerJson));
|
||||
var ownersInfo = getOwnerInfosFromDataArea(DataAreaID.Get(context)).GetAwaiter().GetResult() ?? new List<cLiamUserInfo>();
|
||||
var owners = getPersonsFromUsers(ownersInfo) ?? new List<Guid>();
|
||||
var ownerJson = owners.Select(user => JsonValue.Parse(JsonConvert.SerializeObject(user)));
|
||||
OwnerUserIDs.Set(context, new JsonArray(ownerJson));
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
@@ -579,83 +580,83 @@ namespace C4IT.LIAM.Activities
|
||||
[DisplayName("Object GUID")]
|
||||
public OutArgument<Guid> ObjectGuid { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Created Groups")]
|
||||
public OutArgument<List<Tuple<string, string, string, string>>> CreatedGroups { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Error Code")]
|
||||
public OutArgument<string> ErrorCode { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Error Message")]
|
||||
public OutArgument<string> ErrorMessage { get; set; }
|
||||
|
||||
protected override void Execute(NativeActivityContext context)
|
||||
{
|
||||
if (!IsInitialized) Initialize(context);
|
||||
var CM = MethodBase.GetCurrentMethod();
|
||||
LogMethodBegin(CM);
|
||||
try
|
||||
{
|
||||
LogEntry($"Executing activity '{GetType().Name}'", LogLevels.Info);
|
||||
|
||||
EnsureDataProviders(context);
|
||||
ErrorCode.Set(context, string.Empty);
|
||||
ErrorMessage.Set(context, string.Empty);
|
||||
|
||||
var entry = getDataProvider(ConfigID.Get(context));
|
||||
if (entry != null && entry.Provider is cLiamProviderExchange ex)
|
||||
{
|
||||
var result = ex.exchangeManager.CreateDistributionGroupWithOwnershipGroups(
|
||||
Name.Get(context),
|
||||
Alias.Get(context),
|
||||
DistributionListDisplayName.Get(context),
|
||||
PrimarySmtpAddress.Get(context),
|
||||
out string errorCode,
|
||||
out string errorMessage
|
||||
);
|
||||
ErrorCode.Set(context, errorCode);
|
||||
ErrorMessage.Set(context, errorMessage);
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
Success.Set(context, true);
|
||||
ObjectGuid.Set(context, result.Item1);
|
||||
CreatedGroups.Set(context, result.Item2);
|
||||
LogEntry(
|
||||
$"Distribution group creation succeeded. ObjectGuid='{result.Item1}', CreatedGroups='{result.Item2?.Count ?? 0}'",
|
||||
LogLevels.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
Success.Set(context, false);
|
||||
LogEntry(
|
||||
$"Distribution group creation failed [{errorCode}] {errorMessage}",
|
||||
LogLevels.Error);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Success.Set(context, false);
|
||||
ErrorCode.Set(context, "WF_PROVIDER_INVALID");
|
||||
ErrorMessage.Set(context, $"Provider is not a cLiamProviderExchange for config '{ConfigID.Get(context)}'.");
|
||||
LogEntry(
|
||||
$"Distribution group creation failed [WF_PROVIDER_INVALID] Provider is not a cLiamProviderExchange for config '{ConfigID.Get(context)}'.",
|
||||
LogLevels.Error);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogException(e);
|
||||
Success.Set(context, false);
|
||||
ErrorCode.Set(context, "WF_ACTIVITY_EXCEPTION");
|
||||
ErrorMessage.Set(context, e.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(CM);
|
||||
}
|
||||
[Category("Output")]
|
||||
[DisplayName("Created Groups")]
|
||||
public OutArgument<List<Tuple<string, string, string, string>>> CreatedGroups { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Error Code")]
|
||||
public OutArgument<string> ErrorCode { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Error Message")]
|
||||
public OutArgument<string> ErrorMessage { get; set; }
|
||||
|
||||
protected override void Execute(NativeActivityContext context)
|
||||
{
|
||||
if (!IsInitialized) Initialize(context);
|
||||
var CM = MethodBase.GetCurrentMethod();
|
||||
LogMethodBegin(CM);
|
||||
try
|
||||
{
|
||||
LogEntry($"Executing activity '{GetType().Name}'", LogLevels.Info);
|
||||
|
||||
EnsureDataProviders(context);
|
||||
ErrorCode.Set(context, string.Empty);
|
||||
ErrorMessage.Set(context, string.Empty);
|
||||
|
||||
var entry = getDataProvider(ConfigID.Get(context));
|
||||
if (entry != null && entry.Provider is cLiamProviderExchange ex)
|
||||
{
|
||||
var result = ex.exchangeManager.CreateDistributionGroupWithOwnershipGroups(
|
||||
Name.Get(context),
|
||||
Alias.Get(context),
|
||||
DistributionListDisplayName.Get(context),
|
||||
PrimarySmtpAddress.Get(context),
|
||||
out string errorCode,
|
||||
out string errorMessage
|
||||
);
|
||||
ErrorCode.Set(context, errorCode);
|
||||
ErrorMessage.Set(context, errorMessage);
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
Success.Set(context, true);
|
||||
ObjectGuid.Set(context, result.Item1);
|
||||
CreatedGroups.Set(context, result.Item2);
|
||||
LogEntry(
|
||||
$"Distribution group creation succeeded. ObjectGuid='{result.Item1}', CreatedGroups='{result.Item2?.Count ?? 0}'",
|
||||
LogLevels.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
Success.Set(context, false);
|
||||
LogEntry(
|
||||
$"Distribution group creation failed [{errorCode}] {errorMessage}",
|
||||
LogLevels.Error);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Success.Set(context, false);
|
||||
ErrorCode.Set(context, "WF_PROVIDER_INVALID");
|
||||
ErrorMessage.Set(context, $"Provider is not a cLiamProviderExchange for config '{ConfigID.Get(context)}'.");
|
||||
LogEntry(
|
||||
$"Distribution group creation failed [WF_PROVIDER_INVALID] Provider is not a cLiamProviderExchange for config '{ConfigID.Get(context)}'.",
|
||||
LogLevels.Error);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogException(e);
|
||||
Success.Set(context, false);
|
||||
ErrorCode.Set(context, "WF_ACTIVITY_EXCEPTION");
|
||||
ErrorMessage.Set(context, e.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(CM);
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureDataProviders(NativeActivityContext context)
|
||||
@@ -702,82 +703,82 @@ namespace C4IT.LIAM.Activities
|
||||
[DisplayName("Object GUID")]
|
||||
public OutArgument<Guid> ObjectGuid { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Created Groups")]
|
||||
public OutArgument<List<Tuple<string, string, string, string>>> CreatedGroups { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Error Code")]
|
||||
public OutArgument<string> ErrorCode { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Error Message")]
|
||||
public OutArgument<string> ErrorMessage { get; set; }
|
||||
|
||||
protected override void Execute(NativeActivityContext context)
|
||||
{
|
||||
if (!IsInitialized) Initialize(context);
|
||||
var CM = MethodBase.GetCurrentMethod();
|
||||
LogMethodBegin(CM);
|
||||
try
|
||||
{
|
||||
LogEntry($"Executing activity '{GetType().Name}'", LogLevels.Info);
|
||||
|
||||
EnsureDataProviders(context);
|
||||
ErrorCode.Set(context, string.Empty);
|
||||
ErrorMessage.Set(context, string.Empty);
|
||||
|
||||
var entry = getDataProvider(ConfigID.Get(context));
|
||||
if (entry != null && entry.Provider is cLiamProviderExchange ex)
|
||||
{
|
||||
var result = ex.exchangeManager.CreateSharedMailboxWithOwnershipGroups(
|
||||
Name.Get(context),
|
||||
Alias.Get(context),
|
||||
MailboxDisplayName.Get(context),
|
||||
PrimarySmtpAddress.Get(context),
|
||||
out string errorCode,
|
||||
out string errorMessage
|
||||
);
|
||||
ErrorCode.Set(context, errorCode);
|
||||
ErrorMessage.Set(context, errorMessage);
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
Success.Set(context, true);
|
||||
ObjectGuid.Set(context, result.Item1);
|
||||
CreatedGroups.Set(context, result.Item2);
|
||||
LogEntry(
|
||||
$"Shared mailbox creation succeeded. ObjectGuid='{result.Item1}', CreatedGroups='{result.Item2?.Count ?? 0}'",
|
||||
LogLevels.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
Success.Set(context, false);
|
||||
LogEntry(
|
||||
$"Shared mailbox creation failed [{errorCode}] {errorMessage}",
|
||||
LogLevels.Error);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Success.Set(context, false);
|
||||
ErrorCode.Set(context, "WF_PROVIDER_INVALID");
|
||||
ErrorMessage.Set(context, $"Provider is not a cLiamProviderExchange for config '{ConfigID.Get(context)}'.");
|
||||
LogEntry(
|
||||
$"Shared mailbox creation failed [WF_PROVIDER_INVALID] Provider is not a cLiamProviderExchange for config '{ConfigID.Get(context)}'.",
|
||||
LogLevels.Error);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogException(e);
|
||||
Success.Set(context, false);
|
||||
ErrorCode.Set(context, "WF_ACTIVITY_EXCEPTION");
|
||||
ErrorMessage.Set(context, e.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(CM);
|
||||
[Category("Output")]
|
||||
[DisplayName("Created Groups")]
|
||||
public OutArgument<List<Tuple<string, string, string, string>>> CreatedGroups { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Error Code")]
|
||||
public OutArgument<string> ErrorCode { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Error Message")]
|
||||
public OutArgument<string> ErrorMessage { get; set; }
|
||||
|
||||
protected override void Execute(NativeActivityContext context)
|
||||
{
|
||||
if (!IsInitialized) Initialize(context);
|
||||
var CM = MethodBase.GetCurrentMethod();
|
||||
LogMethodBegin(CM);
|
||||
try
|
||||
{
|
||||
LogEntry($"Executing activity '{GetType().Name}'", LogLevels.Info);
|
||||
|
||||
EnsureDataProviders(context);
|
||||
ErrorCode.Set(context, string.Empty);
|
||||
ErrorMessage.Set(context, string.Empty);
|
||||
|
||||
var entry = getDataProvider(ConfigID.Get(context));
|
||||
if (entry != null && entry.Provider is cLiamProviderExchange ex)
|
||||
{
|
||||
var result = ex.exchangeManager.CreateSharedMailboxWithOwnershipGroups(
|
||||
Name.Get(context),
|
||||
Alias.Get(context),
|
||||
MailboxDisplayName.Get(context),
|
||||
PrimarySmtpAddress.Get(context),
|
||||
out string errorCode,
|
||||
out string errorMessage
|
||||
);
|
||||
ErrorCode.Set(context, errorCode);
|
||||
ErrorMessage.Set(context, errorMessage);
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
Success.Set(context, true);
|
||||
ObjectGuid.Set(context, result.Item1);
|
||||
CreatedGroups.Set(context, result.Item2);
|
||||
LogEntry(
|
||||
$"Shared mailbox creation succeeded. ObjectGuid='{result.Item1}', CreatedGroups='{result.Item2?.Count ?? 0}'",
|
||||
LogLevels.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
Success.Set(context, false);
|
||||
LogEntry(
|
||||
$"Shared mailbox creation failed [{errorCode}] {errorMessage}",
|
||||
LogLevels.Error);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Success.Set(context, false);
|
||||
ErrorCode.Set(context, "WF_PROVIDER_INVALID");
|
||||
ErrorMessage.Set(context, $"Provider is not a cLiamProviderExchange for config '{ConfigID.Get(context)}'.");
|
||||
LogEntry(
|
||||
$"Shared mailbox creation failed [WF_PROVIDER_INVALID] Provider is not a cLiamProviderExchange for config '{ConfigID.Get(context)}'.",
|
||||
LogLevels.Error);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogException(e);
|
||||
Success.Set(context, false);
|
||||
ErrorCode.Set(context, "WF_ACTIVITY_EXCEPTION");
|
||||
ErrorMessage.Set(context, e.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(CM);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -959,5 +960,107 @@ namespace C4IT.LIAM.Activities
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class C4ITLIAMEnsureNtfsPermissionGroupsActivity : cLIAMM42BaseActivity
|
||||
{
|
||||
[Category("Input")]
|
||||
[DisplayName("Config Id")]
|
||||
[RequiredArgument]
|
||||
public InArgument<Guid> ConfigID { get; set; }
|
||||
|
||||
[Category("Input")]
|
||||
[DisplayName("Folder Path")]
|
||||
[RequiredArgument]
|
||||
public InArgument<string> FolderPath { get; set; }
|
||||
|
||||
[Category("Input")]
|
||||
[DisplayName("Owner SIDs")]
|
||||
public InArgument<string> OwnerSids { get; set; }
|
||||
|
||||
[Category("Input")]
|
||||
[DisplayName("Reader SIDs")]
|
||||
public InArgument<string> ReaderSids { get; set; }
|
||||
|
||||
[Category("Input")]
|
||||
[DisplayName("Writer SIDs")]
|
||||
public InArgument<string> WriterSids { get; set; }
|
||||
|
||||
[Category("Input")]
|
||||
[DisplayName("Ensure Traverse")]
|
||||
public InArgument<bool> EnsureTraverse { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Success")]
|
||||
public OutArgument<bool> Success { get; set; }
|
||||
|
||||
[Category("Output")]
|
||||
[DisplayName("Result")]
|
||||
public OutArgument<JsonValue> ResultToken { get; set; }
|
||||
|
||||
protected override void Execute(NativeActivityContext context)
|
||||
{
|
||||
EnsureDataProviders(context);
|
||||
|
||||
var cfgId = ConfigID.Get(context);
|
||||
var providerEntry = getDataProvider(cfgId);
|
||||
var provider = providerEntry?.Provider as cLiamProviderNtfs;
|
||||
var folderPath = FolderPath.Get(context);
|
||||
if (provider == null || string.IsNullOrWhiteSpace(folderPath))
|
||||
{
|
||||
Success.Set(context, false);
|
||||
ResultToken.Set(context, JsonValue.Parse(JsonConvert.SerializeObject(new ResultToken(GetType().Name)
|
||||
{
|
||||
resultErrorId = 1,
|
||||
resultMessage = provider == null ? "Configured provider is not NTFS or not initialized." : "Folder path is missing."
|
||||
})));
|
||||
return;
|
||||
}
|
||||
|
||||
var result = provider.EnsureMissingPermissionGroupsAsync(
|
||||
folderPath,
|
||||
null,
|
||||
ParseSidList(OwnerSids.Get(context)),
|
||||
ParseSidList(ReaderSids.Get(context)),
|
||||
ParseSidList(WriterSids.Get(context)),
|
||||
EnsureTraverse.Get(context)).GetAwaiter().GetResult();
|
||||
|
||||
Success.Set(context, result != null && result.resultErrorId == 0);
|
||||
ResultToken.Set(context, JsonValue.Parse(JsonConvert.SerializeObject(result)));
|
||||
}
|
||||
|
||||
private IEnumerable<string> ParseSidList(string raw)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(raw))
|
||||
return Enumerable.Empty<string>();
|
||||
|
||||
var trimmed = raw.Trim();
|
||||
if (trimmed.StartsWith("["))
|
||||
{
|
||||
try
|
||||
{
|
||||
return JsonConvert.DeserializeObject<List<string>>(trimmed) ?? Enumerable.Empty<string>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
return trimmed
|
||||
.Split(new[] { ';', ',', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(i => i.Trim())
|
||||
.Where(i => !string.IsNullOrWhiteSpace(i))
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private void EnsureDataProviders(NativeActivityContext context)
|
||||
{
|
||||
if (executor == null)
|
||||
executor = context.GetExtension<IExtensionExecutor>();
|
||||
if (schemaReader == null)
|
||||
schemaReader = executor.Get<ISchemaReaderProvider>();
|
||||
if (dataProvider == null)
|
||||
dataProvider = executor.Get<IDataReaderProvider>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user