/// <summary> /// Creates an agent /// </summary> /// <param name="agentType"></param> /// <param name="agentServerRef"></param> /// <returns></returns> public int Create(int agentTypeID, int agentServerID, bool enabled = false) { int agentID = -1; var agentType = new Securable <ObjectIdentifier>(new ObjectIdentifier { ArtifactID = agentTypeID }); var agentServer = new Securable <ObjectIdentifier>(new ObjectIdentifier { ArtifactID = agentServerID }); var agentToCreate = new AgentRequest() { AgentType = agentType, Enabled = enabled, Interval = 5, AgentServer = agentServer, Keywords = "Integration Test Agent", LoggingLevel = 1 }; using (var agentManager = _helper.GetServicesManager().CreateProxy <Relativity.Services.Interfaces.Agent.IAgentManager>(ExecutionIdentity.System)) { // Confirms an agent may be created List <AgentInstanceLimitResult> results = agentManager.ValidateCreateInstanceLimitAsync(-1, agentToCreate, 1).Result; foreach (var result in results) { Console.WriteLine(result.Limit.ToString()); } agentID = agentManager.CreateAsync(-1, agentToCreate).Result; } return(agentID); }
public void Initialize(int version) { string updObjectId = "fb52e98c-8369-4a8b-86ab-69a166fd29c3"; var sec = new Securable[] { new Securable { Id = ObjectId.GenerateNewId(), SecuredItem = SecurableEnum.Patients, Name = "Patients", AssignedPermissions = new SecurablePermission[] { new SecurablePermission { Permission = PermissionOption.Add }, new SecurablePermission { Permission = PermissionOption.Remove }, new SecurablePermission { Permission = PermissionOption.Update }, new SecurablePermission { Permission = PermissionOption.View }, } }, }; foreach (var item in sec) { var menuI = _context.GetAll().Where(arg => arg.Name == item.Name).FirstOrDefault(); if (menuI == null) { item.UserSign = updObjectId; item.CreateDate = DateTime.Now; item.UpdateDate = DateTime.Now; item.Status = "A"; foreach (var p in item.AssignedPermissions) { p.UserSign = updObjectId; p.SecurableId = item.Id; p.Id = ObjectId.GenerateNewId(); p.CreateDate = DateTime.Now; p.UpdateDate = DateTime.Now; p.Status = "A"; } _context.Add(item, updObjectId); } } }
public void Update(int agentID, int agentTypeID, int agentServerID, bool enabled = true) { var agentType = new Securable <ObjectIdentifier>(new ObjectIdentifier { ArtifactID = agentTypeID }); var agentServer = new Securable <ObjectIdentifier>(new ObjectIdentifier { ArtifactID = agentServerID }); var request = new AgentRequest { Enabled = enabled, AgentServer = agentServer, AgentType = agentType, LoggingLevel = 1, Interval = 5 }; using (var agentManager = _helper.GetServicesManager().CreateProxy <Relativity.Services.Interfaces.Agent.IAgentManager>(ExecutionIdentity.System)) { agentManager.UpdateAsync(-1, agentID, request).Wait(); } }
internal static void SetupImp() { ModelUser mu = new ModelUser("Everyone"); if (!mu.Exists) { mu.PasswordHash = null; mu.Enabled = false; mu.Create(); ModelUserRights ur = new ModelUserRights("owner", "Everyone"); ur.Create(); } Securable s = new Securable(typeof(ApplicationExceptionSecureService).FullName); if (!s.Exists) { // Default configuration - the safe way. s.TimeSessionIsIssued = 20; s.AllowAnonymousAccess = true; s.Enabled = true; s.GenerationPasswordLength = 6; s.AllowedIPFailures = 10; s.IPsMustBePreregistered = false; s.IPFailureTimeDenying = 60; s.DisableIPFiltering = false; s.SessionsPerIPAllowed = 2; s.Create(); } }
internal static void RegisterIPFailureImp(Securable s, IPRegistered ipr) { ipr.Failures = ipr.Failures + 1; if (ipr.Failures >= s.AllowedIPFailures) { ipr.Allowed = false; ipr.DenialIssuedUntilTime = DateTime.Now.AddMinutes(s.IPFailureTimeDenying); } ipr.Update(); }
internal static string LoginImp(string userName, string password) { SetupImp(); if (System.Web.HttpContext.Current != null) { Securable s = new Securable(typeof(ApplicationExceptionSecureService).FullName); IPRegistered ipr = new IPRegistered(System.Web.HttpContext.Current.Request.UserHostAddress); ipr = AddIPImp(s); // ipr.SessionsCreated = ipr.SessionsCreated + 1; // ipr.Update(); // IPSessionRegistration CheckIPImp(s, ipr); } ModelSession ms = new ModelSession(GenerateSessionTokenImp()); CreateSessionImp(ref ms, userName, password); return ms.SessionToken; }
internal static string LoginAnonymousImp() { SetupImp(); Securable s = new Securable(typeof(ApplicationExceptionSecureService).FullName); if (!s.AllowAnonymousAccess) return null; if (System.Web.HttpContext.Current != null) { IPRegistered ipr = new IPRegistered(System.Web.HttpContext.Current.Request.UserHostAddress); ipr = AddIPImp(s); // ipr.SessionsCreated = ipr.SessionsCreated + 1; // ipr.Update(); // IPSessionRegistration CheckIPImp(s, ipr); } ModelSession ms = new ModelSession(GenerateSessionTokenImp()); ms.User = new ModelUser("Everyone"); ms.TimeIssued = DateTime.Now; ms.TimeIssuedFor = s.TimeSessionIsIssued; ms.Create(); return ms.SessionToken; }
internal static Securable GetSecurableImp(string SessionToken) { SetupImp(); ModelSession session = CheckSessionImp(SessionToken); if (CheckUserRightsImp(session.User.Name, "ManageApplication")) { Securable s = new Securable(typeof(ApplicationExceptionSecureService).FullName); return s; } throw new UnauthorizedAccessException("Access Denied"); }
internal static string GeneratePasswordImp() { char[] allowedCharacters = "qwertyuiopasdfghjklzxcvbnm1234567890-=!@#$%^&*()_+".ToCharArray(); List<char> characterList = new List<char>(); Random random = new Random(); SetupImp(); Securable s = new Securable(typeof(ApplicationExceptionSecureService).FullName); for (int n = 0; n < s.GenerationPasswordLength; ++n) { characterList.Add(allowedCharacters[random.Next(0, allowedCharacters.Length)]); } return new String(characterList.ToArray()); }
internal static void EnableDisableSecurityImp(bool secure, string sessionToken) { ModelSession session = CheckSessionImp(sessionToken); // Check access "TakeSecurityOffline" if (!CheckUserRightsImp(session.User.Name, "TakeSecurityOffline")) throw new UnauthorizedAccessException("Access Denied"); Securable s = new Securable(typeof(ApplicationExceptionSecureService).FullName); s.Enabled = secure; s.Update(); }
internal static void CreateSessionImp(ref ModelSession ms, string userName, string password) { if (userName.ToLowerInvariant() == "everyone") throw new InvalidOperationException("Wrong API call for anonymous access."); Securable s = new Securable(typeof(ApplicationExceptionSecureService).FullName); ModelUser mu = new ModelUser(userName); if (!mu.Exists) { if (System.Web.HttpContext.Current != null) { IPRegistered ipr = new IPRegistered(System.Web.HttpContext.Current.Request.UserHostAddress); RegisterIPFailureImp(s, ipr); } throw new UnauthorizedAccessException("Access Denied"); } if (!Platform.Runtime.Security.Hash.VerifyHash(password, "SHA512", mu.PasswordHash)) { if (System.Web.HttpContext.Current != null) { IPRegistered ipr = new IPRegistered(System.Web.HttpContext.Current.Request.UserHostAddress); RegisterIPFailureImp(s, ipr); } throw new UnauthorizedAccessException("Access Denied"); } if (!mu.Enabled && !ApplicationExceptionSecureService.CheckUserRightsImp(userName, "CannotBeDisabled")) { if (System.Web.HttpContext.Current != null) { IPRegistered ipr = new IPRegistered(System.Web.HttpContext.Current.Request.UserHostAddress); RegisterIPFailureImp(s, ipr); } throw new UnauthorizedAccessException("Access Denied"); // LoginDisabledException } ms.User = mu; ms.TimeIssued = DateTime.Now; ms.TimeIssuedFor = s.TimeSessionIsIssued; ms.Create(); }
internal static ModelSession CheckSessionImp(string sessionToken) { // Mark IP first Securable s = null; IPRegistered ipr = null; if (System.Web.HttpContext.Current != null) { s = new Securable(typeof(ApplicationExceptionSecureService).FullName); ipr = new IPRegistered(System.Web.HttpContext.Current.Request.UserHostAddress); CheckIPImp(s, ipr); } else { // What other unique data can be gathered? } if (String.IsNullOrEmpty(sessionToken)) { // Invalid data is a security error if (s != null) RegisterIPFailureImp(s, ipr); throw new UnauthorizedAccessException("The session is invalid"); } // Check the consistency of the session ModelSession session = new ModelSession(sessionToken.ToLowerInvariant()); if (!session.Exists) { if (s != null) RegisterIPFailureImp(s, ipr); throw new UnauthorizedAccessException("The session is invalid"); } if (session.User == null) { if (s != null) RegisterIPFailureImp(s, ipr); session.Delete(); throw new UnauthorizedAccessException("The session is invalid"); } DateTime until = session.TimeIssued.AddMinutes(session.TimeIssuedFor); if (until < DateTime.Now) { session.Delete(); throw new UnauthorizedAccessException("Your session has expired"); } return session; }
internal static void CheckIPImp(Securable s, IPRegistered ipr) { if (!ipr.Exists) { throw new UnauthorizedAccessException("IP has not been authenticated in any way"); } if (!ipr.Allowed && ipr.DenialIssuedUntilTime >= DateTime.Now) { throw new UnauthorizedAccessException("IP has been blocked until " + ipr.DenialIssuedUntilTime.ToString() + " (Server time)"); } else if (!ipr.Allowed) { ipr.Allowed = true; ipr.Failures = 0; ipr.Update(); } else { ipr.DenialIssuedUntilTime = DateTime.Now; ipr.Update(); } // Very expensive /*if (!ipr.SessionsRegisteredOnIP.Count >= s.SessionsPerIPAllowed) { // Check how many are valid (also clean up the expired ones) throw new UnauthorizedAccessException("Too many sessions"); }*/ }
internal static IPRegistered AddIPImp(Securable s) { IPRegistered ipr = null; if (System.Web.HttpContext.Current != null) { ipr = new IPRegistered(System.Web.HttpContext.Current.Request.UserHostAddress); if (!ipr.Exists) { if (!s.IPsMustBePreregistered) { ipr.Allowed = true; ipr.DenialIssuedUntilTime = DateTime.Now; ipr.Create(); } else throw new UnauthorizedAccessException("Your IP is not registered in our allowed range"); } else { CheckIPImp(s, ipr); } } return ipr; }
protected override void Seed(StaticVoid.Blog.Data.BlogContext context) { #if DEBUG #if !DISABLE_SEED // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. var admin = new User { Id = 1, ClaimedIdentifier = "", Email = "*****@*****.**", FirstName = "Luke", LastName = "McGregor", IsAuthor = true }; context.Users.AddOrUpdate(admin); var blogCreatorSecurable = new Securable { Name = "Blog Creator", Members = new List <User> { admin } }; context.Securables.AddOrUpdate(blogCreatorSecurable); if (!context.Blogs.Any()) { var blog = new Data.Blog { AuthoritiveUrl = "http://*****:*****@staticv0id", Style = new Style { Css = @".test{ }" }, AuthorSecurable = new Securable { Name = "Author : StaticVoid - Test" } }; context.Blogs.AddOrUpdate(blog); } var postDate = new DateTime(2012, 10, 7, 12, 0, 0); context.Posts.AddOrUpdate( new Post { Id = 1, AuthorId = 1, Title = "First Post", Body = "First Post!", Posted = postDate, Status = PostStatus.Published, Path = PostHelpers.MakeUrl(postDate.Year, postDate.Month, postDate.Day, "First Post"), Canonical = "/" + PostHelpers.MakeUrl(postDate.Year, postDate.Month, postDate.Day, "First Post") }); postDate = postDate.AddDays(1); context.Posts.AddOrUpdate( new Post { Id = 2, AuthorId = 1, Title = "Second Post", Body = "Second Post!", Posted = postDate, Status = PostStatus.Published, Path = PostHelpers.MakeUrl(postDate.Year, postDate.Month, postDate.Day, "Second Post"), Canonical = "/" + PostHelpers.MakeUrl(postDate.Year, postDate.Month, postDate.Day, "Second Post") }); #endif #endif }