WIP
parent
b4d6e8e26c
commit
af12fc21d4
|
@ -15,11 +15,14 @@ using ln.identities;
|
|||
using ln.http.session;
|
||||
using ln.json.mapping;
|
||||
using ln.application.json;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ln.application
|
||||
{
|
||||
public class Application : ResourceApplication
|
||||
{
|
||||
public String ApplicationName { get; protected set; } = "ln.application base";
|
||||
|
||||
public ArgumentContainer Arguments { get; protected set; }
|
||||
public HTTPServer HttpServer { get; private set; }
|
||||
|
||||
|
@ -39,7 +42,7 @@ namespace ln.application
|
|||
public Application(IIdentityProvider identityProvider,RPCContainer rpcContainer)
|
||||
{
|
||||
IdentityProvider = identityProvider;
|
||||
RPCContainer = rpcContainer;
|
||||
RPCContainer = rpcContainer ?? new RPCContainer(CheckRPCAccess);
|
||||
|
||||
MemoryLogger = new MemoryLogger(8192);
|
||||
Logger.Default.Backends.Add(MemoryLogger);
|
||||
|
@ -50,11 +53,35 @@ namespace ln.application
|
|||
.Add('p', "http-port", "8080");
|
||||
|
||||
ServiceContainer = new ServiceContainer(this);
|
||||
|
||||
RPCContainer.Add("",new ApplicationRPC(this));
|
||||
RPCContainer.Add("ServiceContainer", ServiceContainer.RPC);
|
||||
}
|
||||
|
||||
|
||||
public Application() :this(null,new RPCContainer()) { }
|
||||
public Application(IIdentityProvider identityProvider) : this(identityProvider,new RPCContainer()) { }
|
||||
public Application() :this(null,null) { }
|
||||
public Application(IIdentityProvider identityProvider) : this(identityProvider,null) { }
|
||||
|
||||
bool CheckRPCAccess(RPCContainer container, RPCContainer.RPCModule module, System.Reflection.MethodInfo method)
|
||||
{
|
||||
RequireAttribute require = method.GetCustomAttribute<RequireAttribute>();
|
||||
if (require != null)
|
||||
{
|
||||
Identity currentIdentity = ApplicationSession.CurrentSession?.SessionIdentity;
|
||||
if (currentIdentity == null)
|
||||
throw new AuthenticationNeeded();
|
||||
|
||||
Guid requiredUID = require.IdentityUniqueID;
|
||||
if (require.IdentityName != null)
|
||||
{
|
||||
requiredUID = currentIdentity.IdentityProvider.GetIdentity(require.IdentityName)?.UniqueID ?? throw new KeyNotFoundException();
|
||||
}
|
||||
|
||||
return currentIdentity.AssignedRoles.HasRole(requiredUID, require.Role);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public virtual void PrepareStart()
|
||||
{
|
||||
|
@ -81,10 +108,8 @@ namespace ln.application
|
|||
HttpServer.Start();
|
||||
HttpServer.DefaultApplication = this;
|
||||
|
||||
RootResource = new BaseResource("");
|
||||
|
||||
|
||||
/* Application Services */
|
||||
|
||||
foreach (ServiceDefinition serviceDefinition in ServiceContainer)
|
||||
{
|
||||
if (serviceDefinition.AutoStart && !serviceDefinition.IsAlive)
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
using System;
|
||||
using System.Threading;
|
||||
using ln.identities;
|
||||
namespace ln.application
|
||||
{
|
||||
public class ApplicationRPC
|
||||
{
|
||||
public Application Application { get; }
|
||||
public ApplicationRPC(Application application)
|
||||
{
|
||||
Application = application;
|
||||
}
|
||||
|
||||
public String GetApplicationName() => Application.ApplicationName;
|
||||
|
||||
[Require(Role.SUPER)]
|
||||
public void Shutdown()
|
||||
{
|
||||
ThreadPool.QueueUserWorkItem((state) => Application.Stop());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -43,6 +43,7 @@
|
|||
<Compile Include="slots\BinarySlotContainer.cs" />
|
||||
<Compile Include="slots\SlotAllocation.cs" />
|
||||
<Compile Include="json\JSONIdentityMapping.cs" />
|
||||
<Compile Include="ApplicationRPC.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ln.types\ln.types.csproj">
|
||||
|
|
2
www
2
www
|
@ -1 +1 @@
|
|||
Subproject commit db1f67805bdc2a539ef1211d38b574053bb9c9be
|
||||
Subproject commit b870fe214cf73547fc1f80f100a6dab56c3a5281
|
Loading…
Reference in New Issue