-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSecureModule.cs
41 lines (39 loc) · 1.14 KB
/
SecureModule.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using DSM.Core.Ops;
using Nancy;
using Nancy.Security;
namespace DSM.GatewayEngine
{
public abstract class SecureModule : NancyModule
{
protected LogManager logManager;
public SecureModule(string logPath)
{
this.RequiresAuthentication();
logManager = LogManager.GetManager(logPath);
}
public SecureModule(string logPath,string urlPath) : base(urlPath)
{
this.RequiresAuthentication();
logManager =LogManager.GetManager(logPath);
}
protected bool ValidateRoles(params string[]roles)
{
try
{
List<Predicate<Claim>> predicates = new List<Predicate<Claim>>();
List<string> roleList= roles.ToList();
roleList.ForEach(role=> predicates.Add(claim => claim.Value == role));
this.RequiresClaims(predicates.ToArray());
}
catch (Exception)
{
return false;
}
return true;
}
}
}