| 
									
										
										
										
											2023-09-04 22:41:19 +08:00
										 |  |  |  | using System; | 
					
						
							|  |  |  |  | using System.Collections.Generic; | 
					
						
							|  |  |  |  | using System.Linq; | 
					
						
							|  |  |  |  | using System.Web; | 
					
						
							|  |  |  |  | using WcfServiceAuthentication; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | namespace DeiNiu.wms.Logical | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     public class ConstAuthourity | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         protected static log4net.ILog log = log4net.LogManager.GetLogger("logCommon"); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-04 22:41:19 +08:00
										 |  |  |  |         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) | 
					
						
							|  |  |  |  |         { | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |            | 
					
						
							| 
									
										
										
										
											2023-09-04 22:41:19 +08:00
										 |  |  |  |             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) | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |         { | 
					
						
							|  |  |  |  |             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])); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |              | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-04 22:41:19 +08:00
										 |  |  |  |             return userSpecialAuths.ContainsKey(userId) && userSpecialAuths[userId].Contains(permission)  | 
					
						
							|  |  |  |  |                 ||getAuthorities(userId).Contains(permission); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |              | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |    | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | } |