85 lines
2.3 KiB
C#
85 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using WcfServiceAuthentication;
|
|
|
|
namespace DeiNiu.wms.Logical
|
|
{
|
|
public class ConstAuthourity
|
|
{
|
|
|
|
protected static log4net.ILog log = log4net.LogManager.GetLogger("logCommon");
|
|
|
|
public static Dictionary<int, int> userKeyPares = new Dictionary<int, int>();
|
|
public static Dictionary<int, List<string>> userSpecialAuths = new Dictionary<int, List<string>>() ;
|
|
|
|
public static List<string> getAuthorities(int userId)
|
|
{
|
|
|
|
int randomCode = 0;
|
|
if(AuthenticationInspector.tmpCodes.ContainsKey(userId))
|
|
{
|
|
|
|
randomCode = AuthenticationInspector.tmpCodes[userId];
|
|
if (randomCode == 0)
|
|
{
|
|
return new List<string>();
|
|
}
|
|
}
|
|
|
|
foreach (int key in userKeyPares.Keys)
|
|
{
|
|
if(userKeyPares[key] == randomCode)
|
|
{
|
|
userKeyPares[key] = getRandom();
|
|
return userSpecialAuths[key];
|
|
}
|
|
}
|
|
return new List<string>();
|
|
}
|
|
|
|
public static void setSpecialAuths(int userId, List<string> specialAuths)
|
|
{
|
|
userKeyPares[userId] = getRandom();
|
|
|
|
userSpecialAuths[userId] = specialAuths;
|
|
}
|
|
|
|
|
|
private static int getRandom()
|
|
{
|
|
return new Random().Next(1000, 9000);
|
|
}
|
|
|
|
public static bool havePermission(int userId,string permission)
|
|
{
|
|
log.Debug(" to check temp token authorition, userid is " + userId);
|
|
foreach (int key in AuthenticationInspector.tmpCodes.Keys)
|
|
{
|
|
log.Debug(String.Format("temp token authorition: userId {0}, tmpToken {1}", key, AuthenticationInspector.tmpCodes[key]));
|
|
}
|
|
foreach (int key in userKeyPares.Keys)
|
|
{
|
|
log.Debug(String.Format("userKeypares : userId {0}, tmpToken {1}", key, userKeyPares[key]));
|
|
}
|
|
|
|
|
|
|
|
return userSpecialAuths.ContainsKey(userId) && userSpecialAuths[userId].Contains(permission)
|
|
||getAuthorities(userId).Contains(permission);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
} |