public static bool CheckToken(string userName, string tokenValue, string ipAddress, string method, bool refreshToken, out HTTPCheckRoles role) { role = 0; ExpireAllTokensForUser(userName); CriticalResultsEntityManager manager = new CriticalResultsEntityManager(); TokenEntity[] tokens = manager.GetTokensForUser(userName); foreach (TokenEntity token in tokens) { if (token.Token == new Guid(tokenValue) && token.Ipv4 == ipAddress) { if (refreshToken) token.UpdatedTime = DateTime.Now; manager.SaveChanges(); foreach (RoleEntity re in token.User.Roles) { object r = Enum.Parse(typeof(HTTPCheckRoles), re.Name, true); if (r != null) { role |= (HTTPCheckRoles)r; } } return true; } } return false; }
public bool AccountConfirmation(string username) { CriticalResultsEntityManager manager = new CriticalResultsEntityManager(); UserEntity ue = manager.GetUser(username); if (!ue.UserTransports.IsLoaded) { ue.UserTransports.Load(); } foreach (UserTransportEntity ute in ue.UserTransports) { if (!ute.TransportReference.IsLoaded) { ute.TransportReference.Load(); } if (ute.Transport.Name == EMAIL_TRANSPORT && !String.IsNullOrEmpty(ute.Address)) { SystemMailer = new SystemEmailer(); SettingEntity[] settings = new CriticalResultsEntityManager().GetSettings("System"); string message = ""; foreach (SettingEntity setting in settings) { if (setting.EntryKey == "AccountConfirmationMessage") { message = setting.Value; } } message = String.Format(message, ue.UserName); BackgroundWorker bgw = new BackgroundWorker(); bgw.DoWork += new DoWorkEventHandler(bgw_DoWork); bgw.RunWorkerAsync(message + "|" + ute.Address); } } return true; }
protected void Page_Load(object sender, EventArgs e) { WindowsUser = Request.LogonUserIdentity.Name; string queryString = string.Format("it.Type='AuthExt' AND it.Key='{0}' AND it.Value='{1}'", AuthExtName, WindowsUser); CriticalResults.CriticalResultsEntityManager manager = new CriticalResultsEntityManager(); CriticalResults.UserEntryEntity [] entries = manager.QueryUserEntryEntities(queryString, null, null); string userHostAddress = Utilities.GetIP4Address(); if (entries.Count() == 1) { if (entries.First().User.Enabled == true) { UserName = entries.First().User.UserName; Session["UserName"] = UserName; CriticalResults.TokenEntity[] currentTokens = manager.GetTokensForUser(UserName); foreach (CriticalResults.TokenEntity t in currentTokens) { if (t.Ipv4 == userHostAddress) { TokenGuid = t.Token.ToString(); Session["Token"] = TokenGuid.ToString(); } } if (TokenGuid == "") { CriticalResults.TokenEntity token = manager.CreateToken(entries.First().User, userHostAddress); TokenGuid = token.Token.ToString(); Session["Token"] = TokenGuid.ToString(); } Response.AddHeader("REFRESH", "5;URL=ResultList.aspx"); } else { PageMessage = "The ANCR account associated with this Windows Login " + WindowsUser + " is disabled. Please contact your System Administrator."; message.InnerText = PageMessage; } } else if(entries.Count() > 1) { PageMessage = "Multiple ANCR accounts resolved to this Windows User. Until this is resolved you may not login with your Windows User Account. Please contact your System Administrator."; message.InnerText = PageMessage; } else { PageMessage = "No ANCR account can be found for " + WindowsUser + ". Please contact your System Administrator."; message.InnerText = PageMessage; } }
public static int Run() { CriticalResultsEntityManager manager = new CriticalResultsEntityManager(); ResultEntity [] results = manager.QueryResultEntity("", null, null); foreach (ResultEntity result in results) { if (!result.ResultContexts.IsLoaded) { result.ResultContexts.Load(); } if (result.ResultContexts.Count() != 1) { Console.Write("-yowza!-"); } else { ResultContextEntity context = result.ResultContexts.First(); if (string.IsNullOrEmpty(context.PatientKey) && string.IsNullOrEmpty(context.ExamKey)) { RadiologyContext ctx = Newtonsoft.Json.JsonConvert.DeserializeObject<RadiologyContext>(result.ResultContexts.First().JsonValue); context.PatientKey = ctx.MRN.value; context.ExamKey = ctx.Accession.value; Console.Write("-change-"); } else { Console.Write("-good-"); } } } manager.ObjectContext.SaveChanges(); return results.Count(); }
public Level CreateLevel(Level level) { _Trace.TraceEvent(TraceEventType.Verbose, -1, "CreateLevel"); CriticalResultsEntityManager manager = new CriticalResultsEntityManager(); LevelEntity entity = manager.CreateLevel(level.Name, level.Description, level.ShortDescription, level.ColorValue, level.EscalationTimeout, level.DueTimeout, level.DirectContactRequired); if (level.Transports != null) { foreach(Transport t in level.Transports){ bool mandatory = false; foreach(Transport mT in level.MandatoryTransports) { if(mT.Name == t.Name) { mandatory = true; } } manager.CreateTransportLevelEntity(entity.Uuid, t.Name, mandatory); } UserEntity[] ues = manager.GetAllUsers(); entity.TransportLevels.Load(); foreach (UserEntity ue in ues) { ue.UserTransports.Load(); foreach (UserTransportEntity te in ue.UserTransports) { foreach (TransportLevelEntity t in entity.TransportLevels) { if (te.Transport != null) { if (t.Transport.Name == te.Transport.Name) { te.Levels.Add(entity); } } } } } manager.SaveChanges(); } return new Level(entity); }
public ContextType[] GetAllContextTypes() { _Trace.TraceEvent(TraceEventType.Verbose, -1, "GetAllContextTypes"); ContextTypeEntity[] entities = new CriticalResultsEntityManager().GetAllContextTypes(); List<ContextType> types = new List<ContextType>(); foreach (ContextTypeEntity e in entities) { ContextType t = new ContextType(e); types.Add(t); } return types.ToArray(); }
public static bool Authenticate(string authKey, string authValue, string userName, string userIP, TraceSource _Trace, out string outUserName, out string tokenString, out string message) { outUserName=""; tokenString = ""; CriticalResults.CriticalResultsEntityManager manager = new CriticalResultsEntityManager(); bool hasPassword = false; string queryString = string.Format("it.Type='AuthExt' AND it.Key='{0}' AND it.Value='{1}'", authKey, authValue); // if userName is specified then we go from ANCR and authValue is password, overwise authValue is username of already authenticated user if (userName != null) { hasPassword = true; UserEntity user = manager.GetUser(userName); if (user == null) { message = "Invalid username or password."; return false; } queryString = string.Format("it.Type='AuthExt' AND it.Key='{0}' AND it.Value='{1}' AND it.User.Id={2}", authKey, authValue, user.Id); } CriticalResults.UserEntryEntity[] entries = manager.QueryUserEntryEntities(queryString, null, null); if (entries.Count() == 1) { UserEntity user=entries.First().User; if (!hasPassword) { _Trace.TraceEvent(TraceEventType.Information, 0, "Lookup for username \"{0}\" mapped to \"{1}\".", authValue, user.UserName); } if (user.Enabled == true) { outUserName = user.UserName; CriticalResults.TokenEntity[] currentTokens = manager.GetTokensForUser(user.UserName); foreach (CriticalResults.TokenEntity t in currentTokens) { if (t.Ipv4 == userIP) { t.UpdatedTime = DateTime.Now; manager.SaveChanges(); tokenString = t.Token.ToString(); message = ""; return true; } } CriticalResults.TokenEntity token = manager.CreateToken(user, userIP); tokenString = token.Token.ToString(); message = ""; return true; } else { _Trace.TraceEvent(TraceEventType.Warning, 0, "Found user \"{0}\" mapped to \"{1}\". ANCR Account disabled.", authValue, user.UserName); message = "Your account is disabled. Please contact your System Administrator."; return false; } } else { if (entries.Count() > 1) { _Trace.TraceEvent(TraceEventType.Warning, 0, "Found multiple users \"{0}\" (Count: {1})", authValue, entries.Count()); message = "Multiple ANCR users found for your username, until this is resolved you may not login with your credentials. Please contact your System Administrator."; } else { if (hasPassword) { _Trace.TraceEvent(TraceEventType.Warning, 0, "Invalid username or password \"{0}\"", userName); message = "Invalid username or password."; } else { _Trace.TraceEvent(TraceEventType.Warning, 0, "No ANCR account found for \"{0}\"", authValue); message = "No ANCR user is found for your credentials. Please contact your System Administrator."; } } return false; } }
public Acknowledgment GetResultAcknowledgment(string resultUuid) { _Trace.TraceEvent(TraceEventType.Verbose, -1, "GetResultAcknowledgment"); Guid guid = new Guid(resultUuid); CriticalResultsEntityManager manager = new CriticalResultsEntityManager(); AcknowledgmentEntity e = manager.GetResultAcknowledgment(guid); if (e == null) return new Acknowledgment(); Acknowledgment ack = new Acknowledgment(e); ack.ResolveUser(); ack.ResolveResult(); return ack; }
public Setting[] GetSettings_NonWeb(string owner) { SettingEntity[] entities = new CriticalResultsEntityManager().GetSettings(owner); List<Setting> s = new List<Setting>(); foreach (SettingEntity e in entities) { s.Add(new Setting(e)); } return s.ToArray(); }
public User[] GetAllUsers() { _Trace.TraceEvent(TraceEventType.Verbose, -1, "GetAllUsers"); UserEntity[] entities = new CriticalResultsEntityManager().GetAllUsers(); List<User> users = new List<User>(); foreach (UserEntity e in entities) { User u = new User(e); u.ResolveRoles(); users.Add(u); } return users.ToArray(); }
public Notification[] GetNotifications(string notificationStateName, string startDateRangeString, string endDateRangeString) { //CheckHTTPBasicAuth(); _Trace.TraceEvent(TraceEventType.Verbose, -1, "GetNotifications"); string queryString = string.Format("it.State = '{0}'", notificationStateName); if (!string.IsNullOrEmpty(startDateRangeString)) { DateTime startDateRange = DateTime.Parse(startDateRangeString); queryString += string.Format(" AND it.CreationTime > DATETIME'{0}'", startDateRange.ToString("yyyy-MM-dd hh:mm")); } if (!string.IsNullOrEmpty(endDateRangeString)) { DateTime endDateRange = DateTime.Parse(endDateRangeString); queryString += string.Format(" AND it.CreationTime < DATETIME'{0}'", endDateRange.ToString("yyyy-MM-dd hh:mm")); } NotificationEntity[] entities = new CriticalResultsEntityManager().QueryNotificationEntity(queryString, null, null); List<Notification> results = new List<Notification>(); foreach (NotificationEntity entity in entities) { Notification n = new Notification(entity); n.ResolveResult(); n.Result.ResolveSender(); n.ResolveUserTransport(); n.UserTransport.ResolveTransport(); n.UserTransport.ResolveUser(); results.Add(n); } return results.ToArray() ; }
/// <summary> /// Add a transport to all users /// Created: 2009-07-27 John Morgan /// </summary> /// <param name="transportName"></param> /// <returns></returns> private bool AddUsersToTransport(string transportName) { CriticalResultsEntityManager manager = new CriticalResultsEntityManager(); UserEntity[] users = manager.GetAllUsers(); foreach (UserEntity user in users) { manager.CreateUserTransport(user.UserName, transportName, ""); } return true; }
public Role[] GetAllRoles() { RoleEntity[] roleEntities = new CriticalResultsEntityManager().GetAllRoles(); List<Role> roles = new List<Role>(); foreach (RoleEntity entity in roleEntities) { roles.Add(new Role(entity)); } return roles.ToArray(); }
/// <summary> /// Adds all available transports to a user with address to be filled out later. /// Created: 2009-07-28, John Morgan /// Modified: 2009-08-13, John Morgan /// Altered to only add transports that do not exist /// </summary> /// <param name="userName"></param> /// <returns>UserEntity</returns> private UserEntity AddTransportsToUser(string userName) { CriticalResultsEntityManager manager = new CriticalResultsEntityManager(); TransportEntity[] transports = manager.GetAllTransports(); UserEntity user = manager.GetUser(userName); foreach (TransportEntity transport in transports) { bool transportFound = false; foreach (UserTransportEntity t in user.UserTransports) { if (t.Transport.Name == transport.Name) transportFound = true; } if(!transportFound) manager.CreateUserTransport(userName, transport.Name, ""); } return manager.GetUser(userName); }
public User CreateANCRUser(User user) { CriticalResultsEntityManager manager = new CriticalResultsEntityManager(); UserEntity userEntity = manager.CreateUserEntity(user.ToEntity()); AuditEvent("CreateUser:Success", user.UserName); LevelEntity[] levels = manager.GetLevels(); List<string> levelNames = new List<string>(); foreach (LevelEntity level in levels) { levelNames.Add(level.Name); } TransportEntity[] transports = manager.GetAllTransports(); foreach (TransportEntity transport in transports) { bool addTransport = true; foreach (UserTransportEntity userTransport in userEntity.UserTransports) { if (userTransport.Transport.Name == transport.Name) { addTransport = false; } } if (addTransport) { if (user.Transports != null) { bool transportFound = false; for (int i = 0; i < user.Transports.Length; i++) { if (user.Transports[i].Transport.Name == transport.Name) { if (user.Transports[i].Address == null) { user.Transports[i].Address = ""; } manager.CreateUserTransport(userEntity.UserName, transport.Name, user.Transports[i].Address); manager.UpdateLevelsToUserTransport(user.UserName, transport.Name, user.Transports[i].Address, levelNames.ToArray()); transportFound = true; } } if (!transportFound) { manager.CreateUserTransport(userEntity.UserName, transport.Name, ""); manager.UpdateLevelsToUserTransport(user.UserName, transport.Name, "", levelNames.ToArray()); } } else { manager.CreateUserTransport(userEntity.UserName, transport.Name, ""); manager.UpdateLevelsToUserTransport(user.UserName, transport.Name, "", levelNames.ToArray()); } } } userEntity = manager.GetUser(user.UserName); //bool passwordFound = false; //foreach (UserEntryEntity uee in e.UserEntries) //{ // if (uee.Type == "AuthExt" && uee.Key == "ANCR") // passwordFound = true; //} //if(!passwordFound) // GeneratePassword(user.UserName); User u = new User(userEntity); u.ResolveRoles(); u.ResolveTransports(); u.ResolveEntries(); return u; }
public User UserEntry(string userName, string type, string key, string value, string xmlValue) { UserEntryEntity uee = new CriticalResultsEntityManager().CreateUserEntryEntity(userName, type, key, value, xmlValue, false); User u = GetUser_NonWeb(userName); return u; }
public UserTransport UpdateUserTransport(string userName, string transportName, string originalAddress, string address) { HTTPBasicCheckAttribute.AdditionalCheck(userName, HTTPCheckRoles.sysAdmin | HTTPCheckRoles.clinAdmin); UserTransportEntity ute = new CriticalResultsEntityManager().UpdateUserTransport(userName, transportName, originalAddress, address); UserTransport ut = new UserTransport(ute); ut.ResolveTransport(); ut.ResolveLevels(); return ut; }
public bool UpdateUserRoles(string userName, string[] roleNames) { CriticalResultsEntityManager manager = new CriticalResultsEntityManager(); manager.UpdateUserRoles(userName, roleNames); return true; }
public Setting[] GetAllSettings() { SettingEntity[] entities = new CriticalResultsEntityManager().GetAllSettings(); List<Setting> settings = new List<Setting>(); foreach (SettingEntity e in entities) { settings.Add(new Setting(e)); } return settings.ToArray(); }
public bool CreatePassword(string userName) { string password = Guid.NewGuid().ToString().Substring(0, 6); string passwordHash = BitConverter.ToString(HashAlgorithm.Create("SHA256").ComputeHash(Encoding.ASCII.GetBytes(password))).ToLower().Replace("-", ""); bool setPassSuccess = new CriticalResultsEntityManager().UpdateUserEntryEntity(userName, "AuthExt", "ANCR", passwordHash, true); if (setPassSuccess) { UserEntity user = new CriticalResultsEntityManager().GetUser(userName); foreach (UserTransportEntity transport in user.UserTransports) { if (transport.Transport.Name == EMAIL_TRANSPORT && !String.IsNullOrEmpty(transport.Address)) { SystemMailer = new SystemEmailer(); BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += new DoWorkEventHandler(worker_DoWork); worker.RunWorkerAsync(transport.Address + "|" + password); } } } return setPassSuccess; }
public Level[] GetLevels() { _Trace.TraceEvent(TraceEventType.Verbose, -1, "GetAllLevels"); LevelEntity[] entities = new CriticalResultsEntityManager().GetLevels(); List<Level> levels = new List<Level>(); foreach (LevelEntity entity in entities) { Level level = new Level(entity); level.ResolveTransports(); levels.Add(level); } return levels.ToArray(); }
public Acknowledgment CreateResultAcknowledgment(string resultUuid, string userName, string notes) { _Trace.TraceEvent(TraceEventType.Verbose, -1, "CreateResultAcknowledgment"); AcknowledgmentEntity e = new CriticalResultsEntityManager().CreateAcknowledgment(new Guid(resultUuid), userName, notes); Acknowledgment ack = new Acknowledgment(e); ack.ResolveResult(); ack.ResolveUser(); AuditEvent("AcknowledgeResult:Success", string.Format("{0}; {1}", resultUuid, userName)); return ack; }
public Result GetResult(string uuid) { _Trace.TraceEvent(TraceEventType.Verbose, (int)ResultEvents.GetResult, ResultEvents.GetResult.ToString()); ResultEntity e = new CriticalResultsEntityManager().GetResultEntity(new Guid(uuid)); Result r = new Result(e); bool ok; ok = r.ResolveSender(); ok = r.ResolveReceiver(); ok = r.ResolveLevel(); ok = r.Level.ResolveTransports(); ok = r.ResolveContext(); return r; }
public Notification CreateResultNotification(Notification notification, string selectedTransport) { _Trace.TraceEvent(TraceEventType.Verbose, -1, "CreateResultNotification"); CriticalResultsEntityManager crm = new CriticalResultsEntityManager(); NotificationEntity e = new NotificationEntity(); e.Notes = notification.Notes; e.CreationTime = DateTime.Now; e.State = notification.State; e.Result = crm.GetResultEntity(notification.Result.Uuid); e.UserTransport = crm.GetUserTransport(notification.Result.Receiver.UserName, selectedTransport); NotificationEntity ne = crm.CreateResultNotification(e); return new Notification(ne); }
public Notification[] GetResultNotifications(string resultUuid) { _Trace.TraceEvent(TraceEventType.Verbose, -1, "GetResultNotifications"); Guid guid = new Guid(resultUuid); NotificationEntity[] entities = new CriticalResultsEntityManager().GetResultNotifications(guid); List<Notification> notifications = new List<Notification>(); foreach (NotificationEntity entity in entities) { Notification n = new Notification(entity); n.ResolveUserTransport(); n.UserTransport.ResolveTransport(); notifications.Add(n); } return notifications.ToArray(); }
public Transport CreateTransport(string name, string transportUri, string friendlyName) { TransportEntity entity = new CriticalResultsEntityManager().CreateTransport(name, transportUri, friendlyName); Transport transport = new Transport(entity); AddUsersToTransport(transport.Name); return transport; }
public Transport[] GetTransports() { TransportEntity[] entities = new CriticalResultsEntityManager().GetAllTransports(); List<Transport> transports = new List<Transport>(); foreach (TransportEntity entity in entities) { Transport transport = new Transport(entity); transport.ResolveLevels(); transports.Add(transport); } return transports.ToArray(); }
public UserEntry CreateUpdateUserEntry(string userName, string type, string key, string value, string xmlValue) { HTTPBasicCheckAttribute.AdditionalCheck(userName, HTTPCheckRoles.sysAdmin | HTTPCheckRoles.clinAdmin); UserEntryEntity ue = new CriticalResultsEntityManager().CreateUpdateUserEntryEntity(userName, type, key, value, xmlValue, false); return new UserEntry(ue); }
public void LoadSettingsFromDatabase() { CriticalResultsEntityManager manager = new CriticalResultsEntityManager(); SettingEntity[] settings = manager.GetSettings("System"); string host = null; int port = 587; string userName = ""; string password = ""; string domain = ""; bool useSsl = false; string fromAddress = null; string fromName = "Critical Results"; foreach (SettingEntity setting in settings) { switch (setting.EntryKey) { case "SMTP_AccountName": if (!String.IsNullOrEmpty(setting.Value)) { userName = setting.Value; } break; case "SMTP_AccountPassword": if (!String.IsNullOrEmpty(setting.Value)) { password = setting.Value; } break; case "SMTP_AccountDomain": if (!String.IsNullOrEmpty(setting.Value)) { domain = setting.Value; } break; case "SMTP_UseSSL": if (!String.IsNullOrEmpty(setting.Value)) { bool.TryParse(setting.Value, out useSsl); } break; case "SMTP_ServerIP": if (!String.IsNullOrEmpty(setting.Value)) { host = setting.Value; } break; case "SMTP_ServerPort": if (!String.IsNullOrEmpty(setting.Value)) { port = Int32.Parse(setting.Value); } break; case "SMTP_FromAddress": if (!String.IsNullOrEmpty(setting.Value)) { fromAddress = setting.Value; } break; case "SMTP_FromName": if (!String.IsNullOrEmpty(setting.Value)) { fromName = setting.Value; } break; } } //_Mailer = new SimpleEmailer(host, port, userName, password, domain, useSsl, fromAddress, fromName); _Mailer = new SimpleEmailer(host, port, userName, password, domain, useSsl, fromAddress, fromName); }
public UserTransport CreateUserTransport(string userName, string transportName, string address) { HTTPBasicCheckAttribute.AdditionalCheck(userName, HTTPCheckRoles.sysAdmin | HTTPCheckRoles.clinAdmin); UserTransportEntity ute = new CriticalResultsEntityManager().CreateUserTransport(userName, transportName, address); return new UserTransport(ute); }