Skip to content

Commit

Permalink
Mering hotfix 0.3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm360 committed Dec 30, 2021
2 parents e2b1525 + 1195711 commit 03eaaa4
Show file tree
Hide file tree
Showing 84 changed files with 1,086 additions and 960 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/unstable-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Unstable release on Docker Hub

on:
push:
branches:
- dev
- 'hotfix/**'
- 'release/**'

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: etherna/etherna-sso
tags: |
type=ref,event=branch
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
11 changes: 1 addition & 10 deletions EthernaSSO.sln
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,9 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{61C8B690-EEA5-440E-B5B5-7C8D5098503C}"
ProjectSection(SolutionItems) = preProject
.github\workflows\stable-release.yml = .github\workflows\stable-release.yml
.github\workflows\unstable-release.yml = .github\workflows\unstable-release.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "resources", "resources", "{1F3590A3-E673-48CB-BC3D-7EF9671EE42B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EthernaSSO.RCL", "src\EthernaSSO.RCL\EthernaSSO.RCL.csproj", "{E609F100-1AF8-4F48-8F17-7487DD8BE392}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -62,10 +59,6 @@ Global
{8EE2E2BE-2FB6-4E96-8F34-08F9CDACFCFE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8EE2E2BE-2FB6-4E96-8F34-08F9CDACFCFE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8EE2E2BE-2FB6-4E96-8F34-08F9CDACFCFE}.Release|Any CPU.Build.0 = Release|Any CPU
{E609F100-1AF8-4F48-8F17-7487DD8BE392}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E609F100-1AF8-4F48-8F17-7487DD8BE392}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E609F100-1AF8-4F48-8F17-7487DD8BE392}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E609F100-1AF8-4F48-8F17-7487DD8BE392}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -78,8 +71,6 @@ Global
{AF83D80A-77BE-48C8-ABE3-D1373F20F2B0} = {5AE428C2-CD56-4E51-A229-3F4C137D9D83}
{8EE2E2BE-2FB6-4E96-8F34-08F9CDACFCFE} = {BB9B2543-8741-4D95-AC15-35923C422E60}
{61C8B690-EEA5-440E-B5B5-7C8D5098503C} = {1C01CDAC-366E-4F9B-8A52-25F7770FE92A}
{1F3590A3-E673-48CB-BC3D-7EF9671EE42B} = {A0B68B53-E0DF-4EC9-AFAA-7476C8A26256}
{E609F100-1AF8-4F48-8F17-7487DD8BE392} = {1F3590A3-E673-48CB-BC3D-7EF9671EE42B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6EB5F2B3-8912-4D50-BAB1-C3884E3BF3C0}
Expand Down
3 changes: 2 additions & 1 deletion src/EthernaSSO.Domain/EthernaSSO.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

<ItemGroup>
<PackageReference Include="Etherna.DomainEvents" Version="1.3.0" />
<PackageReference Include="EthernaSSL" Version="0.1.0-alpha.18" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Etherna" Version="0.3.0-alpha.7" />
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="5.0.12" />
<PackageReference Include="MongODM.Core" Version="0.23.0-alpha.37" />
<PackageReference Include="MongODM.Core" Version="0.23.0-alpha.74" />
<PackageReference Include="Nethereum.Accounts" Version="4.1.1" />
</ItemGroup>

Expand Down
46 changes: 0 additions & 46 deletions src/EthernaSSO.Domain/Helpers/EmailHelper.cs

This file was deleted.

11 changes: 11 additions & 0 deletions src/EthernaSSO.Domain/ISharedDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Etherna.MongODM.Core;
using Etherna.MongODM.Core.Repositories;
using Etherna.SSOServer.Domain.Models.UserAgg;

namespace Etherna.SSOServer.Domain
{
public interface ISharedDbContext : IDbContext
{
ICollectionRepository<UserSharedInfo, string> UsersInfo { get; }
}
}
42 changes: 42 additions & 0 deletions src/EthernaSSO.Domain/Models/UserAgg/UserSharedInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Microsoft.AspNetCore.Identity;
using Nethereum.Util;
using System;
using System.Collections.Generic;

namespace Etherna.SSOServer.Domain.Models.UserAgg
{
/* This model will not be encapsulated with UserBase until https://etherna.atlassian.net/browse/MODM-101 is solved.
* After it, a full referenced inclusion can be implemented. */

/// <summary>
/// A class that expose <see cref="UserBase"/> information, but that needs to be saved on a different DbContext,
/// shared with other Etherna services.
/// </summary>
public class UserSharedInfo : EntityModelBase<string>
{
// Fields.
private List<string> _etherPreviousAddresses = new();

// Constructors.
public UserSharedInfo(string etherAddress)
{
if (!etherAddress.IsValidEthereumAddressHexFormat())
throw new ArgumentException("The value is not a valid address", nameof(etherAddress));

EtherAddress = etherAddress;
}
protected UserSharedInfo() { }

// Properties.
[PersonalData]
public virtual string EtherAddress { get; protected internal set; } = default!;
[PersonalData]
public virtual IEnumerable<string> EtherPreviousAddresses
{
get => _etherPreviousAddresses;
protected internal set => _etherPreviousAddresses = new List<string>(value ?? Array.Empty<string>());
}
public virtual bool LockoutEnabled { get; set; }
public virtual DateTimeOffset? LockoutEnd { get; set; }
}
}
34 changes: 30 additions & 4 deletions src/EthernaSSO.Domain/Models/UserBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

using Etherna.Authentication;
using Etherna.MongODM.Core.Attributes;
using Etherna.SSL.Helpers;
using Etherna.SSOServer.Domain.Helpers;
using Etherna.SSOServer.Domain.Models.UserAgg;
using Microsoft.AspNetCore.Identity;
Expand Down Expand Up @@ -42,11 +43,19 @@ public abstract class UserBase : EntityModelBase<string>
private List<Role> _roles = new();

// Constructors.
protected UserBase(string username, UserBase? invitedBy, bool invitedByAdmin)
protected UserBase(
string username,
UserBase? invitedBy,
bool invitedByAdmin,
UserSharedInfo sharedInfo)
{
if (sharedInfo is null)
throw new ArgumentNullException(nameof(sharedInfo));

SetUsername(username);
InvitedBy = invitedBy;
InvitedByAdmin = invitedByAdmin;
SharedInfoId = sharedInfo.Id;
}
protected UserBase() { }

Expand Down Expand Up @@ -79,24 +88,33 @@ public virtual IEnumerable<UserClaim> DefaultClaims
return claims;
}
}

[PersonalData]
public virtual string? Email { get; protected set; }

[PersonalData]
/* Keep until SharedInfo can't be encapsulated. */
public virtual string EtherAddress { get; protected set; } = default!;
//[PersonalData]
//public virtual string EtherAddress => SharedInfo.EtherAddress;

[PersonalData]
/* Keep until SharedInfo can't be encapsulated. */
public virtual IEnumerable<string> EtherPreviousAddresses
{
get => _etherPreviousAddresses;
protected set => _etherPreviousAddresses = new List<string>(value ?? Array.Empty<string>());
}
//[PersonalData]
//public virtual IEnumerable<string> EtherPreviousAddresses => SharedInfo.EtherPreviousAddresses;

public virtual UserBase? InvitedBy { get; protected set; }
public virtual bool InvitedByAdmin { get; protected set; }
public virtual bool IsInvited => InvitedByAdmin || InvitedBy is not null;
[PersonalData]
public virtual DateTime LastLoginDateTime { get; protected set; }
public virtual bool LockoutEnabled { get; set; }
public virtual DateTimeOffset? LockoutEnd { get; set; }
//public virtual bool LockoutEnabled => SharedInfo.LockoutEnabled;
//public virtual DateTimeOffset? LockoutEnd => SharedInfo.LockoutEnd;
public virtual string? NormalizedEmail { get; protected set; }
public virtual string NormalizedUsername { get; protected set; } = default!;
[PersonalData]
Expand All @@ -108,6 +126,14 @@ public virtual IEnumerable<Role> Roles
protected set => _roles = new List<Role>(value ?? Array.Empty<Role>());
}
public virtual string SecurityStamp { get; set; } = default!;

/* SharedInfo is encapsulable with resolution of https://etherna.atlassian.net/browse/MODM-101.
* With encapsulation we can expose also EtherAddress and EtherPreviousAddresses properties
* pointing to SharedInfo internal property, and avoid data duplication.
*/
//protected abstract SharedUserInfo SharedInfo { get; set; }
public virtual string SharedInfoId { get; protected set; } = default!;

[PersonalData]
public virtual string Username { get; protected set; } = default!;

Expand Down
30 changes: 17 additions & 13 deletions src/EthernaSSO.Domain/Models/UserWeb2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// limitations under the License.

using Etherna.MongODM.Core.Attributes;
using Etherna.SSOServer.Domain.Models.UserAgg;
using Microsoft.AspNetCore.Identity;
using Nethereum.Hex.HexConvertors.Extensions;
using Nethereum.Util;
using Nethereum.Web3.Accounts;
using System;
Expand All @@ -31,13 +31,25 @@ public class UserWeb2 : UserBase
private List<string> _twoFactorRecoveryCode = new();

// Constructors.
public UserWeb2(string username, UserBase? invitedBy, bool invitedByAdmin, UserAgg.UserLoginInfo? loginInfo = default)
: base(username, invitedBy, invitedByAdmin)
public UserWeb2(
string username,
UserBase? invitedBy,
bool invitedByAdmin,
string etherManagedPrivateKey,
UserSharedInfo sharedInfo,
UserAgg.UserLoginInfo? loginInfo = default)
: base(username, invitedBy, invitedByAdmin, sharedInfo)
{
// Verify that private key generates correct ether address.
var account = new Account(etherManagedPrivateKey);
if (account.Address != sharedInfo.EtherAddress)
throw new ArgumentException("Ethereum managed private key doesn't generate same address of shared info");

// Initialize.
if (loginInfo is not null)
AddLogin(loginInfo);

EtherManagedPrivateKey = GenerateEtherPrivateKey();
EtherManagedPrivateKey = etherManagedPrivateKey;
}
protected UserWeb2() { }

Expand Down Expand Up @@ -74,7 +86,7 @@ public virtual Account EtherManagedAccount
return _etherManagedAccount;
}
}
public virtual string? EtherManagedPrivateKey { get; protected set; }
public virtual string EtherManagedPrivateKey { get; protected set; } = default!;
[PersonalData]
public virtual string? EtherLoginAddress { get; protected set; }
public virtual bool HasPassword => !string.IsNullOrEmpty(PasswordHash);
Expand Down Expand Up @@ -152,13 +164,5 @@ public virtual void SetEtherLoginAddress(string address)

EtherLoginAddress = address.ConvertToEthereumChecksumAddress();
}

// Private helpers.
private static string GenerateEtherPrivateKey()
{
var ecKey = Nethereum.Signer.EthECKey.GenerateKey();
var privateKey = ecKey.GetPrivateKeyAsBytes().ToHex();
return privateKey;
}
}
}
20 changes: 10 additions & 10 deletions src/EthernaSSO.Domain/Models/UserWeb3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using Nethereum.Util;
using Etherna.SSOServer.Domain.Models.UserAgg;
using System;
using System.Linq;

Expand All @@ -21,15 +21,16 @@ namespace Etherna.SSOServer.Domain.Models
public class UserWeb3 : UserBase
{
// Constructors.
public UserWeb3(string address, string username, UserBase? invitedBy, bool invitedByAdmin)
: base(username, invitedBy, invitedByAdmin)
public UserWeb3(
string username,
UserBase? invitedBy,
bool invitedByAdmin,
UserSharedInfo sharedInfo)
: base(username, invitedBy, invitedByAdmin, sharedInfo)
{
if (!address.IsValidEthereumAddressHexFormat())
throw new ArgumentException("The value is not a valid address", nameof(address));

EtherAddress = address;
EtherAddress = sharedInfo.EtherAddress;
}
public UserWeb3(UserWeb2 web2User)
internal UserWeb3(UserWeb2 web2User)
{
if (web2User is null)
throw new ArgumentNullException(nameof(web2User));
Expand All @@ -45,15 +46,14 @@ public UserWeb3(UserWeb2 web2User)
InvitedBy = web2User.InvitedBy;
InvitedByAdmin = web2User.InvitedByAdmin;
LastLoginDateTime = web2User.LastLoginDateTime;
LockoutEnabled = web2User.LockoutEnabled;
LockoutEnd = web2User.LockoutEnd;
NormalizedEmail = web2User.NormalizedEmail;
NormalizedUsername = web2User.NormalizedUsername;
PhoneNumber = web2User.PhoneNumber;
PhoneNumberConfirmed = web2User.PhoneNumberConfirmed;
Roles = web2User.Roles;
SecurityStamp = web2User.SecurityStamp;
Username = web2User.Username;
SharedInfoId = web2User.SharedInfoId;
}
protected UserWeb3() { }
}
Expand Down
1 change: 1 addition & 0 deletions src/EthernaSSO.Domain/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
using System.Runtime.CompilerServices;

[assembly: CLSCompliant(false)]
[assembly: InternalsVisibleTo("EthernaSSO.Persistence")]
[assembly: InternalsVisibleTo("EthernaSSO.Services")]
Loading

0 comments on commit 03eaaa4

Please sign in to comment.