From a83c28cc7b3002a40abca68a3be8d7237ca32b72 Mon Sep 17 00:00:00 2001 From: Doug Schmidt Date: Thu, 13 Dec 2018 20:23:17 +1030 Subject: [PATCH] Issue-109 - Added support for the CanConfigureSystem property in each user row --- TimeSeries/PublicApis/SdkExamples/Readme.md | 29 ------------------- .../SdkExamples/UserImporter/Readme.md | 29 +++++++++++++++++++ .../UserImporter/Records/UserRecord.cs | 7 ++++- .../SdkExamples/UserImporter/UserImporter.cs | 2 +- .../UserImporter/UserImporter.csproj | 3 +- .../UserImporter/UserImporterContext.cs | 8 ++--- .../SdkExamples/UserImporter/UserMapper.cs | 28 +++++++++--------- .../UserImporter/UserRecordValidator.cs | 2 +- 8 files changed, 57 insertions(+), 51 deletions(-) create mode 100644 TimeSeries/PublicApis/SdkExamples/UserImporter/Readme.md diff --git a/TimeSeries/PublicApis/SdkExamples/Readme.md b/TimeSeries/PublicApis/SdkExamples/Readme.md index cdb3f602..af020f9c 100644 --- a/TimeSeries/PublicApis/SdkExamples/Readme.md +++ b/TimeSeries/PublicApis/SdkExamples/Readme.md @@ -53,32 +53,3 @@ Key concepts demonstrated: Everything from the `AppendPoints` example, plus: - Using the `GET /Publish/v2/GetTimeSeriesUniqueIdList` request to monitor a time-series for ["changes since"](https://github.com/AquaticInformatics/aquarius-sdk-net/wiki/Monitoring-changes-to-a-time-series#changes-since-concept) the last time you polled the system. - Using the `POST /Acquisition/v2/{UniqueId}/reflected` request to queue points to be appended to a reflected time-series, overwriting any existing points within a time range. -### UserImporter - -The `UserImporter` example app can be used to import a number of AQTS users from a CSV file. - -All three AQTS authentication methods are supported: -- Aquarius credentials -- Active Directory authentication -- OpenId Connect authentication - -The basic logic performed by the app is: -- Connect to the AQTS server -- Retrieve the current list of users in the system -- Read the CSV to get the user records to create/modify -- New users will be added to AQTS -- Existing users will be updated. This includes changing the authentication mode for an existing user. - -Example CSV format consumed by the `UserImporter` app is: -```csv -Username, FirstName, LastName, Email, Active, CanLaunchRdt, AuthenticationType, Password, UserPrincipalName, SubjectIdentifier -fredcred, fred, cred, fred@derf.com, true, true, Credentials, sekret, , -fredwin, fred, win, fred@win.com, true, true, ActiveDirectory, , fred@win.com, -fredopen, fred, openid, "fred@gmail.com", true, true, OpenIdConnect, , , 113611963171978735131 -``` - -Key concepts demonstrated: -- Using the `GET /Provisioning/v1/users` operation to get the currently configured users from a system. -- Using the `POST /Provisioning/v1/users/{authenticationType}` operations to create users with a specific authentication type -- Using the `PUT /Provisioning/v1/users/{authenticationType}/{userUniqueId}` operations to update existing users properties -- Using the `PUT /Provisioning/v1/users/{userUniqueId}/{authenticationType}` operations to change an existing user from one authentication type to another diff --git a/TimeSeries/PublicApis/SdkExamples/UserImporter/Readme.md b/TimeSeries/PublicApis/SdkExamples/UserImporter/Readme.md new file mode 100644 index 00000000..6c0c34ad --- /dev/null +++ b/TimeSeries/PublicApis/SdkExamples/UserImporter/Readme.md @@ -0,0 +1,29 @@ +# UserImporter + +The `UserImporter` example app can be used to import a number of AQTS users from a CSV file. + +All three AQTS authentication methods are supported: +- Aquarius credentials +- Active Directory authentication +- OpenId Connect authentication + +The basic logic performed by the app is: +- Connect to the AQTS server +- Retrieve the current list of users in the system +- Read the CSV to get the user records to create/modify +- New users will be added to AQTS +- Existing users will be updated. This includes changing the authentication mode for an existing user. + +Example CSV format consumed by the `UserImporter` app is: +```csv +Username, FirstName, LastName, Email, Active, CanLaunchRdt, AuthenticationType, Password, UserPrincipalName, SubjectIdentifier, CanConfigureSystem +fredcred, fred, cred, fred@derf.com, true, true, Credentials, sekret, , , false +fredwin, fred, win, fred@win.com, true, true, ActiveDirectory, , fred@win.com, , false +fredopen, fred, openid, "fred@gmail.com", true, true, OpenIdConnect, , , 113611963171978735131, false +``` + +Key concepts demonstrated: +- Using the `GET /Provisioning/v1/users` operation to get the currently configured users from a system. +- Using the `POST /Provisioning/v1/users/{authenticationType}` operations to create users with a specific authentication type +- Using the `PUT /Provisioning/v1/users/{authenticationType}/{userUniqueId}` operations to update existing users properties +- Using the `PUT /Provisioning/v1/users/{userUniqueId}/{authenticationType}` operations to change an existing user from one authentication type to another diff --git a/TimeSeries/PublicApis/SdkExamples/UserImporter/Records/UserRecord.cs b/TimeSeries/PublicApis/SdkExamples/UserImporter/Records/UserRecord.cs index 9100a105..3d5064f2 100644 --- a/TimeSeries/PublicApis/SdkExamples/UserImporter/Records/UserRecord.cs +++ b/TimeSeries/PublicApis/SdkExamples/UserImporter/Records/UserRecord.cs @@ -37,6 +37,9 @@ public class UserRecord [FieldTrim(TrimMode.Both), FieldQuoted(QuoteMode.OptionalForBoth, MultilineMode.NotAllow)] private string _subjectIdentifier; + [FieldTrim(TrimMode.Both), FieldQuoted(QuoteMode.OptionalForBoth, MultilineMode.NotAllow), FieldOptional, FieldNullValue(false), FieldConverter(typeof(CsvBoolConverter))] + private bool _canConfigureSystem; + public string Username => _username; public string FirstName => _firstName; @@ -55,6 +58,8 @@ public class UserRecord public string UserPrincipalName => _userPrincipalName; - public string SujectIdentifier => _subjectIdentifier; + public string SubjectIdentifier => _subjectIdentifier; + + public bool CanConfigureSystem => _canConfigureSystem; } } diff --git a/TimeSeries/PublicApis/SdkExamples/UserImporter/UserImporter.cs b/TimeSeries/PublicApis/SdkExamples/UserImporter/UserImporter.cs index b35bbf99..c32a0a3f 100644 --- a/TimeSeries/PublicApis/SdkExamples/UserImporter/UserImporter.cs +++ b/TimeSeries/PublicApis/SdkExamples/UserImporter/UserImporter.cs @@ -189,7 +189,7 @@ private static readonly Dictionary new PutOpenIdConnectAuth { - SubjectIdentifier = userRecord.SujectIdentifier, + SubjectIdentifier = userRecord.SubjectIdentifier, UniqueId = uniqueId } }, diff --git a/TimeSeries/PublicApis/SdkExamples/UserImporter/UserImporter.csproj b/TimeSeries/PublicApis/SdkExamples/UserImporter/UserImporter.csproj index d056d34a..83b4f460 100644 --- a/TimeSeries/PublicApis/SdkExamples/UserImporter/UserImporter.csproj +++ b/TimeSeries/PublicApis/SdkExamples/UserImporter/UserImporter.csproj @@ -110,6 +110,7 @@ + @@ -136,4 +137,4 @@ --> - + \ No newline at end of file diff --git a/TimeSeries/PublicApis/SdkExamples/UserImporter/UserImporterContext.cs b/TimeSeries/PublicApis/SdkExamples/UserImporter/UserImporterContext.cs index ee05d6b3..25a41145 100644 --- a/TimeSeries/PublicApis/SdkExamples/UserImporter/UserImporterContext.cs +++ b/TimeSeries/PublicApis/SdkExamples/UserImporter/UserImporterContext.cs @@ -94,10 +94,10 @@ public UserImporterContext(IEnumerable arguments) private static string CreateSampleCsvOutput() { - return @"Username, FirstName, LastName, Email, Active, CanLaunchRdt, AuthenticationType, Password, UserPrincipalName, SubjectIdentifier -fredcred, fred, cred, fred@derf.com, true, true, Credentials, sekret, , -fredwin, fred, win, fred@win.com, true, true, ActiveDirectory, , fred@win.com, -fredopen, fred, openid, ""fred@gmail.com"", true, true, OpenIdConnect, , , 113611963171978735131"; + return @"Username, FirstName, LastName, Email, Active, CanLaunchRdt, AuthenticationType, Password, UserPrincipalName, SubjectIdentifier, CanConfigureSystem +fredcred, fred, cred, fred@derf.com, true, true, Credentials, sekret, , , false +fredwin, fred, win, fred@win.com, true, true, ActiveDirectory, , fred@win.com, , false +fredopen, fred, openid, ""fred@gmail.com"", true, true, OpenIdConnect, , , 113611963171978735131, false"; } } } diff --git a/TimeSeries/PublicApis/SdkExamples/UserImporter/UserMapper.cs b/TimeSeries/PublicApis/SdkExamples/UserImporter/UserMapper.cs index 74985595..4cb2d98f 100644 --- a/TimeSeries/PublicApis/SdkExamples/UserImporter/UserMapper.cs +++ b/TimeSeries/PublicApis/SdkExamples/UserImporter/UserMapper.cs @@ -6,19 +6,19 @@ namespace UserImporter { public static class UserMapper { - public static PutCredentialsUser GetCredentialsPutUserFromRecord(UserRecord userRecord, Guid unqiueIdentifier) + public static PutCredentialsUser GetCredentialsPutUserFromRecord(UserRecord userRecord, Guid uniqueIdentifier) { var postUser = new PutCredentialsUser { Active = userRecord.Active, - CanConfigureSystem = false, + CanConfigureSystem = userRecord.CanConfigureSystem, CanLaunchRatingDevelopmentToolbox = userRecord.CanLaunchRdt, Email = userRecord.Email, FirstName = userRecord.FirstName, LastName = userRecord.LastName, LoginName = userRecord.Username, Password = userRecord.Password, - UniqueId = unqiueIdentifier + UniqueId = uniqueIdentifier }; return postUser; @@ -29,7 +29,7 @@ public static PostCredentialsUser GetCredentialsPostUserFromRecord(UserRecord us var postUser = new PostCredentialsUser { Active = userRecord.Active, - CanConfigureSystem = false, + CanConfigureSystem = userRecord.CanConfigureSystem, CanLaunchRatingDevelopmentToolbox = userRecord.CanLaunchRdt, Email = userRecord.Email, FirstName = userRecord.FirstName, @@ -41,19 +41,19 @@ public static PostCredentialsUser GetCredentialsPostUserFromRecord(UserRecord us return postUser; } - public static PutOpenIdConnectUser GetOpenIdConnectPutUserFromRecord(UserRecord userRecord, Guid unqiueIdentifier) + public static PutOpenIdConnectUser GetOpenIdConnectPutUserFromRecord(UserRecord userRecord, Guid uniqueIdentifier) { var user = new PutOpenIdConnectUser { Active = userRecord.Active, - CanConfigureSystem = false, + CanConfigureSystem = userRecord.CanConfigureSystem, CanLaunchRatingDevelopmentToolbox = userRecord.CanLaunchRdt, Email = userRecord.Email, FirstName = userRecord.FirstName, LastName = userRecord.LastName, LoginName = userRecord.Username, - SubjectIdentifier = userRecord.SujectIdentifier, - UniqueId = unqiueIdentifier + SubjectIdentifier = userRecord.SubjectIdentifier, + UniqueId = uniqueIdentifier }; return user; @@ -64,31 +64,31 @@ public static PostOpenIdConnectUser GetOpenIdConnectPostUserFromRecord(UserRecor var user = new PostOpenIdConnectUser { Active = userRecord.Active, - CanConfigureSystem = false, + CanConfigureSystem = userRecord.CanConfigureSystem, CanLaunchRatingDevelopmentToolbox = userRecord.CanLaunchRdt, Email = userRecord.Email, FirstName = userRecord.FirstName, LastName = userRecord.LastName, LoginName = userRecord.Username, - SubjectIdentifier = userRecord.SujectIdentifier + SubjectIdentifier = userRecord.SubjectIdentifier }; return user; } - public static PutActiveDirectoryUser GetActiveDirectoryPutUserFromRecord(UserRecord userRecord, Guid unqiueIdentifier) + public static PutActiveDirectoryUser GetActiveDirectoryPutUserFromRecord(UserRecord userRecord, Guid uniqueIdentifier) { var user = new PutActiveDirectoryUser { Active = userRecord.Active, - CanConfigureSystem = false, + CanConfigureSystem = userRecord.CanConfigureSystem, CanLaunchRatingDevelopmentToolbox = userRecord.CanLaunchRdt, Email = userRecord.Email, FirstName = userRecord.FirstName, LastName = userRecord.LastName, LoginName = userRecord.Username, UserPrincipalName = userRecord.UserPrincipalName, - UniqueId = unqiueIdentifier + UniqueId = uniqueIdentifier }; return user; @@ -99,7 +99,7 @@ public static PostActiveDirectoryUser GetActiveDirectoryPostUserFromRecord(UserR var user = new PostActiveDirectoryUser { Active = userRecord.Active, - CanConfigureSystem = false, + CanConfigureSystem = userRecord.CanConfigureSystem, CanLaunchRatingDevelopmentToolbox = userRecord.CanLaunchRdt, Email = userRecord.Email, FirstName = userRecord.FirstName, diff --git a/TimeSeries/PublicApis/SdkExamples/UserImporter/UserRecordValidator.cs b/TimeSeries/PublicApis/SdkExamples/UserImporter/UserRecordValidator.cs index 3dc31bc1..33693a7f 100644 --- a/TimeSeries/PublicApis/SdkExamples/UserImporter/UserRecordValidator.cs +++ b/TimeSeries/PublicApis/SdkExamples/UserImporter/UserRecordValidator.cs @@ -47,7 +47,7 @@ public static List ValidateUserList(List userRecords) } if (record.AuthenticationType == AuthenticationType.OpenIdConnect && - string.IsNullOrEmpty(record.SujectIdentifier)) + string.IsNullOrEmpty(record.SubjectIdentifier)) { Log.Error($"User record for '{record.Username}' is {record.AuthenticationType}, but no SubjectIdentifier provided. Skipping."); continue;