diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/Views/Shared/Components/AbpMenu/Default.cshtml b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/Views/Shared/Components/AbpMenu/Default.cshtml
index 4a2365b898..1835de738a 100644
--- a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/Views/Shared/Components/AbpMenu/Default.cshtml
+++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/Views/Shared/Components/AbpMenu/Default.cshtml
@@ -1,6 +1,8 @@
@using System.Threading.Tasks
+@using Volo.Abp.Session
@using Volo.Abp.Ui.Navigation
-@model Volo.Abp.Ui.Navigation.ApplicationMenu
+@model ApplicationMenu
+@inject ICurrentUser CurrentUser
diff --git a/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Security/Claims/HttpContextCurrentPrincipalAccessor.cs b/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Security/Claims/HttpContextCurrentPrincipalAccessor.cs
new file mode 100644
index 0000000000..d1318e2c3e
--- /dev/null
+++ b/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Security/Claims/HttpContextCurrentPrincipalAccessor.cs
@@ -0,0 +1,18 @@
+using System.Security.Claims;
+using Microsoft.AspNetCore.Http;
+using Volo.Abp.Security.Claims;
+
+namespace Volo.Abp.AspNetCore.Security.Claims
+{
+ public class HttpContextCurrentPrincipalAccessor : ThreadCurrentPrincipalAccessor
+ {
+ public override ClaimsPrincipal Principal => _httpContextAccessor.HttpContext?.User ?? base.Principal;
+
+ private readonly IHttpContextAccessor _httpContextAccessor;
+
+ public HttpContextCurrentPrincipalAccessor(IHttpContextAccessor httpContextAccessor)
+ {
+ _httpContextAccessor = httpContextAccessor;
+ }
+ }
+}
diff --git a/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/MultiTenancyManager.cs b/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/MultiTenancyManager.cs
index 1db22637d7..a53ffd7e60 100644
--- a/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/MultiTenancyManager.cs
+++ b/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/MultiTenancyManager.cs
@@ -76,6 +76,8 @@ namespace Volo.Abp.MultiTenancy
return _tenantScopeProvider.CurrentScope.Tenant;
}
+ //TODO: Get from ICurrentUser before resolvers and fail if resolvers find a different tenant!
+
return GetCurrentTenantFromResolvers();
}
@@ -94,7 +96,7 @@ namespace Volo.Abp.MultiTenancy
{
tenantResolver.Resolve(context);
- if (context.ResolvedTenantOrHost())
+ if (context.HasResolvedTenantOrHost())
{
if (context.TenantIdOrName == null)
{
diff --git a/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/TenantResolveContext.cs b/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/TenantResolveContext.cs
index 6f84d5ed75..6f27d5be17 100644
--- a/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/TenantResolveContext.cs
+++ b/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/TenantResolveContext.cs
@@ -10,7 +10,7 @@ namespace Volo.Abp.MultiTenancy
public bool Handled { get; set; }
- internal bool ResolvedTenantOrHost()
+ internal bool HasResolvedTenantOrHost()
{
return Handled || TenantIdOrName != null;
}
diff --git a/src/Volo.Abp/Volo/Abp/Security/Claims/AbpClaimTypes.cs b/src/Volo.Abp/Volo/Abp/Security/Claims/AbpClaimTypes.cs
new file mode 100644
index 0000000000..79eaf25701
--- /dev/null
+++ b/src/Volo.Abp/Volo/Abp/Security/Claims/AbpClaimTypes.cs
@@ -0,0 +1,34 @@
+using System.Security.Claims;
+
+namespace Volo.Abp.Security.Claims
+{
+ ///
+ /// Used to get ABP-specific claim type names.
+ ///
+ public static class AbpClaimTypes
+ {
+ ///
+ /// UserId.
+ /// Default:
+ ///
+ public static string UserName { get; set; } = ClaimTypes.Name;
+
+ ///
+ /// UserId.
+ /// Default:
+ ///
+ public static string UserId { get; set; } = ClaimTypes.NameIdentifier;
+
+ ///
+ /// UserId.
+ /// Default:
+ ///
+ public static string Role { get; set; } = ClaimTypes.Role;
+
+ ///
+ /// UserId.
+ /// Default:
+ ///
+ public static string Email { get; set; } = ClaimTypes.Email;
+ }
+}
diff --git a/src/Volo.Abp/Volo/Abp/Security/Claims/ICurrentPrincipalAccessor.cs b/src/Volo.Abp/Volo/Abp/Security/Claims/ICurrentPrincipalAccessor.cs
new file mode 100644
index 0000000000..d49e61ddd6
--- /dev/null
+++ b/src/Volo.Abp/Volo/Abp/Security/Claims/ICurrentPrincipalAccessor.cs
@@ -0,0 +1,9 @@
+using System.Security.Claims;
+
+namespace Volo.Abp.Security.Claims
+{
+ public interface ICurrentPrincipalAccessor
+ {
+ ClaimsPrincipal Principal { get; }
+ }
+}
diff --git a/src/Volo.Abp/Volo/Abp/Security/Claims/ThreadCurrentPrincipalAccessor.cs b/src/Volo.Abp/Volo/Abp/Security/Claims/ThreadCurrentPrincipalAccessor.cs
new file mode 100644
index 0000000000..de0032c51d
--- /dev/null
+++ b/src/Volo.Abp/Volo/Abp/Security/Claims/ThreadCurrentPrincipalAccessor.cs
@@ -0,0 +1,11 @@
+using System.Security.Claims;
+using System.Threading;
+using Volo.Abp.DependencyInjection;
+
+namespace Volo.Abp.Security.Claims
+{
+ public class ThreadCurrentPrincipalAccessor : ICurrentPrincipalAccessor, ISingletonDependency
+ {
+ public virtual ClaimsPrincipal Principal => Thread.CurrentPrincipal as ClaimsPrincipal;
+ }
+}
\ No newline at end of file
diff --git a/src/Volo.Abp/Volo/Abp/Session/CurrentUser.cs b/src/Volo.Abp/Volo/Abp/Session/CurrentUser.cs
new file mode 100644
index 0000000000..6652a8436a
--- /dev/null
+++ b/src/Volo.Abp/Volo/Abp/Session/CurrentUser.cs
@@ -0,0 +1,60 @@
+using System;
+using System.Linq;
+using System.Security.Claims;
+using Volo.Abp.DependencyInjection;
+using Volo.Abp.Security.Claims;
+
+namespace Volo.Abp.Session
+{
+ public class CurrentUser : ICurrentUser, ITransientDependency //TODO: Singleton?
+ {
+ public virtual bool IsAuthenticated => Id.HasValue;
+
+ public virtual Guid? Id
+ {
+ get
+ {
+ var value = FindClaimValue(AbpClaimTypes.UserId);
+ if (value == null)
+ {
+ return null;
+ }
+
+ return Guid.Parse(value);
+ }
+ }
+
+ public virtual string UserName => FindClaimValue(AbpClaimTypes.UserName);
+
+ public virtual string Email => FindClaimValue(AbpClaimTypes.Email);
+
+ private readonly ICurrentPrincipalAccessor _principalAccessor;
+
+ public CurrentUser(ICurrentPrincipalAccessor principalAccessor)
+ {
+ _principalAccessor = principalAccessor;
+ }
+
+ public virtual Claim FindClaim(string claimType)
+ {
+ return _principalAccessor.Principal?.Claims.FirstOrDefault(c => c.Type == claimType);
+ }
+
+ public virtual T FindClaimValue(string claimType)
+ where T : struct
+ {
+ var value = FindClaimValue(claimType);
+ if (value == null)
+ {
+ return default(T);
+ }
+
+ return value.To();
+ }
+
+ public virtual string FindClaimValue(string claimType)
+ {
+ return FindClaim(claimType)?.Value;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Volo.Abp/Volo/Abp/Session/ICurrentUser.cs b/src/Volo.Abp/Volo/Abp/Session/ICurrentUser.cs
new file mode 100644
index 0000000000..d4eee21cf7
--- /dev/null
+++ b/src/Volo.Abp/Volo/Abp/Session/ICurrentUser.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Security.Claims;
+
+namespace Volo.Abp.Session
+{
+ public interface ICurrentUser
+ {
+ bool IsAuthenticated { get; }
+
+ Guid? Id { get; }
+
+ string UserName { get; }
+
+ string Email { get; }
+
+ Claim FindClaim(string claimType);
+
+ string FindClaimValue(string claimType);
+
+ T FindClaimValue(string claimType)
+ where T : struct;
+ }
+}