Exemplo n.º 1
0
        public static RuleGroup AddPassthroughRule(this ManagementService svc,
            RelyingParty relyingParty, string ruleGroupName)
        {
            Contract.Requires(svc != null);
            Contract.Requires(relyingParty != null);
            Contract.Requires(!string.IsNullOrWhiteSpace(ruleGroupName));

            var ruleGroup = new RuleGroup() { Name = ruleGroupName };

            svc.AddToRuleGroups(ruleGroup);

            svc.SaveChanges(SaveChangesOptions.Batch);

            var localAuthority = svc.Issuers.Where(
                m => m.Name == "LOCAL AUTHORITY").FirstOrDefault();

            var passthrough = new Rule();

            passthrough.Description = "Passthough all ACS claims";

            svc.AddToRules(passthrough);
            svc.SetLink(passthrough, "RuleGroup", ruleGroup);
            svc.SetLink(passthrough, "Issuer", localAuthority);

            var rprg = new RelyingPartyRuleGroup();

            svc.AddToRelyingPartyRuleGroups(rprg);

            svc.AddLink(relyingParty, "RelyingPartyRuleGroups", rprg);
            svc.AddLink(ruleGroup, "RelyingPartyRuleGroups", rprg);

            svc.SaveChanges(SaveChangesOptions.Batch);

            return ruleGroup;
        }
Exemplo n.º 2
0
        public static RelyingParty AddRelyingParty(this ManagementService svc, Uri realm,
            string relyingPartyName, DateTime startDate, DateTime endDate, 
            byte[] tokenSigningKey, int tokenLifetime)
        {
            Contract.Requires(svc != null);
            Contract.Requires(realm != null);
            Contract.Requires(realm.IsAbsoluteUri);
            Contract.Requires(realm.AbsolutePath == "/");
            Contract.Requires(!string.IsNullOrWhiteSpace(relyingPartyName));
            Contract.Requires(startDate != default(DateTime));
            Contract.Requires(endDate > startDate);
            Contract.Requires(tokenSigningKey != null);
            Contract.Requires(tokenLifetime >= 1);

            var relyingParty = new RelyingParty()
            {
                Name = relyingPartyName,
                AsymmetricTokenEncryptionRequired = false,
                TokenType = "SWT",
                TokenLifetime = tokenLifetime
            };

            svc.AddToRelyingParties(relyingParty);

            var relyingPartyAddress = new RelyingPartyAddress()
            {
                Address = realm.AbsoluteUri,
                EndpointType = "Realm"
            };

            svc.AddRelatedObject(relyingParty, "RelyingPartyAddresses", relyingPartyAddress);

            var relyingPartyKey = new RelyingPartyKey()
            {
                StartDate = startDate,
                EndDate = endDate,
                Type = "Symmetric",
                Usage = "Signing",
                IsPrimary = true,
                Value = tokenSigningKey
            };

            svc.AddRelatedObject(relyingParty, "RelyingPartyKeys", relyingPartyKey);

            svc.SaveChanges(SaveChangesOptions.Batch);

            return relyingParty;
        }