protected override bool OnAuthorizeUser(string identifier, string password, HttpActionContext context) { if (!base.OnAuthorizeUser(identifier, password, context)) { return(false); } bool withSimpleAdminAuth = ConfigurationManagerHelper.GetValue <bool>("WebApi.WithSimpleAdminAuth"); if (withSimpleAdminAuth) { string adminIdentifier = ConfigurationManagerHelper.GetValue <string>("WebApi.AdminIdentifier"); string adminPassword = ConfigurationManagerHelper.GetValue <string>("WebApi.AdminPassword"); if (identifier == adminIdentifier && password == adminPassword) { return(true); } } // Authentication from database (the user must be registered in the database and have 'Admin' role). var user = new CustomUserValidator().GetUserWithRoles(identifier, password); return(user != null && user.UserRoleCollection.Select(ur => ur.Role).Any(r => r.CodeRef == Role.CodeRefs.Admin)); }
static void Main(string[] args) { if (!SetConsoleCtrlHandler(ConsoleCtrlHandler, true)) { Console.WriteLine("无法注册系统事件!\n"); } ServiceHost host = new ServiceHost(typeof(UserService).Assembly); var listeningOn = ConfigurationManagerHelper.GetValue("EIM_Service_Url"); host.Init().Start(listeningOn); host.Load(); Console.WriteLine("服务已启动。"); HostCommandHandler commandHandler = new HostCommandHandler(host); while (true) { string cmd = Console.ReadLine(); if (string.IsNullOrEmpty(cmd)) { continue; } if (cmd == "exit") { break; } try { commandHandler.Process(cmd); } catch (Exception ex) { Console.WriteLine(ex.Message); EIMLog.Logger.Error(ex.Message, ex); } } }