9using Microsoft.AspNetCore.Components.Authorization;
11using System.Security.Claims;
12using System.Security.Principal;
13using System.Threading.Tasks;
25 private IPrincipal CurrentPrincipal {
get;
set; }
26 private readonly ClaimsPrincipal UnauthenticatedPrincipal =
new();
27 private bool disposedValue;
47 CurrentPrincipal = UnauthenticatedPrincipal;
52 private void InitializeUser()
57 private void AuthenticationStateProvider_AuthenticationStateChanged(Task<AuthenticationState> task)
59 task.ContinueWith((t) =>
61 if (task.IsCompletedSuccessfully && task.Result !=
null)
62 CurrentPrincipal = task.Result.User;
64 CurrentPrincipal = UnauthenticatedPrincipal;
89 return CurrentPrincipal;
98 public virtual void SetUser(IPrincipal principal)
100 CurrentPrincipal = principal;
108 if (LocalContext ==
null)
119 LocalContext = localContext;
128 if (ClientContext ==
null)
130 return ClientContext;
140 ClientContext = clientContext;
147 protected virtual void Dispose(
bool disposing)
155 disposedValue =
true;
166 GC.SuppressFinalize(
this);
Provides consistent context information between the client and server DataPortal objects.
ExecutionLocations
Enum representing the locations code can execute.
Application context manager that uses HttpContextAccessor when resolving HttpContext to store context...
AuthenticationStateProvider AuthenticationStateProvider
Gets the current HttpContext instance.
void SetClientContext(ContextDictionary clientContext, ApplicationContext.ExecutionLocations executionLocation)
Sets the client context.
void Dispose()
Dispose this object's resources.
bool IsValid
Gets a value indicating whether this context manager is valid for use in the current environment.
bool IsStatefulContext
Gets a value indicating whether the current runtime is stateful (e.g.
ContextDictionary GetClientContext(ApplicationContext.ExecutionLocations executionLocation)
Gets the client context.
virtual void SetUser(IPrincipal principal)
Sets the current principal ONLY IN APPLICATIONCONTEXT.
virtual void Dispose(bool disposing)
Dispose this object's resources.
ApplicationContextManager(AuthenticationStateProvider authenticationStateProvider)
Creates an instance of the object, initializing it with the required IServiceProvider.
ContextDictionary GetLocalContext()
Gets the local context.
void SetLocalContext(ContextDictionary localContext)
Sets the local context.
IPrincipal GetUser()
Gets the current principal.
Dictionary type that is serializable with the SerializationFormatterFactory.GetFormatter().
Defines the interface for an application context manager type.