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 userKeyPares = new Dictionary(); public static Dictionary> userSpecialAuths = new Dictionary>() ; public static List getAuthorities(int userId) { int randomCode = 0; if(AuthenticationInspector.tmpCodes.ContainsKey(userId)) { randomCode = AuthenticationInspector.tmpCodes[userId]; if (randomCode == 0) { return new List(); } } foreach (int key in userKeyPares.Keys) { if(userKeyPares[key] == randomCode) { userKeyPares[key] = getRandom(); return userSpecialAuths[key]; } } return new List(); } public static void setSpecialAuths(int userId, List 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); } } }