Skip to content

Commit

Permalink
Merge pull request #110 from DougSchmidt-AI/feature/Issue-109-UserImp…
Browse files Browse the repository at this point in the history
…orterSupportsCanConfigureSystem

Issue-109 - Added support for the CanConfigureSystem property in each…
  • Loading branch information
Doug Schmidt authored Dec 13, 2018
2 parents 3c78ab6 + a83c28c commit 91e2db2
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 51 deletions.
29 changes: 0 additions & 29 deletions TimeSeries/PublicApis/SdkExamples/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 29 additions & 0 deletions TimeSeries/PublicApis/SdkExamples/UserImporter/Readme.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -55,6 +58,8 @@ public class UserRecord

public string UserPrincipalName => _userPrincipalName;

public string SujectIdentifier => _subjectIdentifier;
public string SubjectIdentifier => _subjectIdentifier;

public bool CanConfigureSystem => _canConfigureSystem;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private static readonly Dictionary<AuthenticationType, Func<UserRecord, Guid, IR
{
AuthenticationType.OpenIdConnect, (userRecord, uniqueId) => new PutOpenIdConnectAuth
{
SubjectIdentifier = userRecord.SujectIdentifier,
SubjectIdentifier = userRecord.SubjectIdentifier,
UniqueId = uniqueId
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
</None>
<EmbeddedResource Include="log4net.config" />
<None Include="packages.config" />
<None Include="Readme.md" />
</ItemGroup>
<ItemGroup>
<None Include="FodyWeavers.xml" />
Expand All @@ -136,4 +137,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ public UserImporterContext(IEnumerable<string> 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";
}
}
}
28 changes: 14 additions & 14 deletions TimeSeries/PublicApis/SdkExamples/UserImporter/UserMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static List<UserRecord> ValidateUserList(List<UserRecord> 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;
Expand Down

0 comments on commit 91e2db2

Please sign in to comment.