WIP
parent
089ce02f0b
commit
3cc4f92e40
|
@ -0,0 +1,38 @@
|
|||
// /**
|
||||
// * File: AuthenticationProvider.cs
|
||||
// * Author: haraldwolff
|
||||
// *
|
||||
// * This file and it's content is copyrighted by the Author and / or copyright holder.
|
||||
// * Any use wihtout proper permission is illegal and may lead to legal actions.
|
||||
// *
|
||||
// *
|
||||
// **/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
namespace ln.http
|
||||
{
|
||||
public abstract class AuthenticationProvider
|
||||
{
|
||||
public AuthenticationProvider()
|
||||
{
|
||||
}
|
||||
|
||||
public abstract IEnumerable<HttpUser> EnumerateUsers();
|
||||
public abstract HttpUser Authenticate(HttpRequest httpRequest);
|
||||
|
||||
public virtual HttpUser GetHttpUser(String authenticationName)
|
||||
{
|
||||
foreach (HttpUser httpUser in EnumerateUsers())
|
||||
{
|
||||
if (httpUser.AuthenticationName.Equals(authenticationName))
|
||||
{
|
||||
return httpUser;
|
||||
}
|
||||
}
|
||||
throw new KeyNotFoundException();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
// /**
|
||||
// * File: AuthorizationMask.cs
|
||||
// * Author: haraldwolff
|
||||
// *
|
||||
// * This file and it's content is copyrighted by the Author and / or copyright holder.
|
||||
// * Any use wihtout proper permission is illegal and may lead to legal actions.
|
||||
// *
|
||||
// *
|
||||
// **/
|
||||
using System;
|
||||
namespace ln.http
|
||||
{
|
||||
public static class AuthorizationMask
|
||||
{
|
||||
public static readonly long A_ACCESS = (1l << 0);
|
||||
public static readonly long A_READ = (1l << 0);
|
||||
public static readonly long A_WRITE = (1l << 0);
|
||||
public static readonly long A_EXEC = (1l << 0);
|
||||
|
||||
public static readonly long A_SUPER = (-1);
|
||||
}
|
||||
}
|
|
@ -114,6 +114,9 @@ namespace ln.http
|
|||
if (applications.ContainsKey(httpRequest.BaseURI))
|
||||
application = applications[httpRequest.BaseURI];
|
||||
|
||||
application.Authenticate(httpRequest);
|
||||
application.Authorize(httpRequest);
|
||||
|
||||
response = application.GetResponse( httpRequest );
|
||||
} catch (Exception e)
|
||||
{
|
||||
|
|
|
@ -1,13 +1,20 @@
|
|||
using System;
|
||||
using ln.http;
|
||||
using ln.http.resources.session;
|
||||
namespace ln.http
|
||||
{
|
||||
public abstract class HttpApplication
|
||||
{
|
||||
public AuthenticationProvider AuthenticationProvider { get; protected set; }
|
||||
|
||||
public HttpApplication()
|
||||
{
|
||||
}
|
||||
|
||||
public abstract HttpResponse GetResponse(HttpRequest httpRequest);
|
||||
|
||||
public virtual void Authenticate(HttpRequest httpRequest) { }
|
||||
public virtual void Authorize(HttpRequest httpRequest) { }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,6 +105,8 @@ namespace ln.http
|
|||
}
|
||||
}
|
||||
|
||||
public HttpUser CurrentUser => Session.CurrentUser;
|
||||
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
// /**
|
||||
// * File: HttpUser.cs
|
||||
// * Author: haraldwolff
|
||||
// *
|
||||
// * This file and it's content is copyrighted by the Author and / or copyright holder.
|
||||
// * Any use wihtout proper permission is illegal and may lead to legal actions.
|
||||
// *
|
||||
// *
|
||||
// **/
|
||||
using System;
|
||||
|
||||
namespace ln.http
|
||||
{
|
||||
public class HttpUser
|
||||
{
|
||||
public String AuthenticationName { get; private set; }
|
||||
public virtual String DisplayName { get; private set; }
|
||||
|
||||
public long AccessRightsMask { get; private set; }
|
||||
|
||||
public HttpUser()
|
||||
{
|
||||
AuthenticationName = "";
|
||||
DisplayName = "Anonymous";
|
||||
AccessRightsMask = 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -45,6 +45,8 @@
|
|||
<Compile Include="HttpCookie.cs" />
|
||||
<Compile Include="session\Session.cs" />
|
||||
<Compile Include="session\SessionCache.cs" />
|
||||
<Compile Include="HttpUser.cs" />
|
||||
<Compile Include="AuthenticationProvider.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="exceptions\" />
|
||||
|
|
|
@ -10,11 +10,15 @@ namespace ln.http.resources.session
|
|||
public long SessionAge => DateTimeOffset.Now.ToUnixTimeSeconds() - LastTouch;
|
||||
public long LastTouch { get; private set; }
|
||||
|
||||
public HttpUser CurrentUser { get; set; }
|
||||
|
||||
|
||||
private readonly Dictionary<string, object> elements = new Dictionary<string, object>();
|
||||
|
||||
public Session()
|
||||
{
|
||||
SessionID = Guid.NewGuid();
|
||||
CurrentUser = new HttpUser();
|
||||
}
|
||||
|
||||
public object this[string name]
|
||||
|
@ -29,5 +33,11 @@ namespace ln.http.resources.session
|
|||
{
|
||||
LastTouch = DateTimeOffset.Now.ToUnixTimeSeconds();
|
||||
}
|
||||
|
||||
public virtual void Authenticate(HttpRequest httpRequest)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue