Ejemplo n.º 1
0
        public void SetServicePolicy(Guid serviceId, ServicePolicy servicePolicy)
        {
            GetDirectoryClient().SetServicePolicy(serviceId, servicePolicy);

            // clear the service policy so we don't accidentally inspect data we just sent.
            _loadedServicePolicy = null;
        }
Ejemplo n.º 2
0
        public void SetServicePolicy(Guid serviceId, ServicePolicy servicePolicy)
        {
            _orgClient.SetServicePolicy(serviceId, servicePolicy);

            // clear the service policy so we don't accidentally inspect data we just sent.
            _loadedServicePolicy = null;//new ServicePolicy();
        }
Ejemplo n.º 3
0
 public PolicyController()
 {
     _policyServices  = new ServicePolicy();
     _auditLogService = new ServiceAuditLog();
     _userId          = Convert.ToInt32(((ClaimsIdentity)User.Identity).Claims.Where(c => c.Type == "user_id")
                                        .Select(c => c.Value).SingleOrDefault());
 }
Ejemplo n.º 4
0
        public void ToTransport_Variant4()
        {
            var servicePolicy = new ServicePolicy(
                timeFences: new List <TimeFence>
            {
                new TimeFence(
                    "Weekend nights",
                    new List <DayOfWeek> {
                    DayOfWeek.Friday, DayOfWeek.Saturday
                },
                    20, 1,
                    23, 2,
                    "America/New_York"
                    )
            }
                );

            var result = servicePolicy.ToTransport();

            Assert.IsTrue(result.MinimumRequirements.Count == 0);
            Assert.IsTrue(result.Factors.Count == 1);
            Assert.IsTrue(result.Factors[0].Attributes.TimeFences.Count == 1);
            Assert.IsTrue(result.Factors[0].Attributes.TimeFences[0].Name == "Weekend nights");
            Assert.IsTrue(result.Factors[0].Attributes.TimeFences[0].Days.Count == 2);
            Assert.IsTrue(result.Factors[0].Attributes.TimeFences[0].Days[0] == "Friday");
            Assert.IsTrue(result.Factors[0].Attributes.TimeFences[0].Days[1] == "Saturday");
            Assert.IsTrue(result.Factors[0].Attributes.TimeFences[0].StartHour == 20);
            Assert.IsTrue(result.Factors[0].Attributes.TimeFences[0].EndHour == 23);
            Assert.IsTrue(result.Factors[0].Attributes.TimeFences[0].StartMinute == 1);
            Assert.IsTrue(result.Factors[0].Attributes.TimeFences[0].EndMinute == 2);
            Assert.IsTrue(result.Factors[0].Attributes.TimeFences[0].TimeZone == "America/New_York");
        }
Ejemplo n.º 5
0
 public ImportPolicy(DtoPolicyExport export)
 {
     _export        = export;
     _policyService = new ServicePolicy();
     _policy        = new EntityPolicy();
     _uow           = new UnitOfWork();
 }
Ejemplo n.º 6
0
        public void ToTransport_Variant3()
        {
            var servicePolicy = new ServicePolicy(
                locations: new List <Location>
            {
                new Location("john's house", 5.0, 100, 200),
                new Location("the middle of the pacific ocean", 10, 200, 500)
            }
                );

            var result = servicePolicy.ToTransport();

            Assert.IsTrue(result.MinimumRequirements.Count == 0);
            Assert.IsTrue(result.Factors.Count == 1);
            Assert.IsTrue(result.Factors[0].Factor == Sdk.Transport.Domain.AuthPolicy.FactorType.Geofence);
            Assert.IsTrue(result.Factors[0].Attributes.Locations.Count == 2);

            Assert.AreEqual(result.Factors[0].Attributes.Locations[0].Name, "john's house");
            Assert.AreEqual(result.Factors[0].Attributes.Locations[0].Radius, 5, 0.01);
            Assert.AreEqual(result.Factors[0].Attributes.Locations[0].Latitude, 100, 0.01);
            Assert.AreEqual(result.Factors[0].Attributes.Locations[0].Longitude, 200, 0.01);

            Assert.AreEqual(result.Factors[0].Attributes.Locations[1].Name, "the middle of the pacific ocean");
            Assert.AreEqual(result.Factors[0].Attributes.Locations[1].Radius, 10, 0.01);
            Assert.AreEqual(result.Factors[0].Attributes.Locations[1].Latitude, 200, 0.01);
            Assert.AreEqual(result.Factors[0].Attributes.Locations[1].Longitude, 500, 0.01);
        }
Ejemplo n.º 7
0
        public void ToTransport_Variant2()
        {
            var servicePolicy = new ServicePolicy(
                requireKnowledgeFactor: true
                );
            var result = servicePolicy.ToTransport();

            Assert.IsTrue(result.MinimumRequirements[0].Knowledge == 1);
            Assert.IsTrue(result.MinimumRequirements[0].Inherence == null);
            Assert.IsTrue(result.MinimumRequirements[0].Possession == null);
            Assert.IsTrue(result.MinimumRequirements[0].Any == null);
        }
Ejemplo n.º 8
0
        public void AutoArchivePolicies()
        {
            Logger.Debug("Policy Archive Started");
            var servicePolicy = new ServicePolicy();
            var allPolicies   = _uow.PolicyRepository.Get(x => !x.Archived);

            foreach (var policy in allPolicies)
            {
                if (policy.AutoArchiveType == EnumPolicy.AutoArchiveType.AfterXdays)
                {
                    int intArchiveDays;
                    if (!int.TryParse(policy.AutoArchiveSub, out intArchiveDays))
                    {
                        continue;
                    }

                    if (intArchiveDays <= 0)
                    {
                        continue;
                    }

                    var dateCutOff = DateTime.UtcNow - TimeSpan.FromDays(intArchiveDays);

                    if (policy.StartDate < dateCutOff && policy.StartDate > _utcCutoff)
                    {
                        servicePolicy.DeactivatePolicy(policy.Id);
                        servicePolicy.ArchivePolicy(policy.Id);
                    }
                }
                else if (policy.AutoArchiveType == EnumPolicy.AutoArchiveType.WhenComplete)
                {
                    var groupsWithThisPolicy = servicePolicy.GetPolicyGroups(policy.Id);
                    var memberIds            = new List <int>();
                    foreach (var group in groupsWithThisPolicy)
                    {
                        var groupMembers = new ServiceGroup().GetGroupMembers(group.Id);
                        memberIds.AddRange(groupMembers.Select(member => member.Id));
                    }
                    var distinctMembers = memberIds.Distinct().ToList();
                    if (!distinctMembers.Any())
                    {
                        continue;
                    }
                    var successCount = _uow.PolicyHistoryRepository.Get(x => x.PolicyId == policy.Id && x.Result == EnumPolicyHistory.RunResult.Success).ToList().GroupBy(x => x.ComputerId).Count();
                    if (successCount == distinctMembers.Count)
                    {
                        servicePolicy.DeactivatePolicy(policy.Id);
                        servicePolicy.ArchivePolicy(policy.Id);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public void ToTransport_Variant1()
        {
            var servicePolicy = new ServicePolicy(
                requiredFactors: 1,
                jailbreakDetection: true
                );
            var result = servicePolicy.ToTransport();

            Assert.IsTrue(result.Factors.Count == 1);
            Assert.IsTrue(result.Factors[0].Factor == Sdk.Transport.Domain.AuthPolicy.FactorType.DeviceIntegrity);
            Assert.IsTrue(result.MinimumRequirements.Count == 1);
            Assert.IsTrue(result.MinimumRequirements[0].Any == 1);
        }
Ejemplo n.º 10
0
        public ServicePolicy GetServicePolicy(Guid serviceId)
        {
            DomainPolicy.IPolicy legacyPolicy = GetAdvancedServicePolicy(serviceId);

            if (legacyPolicy.GetType() != typeof(DomainPolicy.LegacyPolicy))
            {
                Trace.TraceWarning($"Invalid policy type returned to legacy function. To utilize new policies please use GetAdvancedServicePolicy");
                return(null);
            }

            // This calls ToTransport because the parsing logic that is contained in the ServicePolicy class shouldn't be duplicated
            return(ServicePolicy.FromTransport((AuthPolicy)legacyPolicy.ToTransport()));
        }
Ejemplo n.º 11
0
 public ValidatePolicy()
 {
     _result                 = new DtoActionResult();
     _policyService          = new ServicePolicy();
     _filter                 = new DtoModuleSearchFilter();
     _filter.IncludeCommand  = true;
     _filter.IncludeFileCopy = true;
     _filter.IncludePrinter  = true;
     _filter.IncludeScript   = true;
     _filter.IncludeSoftware = true;
     _filter.IncludeWu       = true;
     _filter.IncludeMessage  = true;
     _filter.Limit           = Int32.MaxValue;
 }
Ejemplo n.º 12
0
 public ExportPolicy()
 {
     _policyService          = new ServicePolicy();
     _filter                 = new DtoModuleSearchFilter();
     _policyExport           = new DtoPolicyExport();
     _filter.IncludeCommand  = true;
     _filter.IncludeFileCopy = true;
     _filter.IncludePrinter  = true;
     _filter.IncludeScript   = true;
     _filter.IncludeSoftware = true;
     _filter.IncludeWu       = true;
     _filter.IncludeMessage  = true;
     _filter.Limit           = Int32.MaxValue;
 }
Ejemplo n.º 13
0
        public void FromTransport_Variant1()
        {
            var authPolicy = new AuthPolicy(1, null, null, null, true, new List <AuthPolicy.Location>
            {
                new AuthPolicy.Location("n", 1, 2, 3),
                new AuthPolicy.Location("x", 2, 4, 6)
            },
                                            new List <AuthPolicy.TimeFence>
            {
                new AuthPolicy.TimeFence("y", new List <string> {
                    "Monday"
                }, 1, 2, 3, 4, "A")
            });

            var servicePolicy = ServicePolicy.FromTransport(authPolicy);

            Assert.IsTrue(servicePolicy.RequiredFactors == 1);
            Assert.IsTrue(servicePolicy.RequireInherenceFactor == null);
            Assert.IsTrue(servicePolicy.RequireKnowledgeFactor == null);
            Assert.IsTrue(servicePolicy.RequirePossessionFactor == null);

            Assert.IsTrue(servicePolicy.TimeFences.Count == 1);
            Assert.IsTrue(servicePolicy.TimeFences[0].Days.Count == 1);
            Assert.IsTrue(servicePolicy.TimeFences[0].Days[0] == DayOfWeek.Monday);
            Assert.IsTrue(servicePolicy.TimeFences[0].Name == "y");
            Assert.IsTrue(servicePolicy.TimeFences[0].TimeZone == "A");
            Assert.IsTrue(servicePolicy.TimeFences[0].StartHour == 1);
            Assert.IsTrue(servicePolicy.TimeFences[0].EndHour == 2);
            Assert.IsTrue(servicePolicy.TimeFences[0].StartMinute == 3);
            Assert.IsTrue(servicePolicy.TimeFences[0].EndMinute == 4);

            Assert.IsTrue(servicePolicy.Locations.Count == 2);
            Assert.IsTrue(servicePolicy.Locations[0].Name == "n");
            Assert.AreEqual(servicePolicy.Locations[0].Latitude, 2, 0.01);
            Assert.AreEqual(servicePolicy.Locations[0].Longitude, 3, 0.01);
            Assert.AreEqual(servicePolicy.Locations[0].Radius, 1, 0.01);

            Assert.IsTrue(servicePolicy.Locations[1].Name == "x");
            Assert.AreEqual(servicePolicy.Locations[1].Latitude, 4, 0.01);
            Assert.AreEqual(servicePolicy.Locations[1].Longitude, 6, 0.01);
            Assert.AreEqual(servicePolicy.Locations[1].Radius, 2, 0.01);
        }
Ejemplo n.º 14
0
 public void LoadServicePolicy(Guid serviceId)
 {
     _loadedServicePolicy = GetDirectoryClient().GetServicePolicy(serviceId);
 }
Ejemplo n.º 15
0
        public DtoActionResult Execute(int groupId)
        {
            var    list = new List <DtoClientPolicy>();
            var    inactivePolicyIds = new List <int>();
            var    groupPolicies     = new ServiceGroup().GetAssignedPolicies(groupId, new DtoSearchFilter());
            string warningMessage    = null;

            if (groupPolicies.Count == 0)
            {
                //All Policies have been removed from the group.  Remove the active entry if it exists.
                var currentActiveGroupPolicy = new ServiceGroup().GetActiveGroupPolicy(groupId);
                if (currentActiveGroupPolicy != null)
                {
                    new ServiceActiveGroupPolicy().Delete(currentActiveGroupPolicy.Id);
                }
                return(new DtoActionResult()
                {
                    Success = true
                });
            }

            foreach (var groupPolicy in groupPolicies)
            {
                var policyJson = new ServicePolicy().GetActivePolicy(groupPolicy.PolicyId);
                if (policyJson == null) //Policy hasn't been activated yet
                {
                    inactivePolicyIds.Add(groupPolicy.PolicyId);
                    continue;
                }

                var deserializedPolicy = JsonConvert.DeserializeObject <DtoClientPolicy>(policyJson.PolicyJson);
                deserializedPolicy.Order = groupPolicy.PolicyOrder;
                list.Add(deserializedPolicy);
            }
            if (inactivePolicyIds.Count > 0) //some of the polices are inactive
            {
                var listInactivePolicies = inactivePolicyIds.Select(policyId => new ServicePolicy().GetPolicy(policyId)).ToList();
                warningMessage =
                    "Warning: Inactive Policies Are Applied.  The Following Assigned Policies Will Not Function Until They Are Activated: " +
                    String.Join(", ", listInactivePolicies.Select(x => x.Name));

                if (list.Count == 0) //All Of this groups policies are inactive.  Remove the active group entry and stop processing
                {
                    var currentActiveGroupPolicy = new ServiceGroup().GetActiveGroupPolicy(groupId);
                    if (currentActiveGroupPolicy != null)
                    {
                        new ServiceActiveGroupPolicy().Delete(currentActiveGroupPolicy.Id);
                    }
                    return(new DtoActionResult()
                    {
                        ErrorMessage = warningMessage
                    });
                }
            }

            var json = JsonConvert.SerializeObject(list);
            var clientGroupPolicy = new EntityActiveGroupPolicy();

            clientGroupPolicy.GroupId    = groupId;
            clientGroupPolicy.PolicyJson = json;

            new ServiceActiveGroupPolicy().InsertOrUpdate(clientGroupPolicy);

            //verify info was saved correctly and can be deserialized back to each invdividual policy
            var activeGroupPolicies = new ServiceActiveGroupPolicy().Get(clientGroupPolicy.Id);

            try
            {
                JsonConvert.DeserializeObject <List <DtoClientPolicy> >(activeGroupPolicies.PolicyJson);
                if (string.IsNullOrEmpty(warningMessage))
                {
                    return new DtoActionResult()
                           {
                               Success = true, Id = clientGroupPolicy.Id
                           }
                }
                ;
                else
                {
                    return new DtoActionResult()
                           {
                               ErrorMessage = warningMessage
                           }
                };
            }
            catch (Exception ex)
            {
                //back out any changes
                new ServiceActiveGroupPolicy().Delete(clientGroupPolicy.Id);
                return(new DtoActionResult {
                    ErrorMessage = "Could Not Verify Group Policy Deserialization", Id = 0
                });
                //todo: add logging
            }
        }
Ejemplo n.º 16
0
 public void LoadServicePolicy(Guid serviceId)
 {
     _loadedServicePolicy = _orgClient.GetServicePolicy(serviceId);
 }
Ejemplo n.º 17
0
 public void SetServicePolicy(Guid serviceId, ServicePolicy policy)
 {
     SetAdvancedServicePolicy(serviceId, policy.ToLegacyPolicy());
 }
Ejemplo n.º 18
0
 public ClientPolicyJson()
 {
     _policyService = new ServicePolicy();
     _clientPolicy  = new DtoClientPolicy();
 }