Пример #1
0
        public async Task Trivial()
        {
            var request  = new PolicyRequest();
            var response = new PolicyResponse();

            await this.RoundtripAsync(Protocol.Default, new[] { request }, new[] { response });
        }
Пример #2
0
        public ActionResult AddCovering(long policyId, string coveringName)
        {
            PolicyResponse policy = PolicyApplicationService.ReadPolicyById(policyId);

            try
            {
                PolicyRequest request = new PolicyRequest
                {
                    id                    = policy.id,
                    descripcion           = policy.descripcion,
                    nombre                = policy.nombre,
                    TSeg_Tipo_Cubrimiento = getCoveringTypes(policy, coveringName)
                };

                int response = PolicyApplicationService.UpdatePolicy(request);
                return(RedirectToAction("Details", new { id = policyId }));
            }
            catch
            {
                ViewBag.PolicyName = policy.nombre;
                ViewBag.PolicyId   = policy.id;

                ViewBag.Error = "El tipo de cubrimiento no se pudo adicionar.";

                return(View("~/Views/Policies/AddCovering.cshtml"));
            }
        }
        /// <summary>
        /// Start PE Commit.
        /// </summary>
        private void SetPECommit()
        {
            // fetch the latest PE object
            ProtectableItemResponse protectableItemResponse =
                RecoveryServicesClient.GetAzureSiteRecoveryProtectableItem(this.fabricName,
                                                                           this.ProtectionEntity.ProtectionContainerId, this.ProtectionEntity.Name);

            ReplicationProtectedItemResponse replicationProtectedItemResponse =
                RecoveryServicesClient.GetAzureSiteRecoveryReplicationProtectedItem(this.fabricName,
                                                                                    this.ProtectionEntity.ProtectionContainerId, Utilities.GetValueFromArmId(protectableItemResponse.ProtectableItem.Properties.ReplicationProtectedItemId, ARMResourceTypeConstants.ReplicationProtectedItems));

            PolicyResponse policyResponse = RecoveryServicesClient.GetAzureSiteRecoveryPolicy(Utilities.GetValueFromArmId(replicationProtectedItemResponse.ReplicationProtectedItem.Properties.PolicyID, ARMResourceTypeConstants.ReplicationPolicies));

            this.ProtectionEntity = new ASRProtectionEntity(protectableItemResponse.ProtectableItem, replicationProtectedItemResponse.ReplicationProtectedItem);

            LongRunningOperationResponse response = RecoveryServicesClient.StartAzureSiteRecoveryCommitFailover(
                this.fabricName,
                this.protectionContainerName,
                Utilities.GetValueFromArmId(replicationProtectedItemResponse.ReplicationProtectedItem.Id, ARMResourceTypeConstants.ReplicationProtectedItems));

            JobResponse jobResponse =
                RecoveryServicesClient
                .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));

            WriteObject(new ASRJob(jobResponse.Job));
        }
        /// <summary>
        /// Write Protection Entities
        /// </summary>
        /// <param name="protectableItems">List of protectable items</param>
        private void WriteProtectionEntities(IList <ProtectableItem> protectableItems)
        {
            List <ASRProtectionEntity> asrProtectionEntityList = new List <ASRProtectionEntity>();

            foreach (ProtectableItem protectableItem in protectableItems)
            {
                ReplicationProtectedItemResponse replicationProtectedItemResponse = null;
                if (!String.IsNullOrEmpty(protectableItem.Properties.ReplicationProtectedItemId))
                {
                    replicationProtectedItemResponse = RecoveryServicesClient.GetAzureSiteRecoveryReplicationProtectedItem(
                        Utilities.GetValueFromArmId(this.ProtectionContainer.ID, ARMResourceTypeConstants.ReplicationFabrics),
                        this.ProtectionContainer.Name,
                        Utilities.GetValueFromArmId(protectableItem.Properties.ReplicationProtectedItemId, ARMResourceTypeConstants.ReplicationProtectedItems));
                }

                if (replicationProtectedItemResponse != null && replicationProtectedItemResponse.ReplicationProtectedItem != null)
                {
                    PolicyResponse policyResponse = RecoveryServicesClient.GetAzureSiteRecoveryPolicy(Utilities.GetValueFromArmId(replicationProtectedItemResponse.ReplicationProtectedItem.Properties.PolicyID, ARMResourceTypeConstants.ReplicationPolicies));
                    asrProtectionEntityList.Add(new ASRProtectionEntity(protectableItem, replicationProtectedItemResponse.ReplicationProtectedItem, policyResponse.Policy));
                }
                else
                {
                    asrProtectionEntityList.Add(new ASRProtectionEntity(protectableItem));
                }
            }

            this.WriteObject(asrProtectionEntityList, true);
        }
Пример #5
0
        public static void Setup(TestContext context)
        {
            // Init the test fixture
            IFixture fixture = new Fixture().Customize(new AutoMoqCustomization());

            // Create new mock policy
            _policy = fixture.Create <Policy>();

            // Create new mock of policy response and a list of policy responses
            _policyResponse     = fixture.Create <PolicyResponse>();
            _policyResponseList = new List <PolicyResponse> {
                _policyResponse
            };

            // Mock the Policy class
            _policyClassMock = fixture.Freeze <Mock <IPolicy> >();
            _policyClassMock.Setup(x => x.InsertPolicy(It.IsAny <Policy>())).ReturnsAsync(true);

            // Mock the PolicyListResponse class
            _policyListReponseClassMock = fixture.Freeze <Mock <IPolicyResponse> >();
            _policyListReponseClassMock.Setup(x => x.GetPolicyResponse()).Returns(_policyResponseList);

            // Init the policy service
            _sut = fixture.Create <PolicyService>();
        }
Пример #6
0
        public void Trivial()
        {
            var request  = new PolicyRequest();
            var response = new PolicyResponse();

            ExtensionTestUtilities.Roundtrip(Protocol.Default, new[] { request }, new[] { response });
        }
Пример #7
0
        public List <RoleResponse> GetPartnerRoles()
        {
            var roleList = _dbContext.RolePolicyDetail.Where(p => !p.IsDeleted && p.RoleType == "Partner").ToList();
            var roles    = roleList.GroupBy(p => new { p.RoleId, p.Name, p.RoleType });
            var response = new List <RoleResponse>();

            foreach (var item in roles)
            {
                var obj = new RoleResponse();
                obj.RoleId   = item.Key.RoleId;
                obj.Name     = item.Key.Name;
                obj.RoleType = item.Key.RoleType;
                obj.Policies = new List <PolicyResponse>();
                foreach (var resouce in item.Where(p => p.PolicyId.HasValue))
                {
                    var res = new PolicyResponse()
                    {
                        PolicyId    = resouce.PolicyId,
                        Name        = resouce.PolicyName,
                        Description = resouce.PolicyDescription
                    };
                    obj.Policies.Add(res);
                }
                response.Add(obj);
            }

            return(response);
        }
Пример #8
0
    protected void Yes_Click(Object sender, EventArgs e)
    {
        var            sregRequest  = ProviderEndpoint.PendingAuthenticationRequest.GetExtension <ClaimsRequest>();
        ClaimsResponse sregResponse = null;

        if (sregRequest != null)
        {
            sregResponse = profileFields.GetOpenIdProfileFields(sregRequest);
            ProviderEndpoint.PendingAuthenticationRequest.AddResponseExtension(sregResponse);
        }
        var            papeRequest  = ProviderEndpoint.PendingAuthenticationRequest.GetExtension <PolicyRequest>();
        PolicyResponse papeResponse = null;

        if (papeRequest != null)
        {
            papeResponse = new PolicyResponse();
            papeResponse.NistAssuranceLevel = NistAssuranceLevel.InsufficientForLevel1;
            ProviderEndpoint.PendingAuthenticationRequest.AddResponseExtension(papeResponse);
        }

        ProviderEndpoint.PendingAuthenticationRequest.IsAuthenticated = true;
        Debug.Assert(ProviderEndpoint.PendingAuthenticationRequest.IsResponseReady);
        ProviderEndpoint.PendingAuthenticationRequest.Response.Send();
        ProviderEndpoint.PendingAuthenticationRequest = null;
    }
Пример #9
0
        public RoleResponse GetRole(int roleId)
        {
            var roleList = _dbContext.RolePolicyDetail.Where(p => p.RoleId == roleId).ToList();
            var roles    = roleList.GroupBy(p => new { p.RoleId, p.Name });

            foreach (var item in roles)
            {
                var obj = new RoleResponse();
                obj.RoleId   = item.Key.RoleId;
                obj.Name     = item.Key.Name;
                obj.Policies = new List <PolicyResponse>();
                foreach (var resouce in item.Where(p => p.PolicyId.HasValue))
                {
                    var res = new PolicyResponse()
                    {
                        PolicyId    = resouce.PolicyId,
                        Name        = resouce.PolicyName,
                        Description = resouce.PolicyDescription
                    };
                    obj.Policies.Add(res);
                }
                return(obj);
            }

            return(null);
        }
Пример #10
0
        public PolicyResponse GetPolicyById(int policyId)
        {
            var policyList = _dbContext.ResourcePolicyDetail.Where(p => p.PolicyId == policyId).ToList();
            var policy     = policyList.GroupBy(p => new { p.PolicyId, p.Name, p.Description });

            foreach (var item in policy)
            {
                var obj = new PolicyResponse();
                obj.PolicyId    = item.Key.PolicyId;
                obj.Name        = item.Key.Name;
                obj.Description = item.Key.Description;
                obj.Resources   = new List <ResourceResponse>();
                foreach (var resouce in item.Where(p => p.ResourceId.HasValue))
                {
                    var res = new ResourceResponse()
                    {
                        ResourceId          = resouce.ResourceId,
                        Mehtod              = resouce.Method,
                        ResourceGroup       = resouce.ResourceGroup,
                        ResourceUri         = resouce.ResourceUri,
                        ResourceDescription = resouce.ResourceDescription
                    };
                    obj.Resources.Add(res);
                }
                return(obj);
            }

            return(null);
        }
Пример #11
0
        public IEnumerable <PolicyResponse> GetPolicies(string name = "")
        {
            var policyList = _dbContext.ResourcePolicyDetail.Where(p => !p.IsDeleted).ToList();
            var policy     = policyList.GroupBy(p => new { p.PolicyId, p.Name, p.Description });
            var response   = new List <PolicyResponse>();

            foreach (var item in policy)
            {
                var obj = new PolicyResponse();
                obj.PolicyId    = item.Key.PolicyId;
                obj.Name        = item.Key.Name;
                obj.Description = item.Key.Description;
                obj.Resources   = new List <ResourceResponse>();
                foreach (var resouce in item.Where(p => p.ResourceId.HasValue))
                {
                    var res = new ResourceResponse()
                    {
                        ResourceId          = resouce.ResourceId,
                        Mehtod              = resouce.Method,
                        ResourceGroup       = resouce.ResourceGroup,
                        ResourceUri         = resouce.ResourceUri,
                        ResourceDescription = resouce.ResourceDescription
                    };
                    obj.Resources.Add(res);
                }
                response.Add(obj);
            }

            return(response);
        }
Пример #12
0
        public void AuthenticationTimeUtcSetUtc()
        {
            PolicyResponse resp = new PolicyResponse();

            resp.AuthenticationTimeUtc = someUtcTime;
            Assert.AreEqual(someUtcTime, resp.AuthenticationTimeUtc);
        }
Пример #13
0
 public PolicyData(PolicyResponse response)
 {
     Id             = response.Id;
     OrganizationId = response.OrganizationId;
     Type           = response.Type;
     Data           = response.Data;
     Enabled        = response.Enabled;
 }
Пример #14
0
        public void Ctor()
        {
            PolicyResponse resp = new PolicyResponse();

            Assert.IsNotNull(resp.ActualPolicies);
            Assert.AreEqual(0, resp.ActualPolicies.Count);
            Assert.IsNull(resp.AuthenticationTimeUtc);
            Assert.IsNull(resp.NistAssuranceLevel);
        }
Пример #15
0
        public void AuthenticationTimeUtcConvertsToUtc()
        {
            PolicyResponse resp = new PolicyResponse();

            resp.AuthenticationTimeUtc = someLocalTime;
            Assert.IsNotNull(resp.AuthenticationTimeUtc);
            Assert.AreEqual(DateTimeKind.Utc, resp.AuthenticationTimeUtc.Value.Kind);
            Assert.AreEqual(someLocalTime.ToUniversalTime(), resp.AuthenticationTimeUtc.Value);
        }
Пример #16
0
        /// <summary>
        /// Starts PE Unplanned failover.
        /// </summary>
        private void StartPEUnplannedFailover()
        {
            var unplannedFailoverInputProperties = new UnplannedFailoverInputProperties()
            {
                FailoverDirection       = this.Direction,
                SourceSiteOperations    = this.PerformSourceSideActions ? "Required" : "NotRequired", //Required|NotRequired
                ProviderSpecificDetails = new ProviderSpecificFailoverInput()
            };

            var input = new UnplannedFailoverInput()
            {
                Properties = unplannedFailoverInputProperties
            };

            // fetch the latest PE object
            ProtectableItemResponse protectableItemResponse =
                RecoveryServicesClient.GetAzureSiteRecoveryProtectableItem(this.fabricName,
                                                                           this.ProtectionEntity.ProtectionContainerId, this.ProtectionEntity.Name);

            ReplicationProtectedItemResponse replicationProtectedItemResponse =
                RecoveryServicesClient.GetAzureSiteRecoveryReplicationProtectedItem(this.fabricName,
                                                                                    this.ProtectionEntity.ProtectionContainerId, Utilities.GetValueFromArmId(protectableItemResponse.ProtectableItem.Properties.ReplicationProtectedItemId, ARMResourceTypeConstants.ReplicationProtectedItems));

            PolicyResponse policyResponse = RecoveryServicesClient.GetAzureSiteRecoveryPolicy(Utilities.GetValueFromArmId(replicationProtectedItemResponse.ReplicationProtectedItem.Properties.PolicyID, ARMResourceTypeConstants.ReplicationPolicies));

            this.ProtectionEntity = new ASRProtectionEntity(protectableItemResponse.ProtectableItem, replicationProtectedItemResponse.ReplicationProtectedItem);

            if (0 == string.Compare(
                    this.ProtectionEntity.ReplicationProvider,
                    Constants.HyperVReplicaAzure,
                    StringComparison.OrdinalIgnoreCase))
            {
                if (this.Direction == Constants.PrimaryToRecovery)
                {
                    var failoverInput = new HyperVReplicaAzureFailoverProviderInput()
                    {
                        PrimaryKekCertificatePfx   = primaryKekCertpfx,
                        SecondaryKekCertificatePfx = secondaryKekCertpfx,
                        VaultLocation = this.GetCurrentVaultLocation()
                    };
                    input.Properties.ProviderSpecificDetails = failoverInput;
                }
            }

            LongRunningOperationResponse response =
                RecoveryServicesClient.StartAzureSiteRecoveryUnplannedFailover(
                    this.fabricName,
                    this.protectionContainerName,
                    Utilities.GetValueFromArmId(replicationProtectedItemResponse.ReplicationProtectedItem.Id, ARMResourceTypeConstants.ReplicationProtectedItems),
                    input);

            JobResponse jobResponse =
                RecoveryServicesClient
                .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));

            WriteObject(new ASRJob(jobResponse.Job));
        }
Пример #17
0
        protected void Yes_Click(object sender, EventArgs e)
        {
            this.RegisterAsyncTask(
                new PageAsyncTask(
                    async ct => {
                if (!Page.IsValid || ProviderEndpoint.PendingRequest == null)
                {
                    return;
                }

                if (this.OAuthPanel.Visible)
                {
                    string grantedScope = null;
                    if (this.oauthPermission.Checked)
                    {
                        // This SIMPLE sample merely uses the realm as the consumerKey,
                        // but in a real app this will probably involve a database lookup to translate
                        // the realm to a known consumerKey.
                        grantedScope = string.Empty;                                         // we don't scope individual access rights on this sample
                    }

                    OAuthHybrid.ServiceProvider.AttachAuthorizationResponse(ProviderEndpoint.PendingRequest, grantedScope);
                }

                var sregRequest             = ProviderEndpoint.PendingRequest.GetExtension <ClaimsRequest>();
                ClaimsResponse sregResponse = null;
                if (sregRequest != null)
                {
                    sregResponse = this.profileFields.GetOpenIdProfileFields(sregRequest);
                    ProviderEndpoint.PendingRequest.AddResponseExtension(sregResponse);
                }
                var papeRequest             = ProviderEndpoint.PendingRequest.GetExtension <PolicyRequest>();
                PolicyResponse papeResponse = null;
                if (papeRequest != null)
                {
                    papeResponse = new PolicyResponse();
                    papeResponse.NistAssuranceLevel = NistAssuranceLevel.InsufficientForLevel1;
                    ProviderEndpoint.PendingRequest.AddResponseExtension(papeResponse);
                }

                if (ProviderEndpoint.PendingAuthenticationRequest != null)
                {
                    ProviderEndpoint.PendingAuthenticationRequest.IsAuthenticated = true;
                }
                else
                {
                    ProviderEndpoint.PendingAnonymousRequest.IsApproved = true;
                }
                Debug.Assert(
                    ProviderEndpoint.PendingRequest.IsResponseReady, "Setting authentication should be all that's necessary.");

                var provider = new ProviderEndpoint();
                var response = await provider.PrepareResponseAsync();
                await response.SendAsync();
            }));
        }
Пример #18
0
        public void EqualsTest()
        {
            PolicyResponse resp  = new PolicyResponse();
            PolicyResponse resp2 = new PolicyResponse();

            Assert.AreEqual(resp, resp2);
            Assert.AreNotEqual(resp, null);
            Assert.AreNotEqual(null, resp);

            // Test ActualPolicies list comparison
            resp.ActualPolicies.Add(AuthenticationPolicies.PhishingResistant);
            Assert.AreNotEqual(resp, resp2);
            resp2.ActualPolicies.Add(AuthenticationPolicies.MultiFactor);
            Assert.AreNotEqual(resp, resp2);
            resp2.ActualPolicies.Clear();
            resp2.ActualPolicies.Add(AuthenticationPolicies.PhishingResistant);
            Assert.AreEqual(resp, resp2);

            // Test ActualPolicies list comparison when that list is not in the same order.
            resp.ActualPolicies.Add(AuthenticationPolicies.MultiFactor);
            Assert.AreNotEqual(resp, resp2);
            resp2.ActualPolicies.Insert(0, AuthenticationPolicies.MultiFactor);
            Assert.AreEqual(resp, resp2);

            // Test AuthenticationTimeUtc comparison.
            resp.AuthenticationTimeUtc = DateTime.Now;
            Assert.AreNotEqual(resp, resp2);
            resp2.AuthenticationTimeUtc = resp.AuthenticationTimeUtc;
            Assert.AreEqual(resp, resp2);
            resp2.AuthenticationTimeUtc += TimeSpan.FromSeconds(1);
            Assert.AreNotEqual(resp, resp2);
            resp2.AuthenticationTimeUtc = resp.AuthenticationTimeUtc;
            Assert.AreEqual(resp, resp2);

            // Test NistAssuranceLevel comparison.
            resp.NistAssuranceLevel = NistAssuranceLevel.InsufficientForLevel1;
            Assert.AreNotEqual(resp, resp2);
            resp2.NistAssuranceLevel = NistAssuranceLevel.InsufficientForLevel1;
            Assert.AreEqual(resp, resp2);
            resp.NistAssuranceLevel = NistAssuranceLevel.Level2;
            Assert.AreNotEqual(resp, resp2);
            resp2.NistAssuranceLevel = NistAssuranceLevel.Level2;
            Assert.AreEqual(resp, resp2);

            // Test AssuranceLevels comparison.
            resp.AssuranceLevels.Add("custom", "b");
            Assert.AreNotEqual(resp, resp2);
            resp2.AssuranceLevels.Add("custom", "2");
            Assert.AreNotEqual(resp, resp2);
            resp2.AssuranceLevels["custom"] = "b";
            Assert.AreEqual(resp, resp2);
            resp.AssuranceLevels[Constants.AuthenticationLevels.NistTypeUri] = "1";
            Assert.AreNotEqual(resp, resp2);
            resp2.AssuranceLevels[Constants.AuthenticationLevels.NistTypeUri] = "1";
            Assert.AreEqual(resp, resp2);
        }
Пример #19
0
        public async Task <IActionResult> CreatePolicy([FromBody] PolicyCreationRequest request)
        {
            if (string.IsNullOrEmpty(request.Name) ||
                string.IsNullOrEmpty(request.Description) ||
                string.IsNullOrEmpty(request.CoverageStartDate) ||
                request.CoverageLength <= 0 ||
                request.PremiumPrice <= 0 ||
                !Enum.IsDefined(typeof(RiskLevel), request.RiskLevelId))
            {
                return(BadRequest());
            }

            var coverages = new Dictionary <InsuranceCoverage, float>();

            if (request.EarthquakeCoverage > 0)
            {
                coverages.Add(InsuranceCoverage.Earthquake, request.EarthquakeCoverage);
            }

            if (request.FireCoverage > 0)
            {
                coverages.Add(InsuranceCoverage.Fire, request.FireCoverage);
            }

            if (request.TheftCoverage > 0)
            {
                coverages.Add(InsuranceCoverage.Theft, request.TheftCoverage);
            }

            if (request.LossCoverage > 0)
            {
                coverages.Add(InsuranceCoverage.Loss, request.LossCoverage);
            }

            if (!coverages.Any())
            {
                return(BadRequest());
            }

            DateTime coverageStartDate;

            try {
                coverageStartDate = DateTime.Parse(request.CoverageStartDate);
            } catch (FormatException) {
                return(BadRequest());
            }

            var riskLevel = (RiskLevel)request.RiskLevelId;
            var policy    = await insuranceService.CreatePolicyAsync(
                request.Name, request.Description, coverages, coverageStartDate,
                request.CoverageLength, request.PremiumPrice, riskLevel);

            var response = new PolicyResponse(policy);

            return(Ok(response));
        }
Пример #20
0
        public void CanSearchOnePolicy(string name, bool expectedResults)
        {
            PolicyGrinder grinder = PolicyGrinderFactory.Synthesize();
            Policy        policy  = new Policy();

            policy.Name = name;
            PolicyResponse response = grinder.GetOnePolicy(policy);

            Assert.AreEqual(expectedResults, response.Success);
        }
Пример #21
0
        public List <CustomerPolicyResponse> getPoliciesDetails(List <CustomerPolicyResponse> list)
        {
            for (int i = 0; i < list.Count; i++)
            {
                PolicyResponse policy = PolicyApplicationService.ReadPolicyById(list.ElementAt(i).id_poliza);
                list.ElementAt(i).nombre_poliza = policy.nombre;
            }

            return(list);
        }
Пример #22
0
        /// <summary>
        /// Should allow user access.
        /// </summary>
        /// <param name="response"></param>
        public void Allow(PolicyResponse response)
        {
            if (IsFinishing)
            {
                // Don't update UI if Activity is finishing.
                return;
            }

            DisplayResult(GetString(Resource.String.allow));
        }
Пример #23
0
        public void AddPolicies()
        {
            PolicyResponse resp = new PolicyResponse();

            resp.ActualPolicies.Add(AuthenticationPolicies.MultiFactor);
            resp.ActualPolicies.Add(AuthenticationPolicies.PhishingResistant);
            Assert.AreEqual(2, resp.ActualPolicies.Count);
            Assert.AreEqual(AuthenticationPolicies.MultiFactor, resp.ActualPolicies[0]);
            Assert.AreEqual(AuthenticationPolicies.PhishingResistant, resp.ActualPolicies[1]);
        }
Пример #24
0
        public ActionResult AddCovering(long policyId)
        {
            PolicyResponse policy = PolicyApplicationService.ReadPolicyById(policyId);

            //  List<CoveringTypeResponse> coveringTypes = CoveringTypeApplicationService.ReadCoveringTypes();
            ViewBag.PolicyName = policy.nombre;
            ViewBag.PolicyId   = policy.id;
            // ViewBag.coveringTypes = new SelectList(coveringTypes, nameof(CoveringTypeResponse.id), nameof(PolicyResponse.nombre));
            return(View("~/Views/Policies/AddCovering.cshtml"));
        }
Пример #25
0
        public ActionResult Details(long id)
        {
            PolicyResponse    policy = PolicyApplicationService.ReadPolicyById(id);
            CoveringModelView model  = new CoveringModelView();

            model.policy   = policy;
            model.covering = policy.TSeg_Tipo_Cubrimiento;

            return(View("~/Views/Policies/CoveringDetails.cshtml", model));
        }
Пример #26
0
 public ActionResult AddPolicy(Policy policy)
 {
     if (ModelState.IsValid)
     {
         PolicyGrinder  grinder  = PolicyGrinderFactory.Synthesize();
         PolicyResponse response = grinder.AddNewPolicy(policy);
         return(RedirectToAction("ManagePolicies", response));
     }
     return(View(policy));
 }
Пример #27
0
        /// <summary>
        /// Sends a positive or a negative assertion, based on how the pending request is currently marked.
        /// </summary>
        /// <returns>An MVC redirect result.</returns>
        public ActionResult SendAssertion()
        {
            var pendingRequest = ProviderEndpoint.PendingRequest;
            var authReq = pendingRequest as IAuthenticationRequest;
            var anonReq = pendingRequest as IAnonymousRequest;
            ProviderEndpoint.PendingRequest = null; // clear session static so we don't do this again
            if (pendingRequest == null)
            {
                throw new InvalidOperationException("There's no pending authentication request!");
            }

            // Set safe defaults if somehow the user ended up (perhaps through XSRF) here before electing to send data to the RP.
            if (anonReq != null && !anonReq.IsApproved.HasValue)
            {
                anonReq.IsApproved = false;
            }

            if (authReq != null && !authReq.IsAuthenticated.HasValue)
            {
                authReq.IsAuthenticated = false;
            }

            if (authReq != null && authReq.IsAuthenticated.Value)
            {
                if (authReq.IsDirectedIdentity)
                {
                    authReq.LocalIdentifier = Util.GetClaimedIdentifierForUser(User.Identity.Name);
                }

                if (!authReq.IsDelegatedIdentifier)
                {
                    authReq.ClaimedIdentifier = authReq.LocalIdentifier;
                }
            }

            // Respond to AX/sreg extension requests only on a positive result.
            if ((authReq != null && authReq.IsAuthenticated.Value) ||
                (anonReq != null && anonReq.IsApproved.Value))
            {
                // Look for PAPE requests.
                var papeRequest = pendingRequest.GetExtension<PolicyRequest>();
                if (papeRequest != null)
                {
                    var papeResponse = new PolicyResponse();
                    if (papeRequest.MaximumAuthenticationAge.HasValue)
                    {
                        papeResponse.AuthenticationTimeUtc = formsAuth.SignedInTimestampUtc;
                    }

                    pendingRequest.AddResponseExtension(papeResponse);
                }
            }

            return OpenIdProvider.PrepareResponse(pendingRequest).AsActionResult();
        }
Пример #28
0
        public void CanDeletePolicy(string name, string content, bool expectedResults)
        {
            PolicyGrinder grinder = PolicyGrinderFactory.Synthesize();
            Policy        policy  = new Policy();

            policy.Name    = name;
            policy.Content = content;
            PolicyResponse response = grinder.DeletePolicy(policy);

            Assert.AreEqual(expectedResults, response.Success);
        }
Пример #29
0
        public void NistAssuranceLevelSetVarious()
        {
            PolicyResponse resp = new PolicyResponse();

            resp.NistAssuranceLevel = NistAssuranceLevel.Level1;
            Assert.AreEqual(NistAssuranceLevel.Level1, resp.NistAssuranceLevel);
            resp.NistAssuranceLevel = null;
            Assert.IsNull(resp.NistAssuranceLevel);
            resp.NistAssuranceLevel = NistAssuranceLevel.InsufficientForLevel1;
            Assert.AreEqual(NistAssuranceLevel.InsufficientForLevel1, resp.NistAssuranceLevel);
        }
Пример #30
0
        /// <summary>
        /// Should not allow access.
        /// <br />
        /// In most cases, the app should assume the user has access unless it
        /// encounters this. If it does, the app should inform the user of
        /// their unlicensed ways and then either shut down the app or limit
        /// the user to a restricted set of features.
        /// <br />
        /// In this example, we show a dialog that takes the user to Play.
        /// If the reason for the lack of license is that the service is
        /// unavailable or there is another problem, we display a
        /// retry button on the dialog and a different message.
        /// </summary>
        /// <param name="response"></param>
        public void DontAllow(PolicyResponse response)
        {
            if (IsFinishing)
            {
                // Don't update UI if Activity is finishing.
                return;
            }

            DisplayResult(GetString(Resource.String.dont_allow));
            DisplayDialog(response == PolicyResponse.Retry);
        }
Пример #31
0
        public static void AddActionToContentItem(ContentItem contentItem, PolicyResponseAction responseAction, bool triggeredPolicy)
        {
            PolicySetResponse psr = new PolicySetResponse("Test Policy Set");
            PolicyResponse pr = new PolicyResponse();
            pr.Triggered = triggeredPolicy;

            pr.ActionCollection = new Collection<IPolicyResponseAction>();
            pr.ActionCollection.Add(responseAction);

            psr.PolicyReportCollection = new Collection<IPolicyResponse>();
            psr.PolicyReportCollection.Add(pr);

            contentItem.PolicySetCollection = new Collection<IPolicySetResponse>();
            contentItem.PolicySetCollection.Add(psr);
        }
Пример #32
0
        public void SetupPro()
        {    
            pro = new PolicyResponseObject();

            pro.ContentCollection = new Collection<IContentItem>();

            ContentItem ci = new ContentItem();
            ci.Name = "ContentItem1";
            pro.ContentCollection.Add(ci);

            PolicySetResponse setA = new PolicySetResponse("setA");
            PolicySetResponse setB = new PolicySetResponse("setB");

            ((ContentItem)pro.ContentCollection[0]).PolicySetCollection = new Collection<IPolicySetResponse>();
            pro.ContentCollection[0].PolicySetCollection.Add(setA);
            pro.ContentCollection[0].PolicySetCollection.Add(setB);

            PolicyResponse policyW = new PolicyResponse();
            policyW.Triggered = true;
            PolicyResponse policyX = new PolicyResponse();
            policyX.Triggered = true;
            PolicyResponse policyY = new PolicyResponse();
            policyY.Triggered = true;
            PolicyResponse policyZ = new PolicyResponse();
            policyZ.Triggered = true;

            setA.PolicyReportCollection = new Collection<IPolicyResponse>();
            setA.PolicyReportCollection.Add(policyW);
            setA.PolicyReportCollection.Add(policyX);

            setB.PolicyReportCollection = new Collection<IPolicyResponse>();
            setB.PolicyReportCollection.Add(policyY);
            setB.PolicyReportCollection.Add(policyZ);

            policyW.ActionCollection = new Collection<IPolicyResponseAction>();
            policyW.ActionCollection.Add(new PolicyResponseAction());
            policyX.ActionCollection = new Collection<IPolicyResponseAction>();
            policyX.ActionCollection.Add(new PolicyResponseAction());

            ((PolicyResponseAction)policyW.ActionCollection[0]).Type = ((PolicyResponseAction)policyX.ActionCollection[0]).Type = "1stTypeOfAction";
            
            policyY.ActionCollection = new Collection<IPolicyResponseAction>();
            policyY.ActionCollection.Add(new PolicyResponseAction());
            policyZ.ActionCollection = new Collection<IPolicyResponseAction>();
            policyZ.ActionCollection.Add(new PolicyResponseAction());

            ((PolicyResponseAction)policyY.ActionCollection[0]).Type = ((PolicyResponseAction)policyZ.ActionCollection[0]).Type = "2ndTypeOfAction";

            //Wire up the resolved actions... one of each type.
            ResolvedAction action1 = new ResolvedAction();
            action1.ResponseAction = policyW.ActionCollection[0];

            ResolvedAction action2 = new ResolvedAction();
            action2.ResponseAction = policyY.ActionCollection[0];

            pro.ResolvedActionCollection = new Collection<IResolvedAction>();
            pro.ResolvedActionCollection.Add(action1);
            pro.ResolvedActionCollection.Add(action2);

            //This bit mimics what happens in action resolution - each resolved actions has a list of which content items it will act on.
            action1.ContentCollection = new Collection<IContentItem>();
            action1.ContentCollection.Add(ci);

            action2.ContentCollection = new Collection<IContentItem>();
            action2.ContentCollection.Add(ci);
        }
Пример #33
0
        public void ResolveActionsForVerifiedResponses_MultipleContentItems()
        {
            pro.VerifiedOnClient = true;

            pro.ContentCollection[0].PolicySetCollection[0].PolicyReportCollection[0].SkipVerifiedMessages = true;
            pro.ContentCollection[0].PolicySetCollection[0].PolicyReportCollection[1].SkipVerifiedMessages = true; //These two policies trigger the same type of action.

            pro.ContentCollection[0].PolicySetCollection[1].PolicyReportCollection[0].SkipVerifiedMessages = true;
            pro.ContentCollection[0].PolicySetCollection[1].PolicyReportCollection[1].SkipVerifiedMessages = true;  //These two pols trigger the same type of action, but different from 1st two policies.

            ContentItem ci = new ContentItem();
            ci.Name = "ContentItem2";

            pro.ContentCollection.Add(ci);
            Assert.AreEqual(2, pro.ContentCollection.Count);

            ci.PolicySetCollection = new Collection<IPolicySetResponse>();
            
            PolicySetResponse psr = new PolicySetResponse("PolicyC");
            PolicyResponse pol = new PolicyResponse();
            pol.Triggered = true;
            pol.SkipVerifiedMessages = false;  
            //Therefore, this policy vetoes the skipping.  We expect to see any actions from this policy show up in the resolved list.

            psr.PolicyReportCollection = new Collection<IPolicyResponse>();
            psr.PolicyReportCollection.Add(pol);
            ci.PolicySetCollection.Add(psr);

            pol.ActionCollection = new Collection<IPolicyResponseAction>();
            PolicyResponseAction pra1 = new PolicyResponseAction();
            pra1.Type = "1stTypeOfAction";

            PolicyResponseAction pra2 = new PolicyResponseAction();
            pra2.Type = "2ndTypeOfAction";

            pol.ActionCollection.Add(pra1);
            pol.ActionCollection.Add(pra2);

            //We've now mimicked an existing action being triggered on a new content item.  
            //Update the content collections that the resolved actions maintain.
            pro.ResolvedActionCollection[0].ContentCollection.Add(ci);
            pro.ResolvedActionCollection[1].ContentCollection.Add(ci);

            ActionUtils.ResolveActionsForVerifiedResponses(pro);
            Assert.AreEqual(2, pro.ResolvedActionCollection.Count, "Both actions should be present.");
            IResolvedAction action1 = pro.ResolvedActionCollection[0];
            IResolvedAction action2 = pro.ResolvedActionCollection[1];

            Assert.AreEqual("1stTypeOfAction", action1.ResponseAction.Type);
            Assert.AreEqual("2ndTypeOfAction", action2.ResponseAction.Type);

            Assert.AreEqual(1, action1.ContentCollection.Count, "Expected a single item in the content collection, because this action should only apply to one of the content items, not both");

            Assert.AreEqual(1, action2.ContentCollection.Count, "Expected a single item in the content collection.");

            pol.SkipVerifiedMessages = true;
            ActionUtils.ResolveActionsForVerifiedResponses(pro);
            Assert.AreEqual(0, pro.ResolvedActionCollection.Count);
        }