/// <summary>
        ///   Creates  a new <see cref = " RelyingParty" />.
        /// </summary>
        /// <param name = "name">Name of this new <see cref = " RelyingParty" />.</param>
        /// <param name = "realm">Realm of the relying party.</param>
        /// <param name = "reply">ReplyTo address for the relying party. May be null.</param>
        /// <param name = "tokenType">The type of token that the relying party consumes.</param>
        /// <param name = "requireEncryption">Whether to require asymmetric token encryption.</param>
        /// <returns>The new <see cref = " RelyingParty" /> created.</returns>
        public static RelyingParty CreateRelyingParty(
            this ManagementService svc, string name, string realm, string reply, RelyingPartyTokenType tokenType, bool requireEncryption)
        {
            svc.DeleteRelyingPartyByRealmIfExists(realm);

            var relyingParty = new RelyingParty
            {
                AsymmetricTokenEncryptionRequired = requireEncryption, Name = name, TokenType = tokenType.ToString(), TokenLifetime = 3600,
            };

            svc.AddToRelyingParties(relyingParty);

            //
            // Create the Realm address
            //
            var realmAddress = new RelyingPartyAddress {
                Address = realm, EndpointType = RelyingPartyAddressType.Realm.ToString(),
            };

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

            if (!string.IsNullOrEmpty(reply))
            {
                //
                // Create the ReplyTo address
                //
                var replyAddress = new RelyingPartyAddress {
                    Address = reply, EndpointType = RelyingPartyAddressType.Reply.ToString(),
                };

                svc.AddRelatedObject(relyingParty, "RelyingPartyAddresses", replyAddress);
            }

            return(relyingParty);
        }
Пример #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);
        }