Как настроить IssuedSecurityTokenParameters в .NET 6

У нас есть службы WCF, которые требуют специальной привязки и дополнительных параметров. Мы создали его собственные привязки и передали дополнительные параметры в.NET 4.8рамки. Сейчас мы переносим его в . После обновления проекта возникли две ошибки: «IssuedSecurityTokenParametersне содержит определенияAdditionalRequestParametersиIssuerMetadataAddress. Мы добавилиSystem.ServiceModelссылка в нашем.NET 6проект. Код приведен ниже

       public Binding CreateBinding(string customCode, string serverName, string msLogon)
    {
        var issuedSecurityTokenParameters = CreateIssuedSecurityTokenParameters(customCode, serverName, msLogon);

        var issuedTokenOverTransport = SecurityBindingElement.CreateIssuedTokenOverTransportBindingElement(issuedSecurityTokenParameters);
        issuedTokenOverTransport.MessageSecurityVersion = MessageSecurityVersion;
        issuedTokenOverTransport.LocalClientSettings.MaxClockSkew = TimeSpan.FromMinutes(5);

        SecurityBindingElement secureConversationBindingElement = SecurityBindingElement.CreateSecureConversationBindingElement(issuedTokenOverTransport);
        secureConversationBindingElement.MessageSecurityVersion = MessageSecurityVersion;

        BinaryMessageEncodingBindingElement binaryMessageEncodingBindingElement = new BinaryMessageEncodingBindingElement
        {
            MaxReadPoolSize = config.MaxReadPoolSize,
            MaxSessionSize = config.MaxSessionSize,
            MaxWritePoolSize = config.MaxWritePoolSize,
            ReaderQuotas =
            {
                MaxArrayLength = config.MaxArrayLength,
                MaxStringContentLength = config.MaxStringContentLength,
                MaxBytesPerRead = config.MaxBytesPerRead
            },
            CompressionFormat = config.CompressionFormat
        };

        TcpTransportBindingElement tcpTransportBindingElement = new TcpTransportBindingElement
        {
            MaxBufferPoolSize = config.MaxBufferPoolSize,
            MaxBufferSize = config.MaxBufferSize,
            ConnectionBufferSize = config.ConnectionBufferSize,
            MaxReceivedMessageSize = config.MaxReceivedMessageSize,
            TransferMode = TransferMode.Streamed

        };

        var streamSecurity = new SslStreamSecurityBindingElement { RequireClientCertificate = false };

        CustomBinding binding = new CustomBinding()
        {
            Elements =
                                            {
                                                secureConversationBindingElement,
                                                binaryMessageEncodingBindingElement,
                                                streamSecurity,
                                                tcpTransportBindingElement
                                            },

            Name = "tcpTransportWithIssuedTokenSecurity",
            Namespace = "http://fully-qualified-namespcae.com/tcp",
            CloseTimeout = config.CloseTimeout,
            OpenTimeout = config..OpenTimeout,
            ReceiveTimeout = config.ReceiveTimeout,
            SendTimeout = config.SendTimeout

        };

        return binding;
    }
    private IssuedSecurityTokenParameters CreateIssuedSecurityTokenParameters(string customCode, string serverName, string msLogon)
    {
        //var identity = EndpointIdentity.CreateUpnIdentity(config.ServerConfiguration.UserPrincipalName);
        var identity = new UpnEndpointIdentity(config.UserPrincipalName);

        var endpointAddress = new EndpointAddress(new Uri("https://" + serverName + ":" + config.PortNumber + "/SecurityTokenService/windows"), identity);
        var issuerMetadataAddress = new EndpointAddress(new Uri("https://" + serverName + ":" + config.PortNumber + "/SecurityTokenService/mex"), identity);

        WS2007HttpBinding binding = new WS2007HttpBinding(SecurityMode.TransportWithMessageCredential)
        {
            Name = "WindowsAuthBinding",
            Namespace = "http://fully-qualified-namespcae.com/auth",
            MaxReceivedMessageSize = int.MaxValue
        };
        binding.Security.Message.EstablishSecurityContext = false;
        binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
        binding.Security.Message.NegotiateServiceCredential = false;

        var issuedSecurityTokenParams =
            new IssuedSecurityTokenParameters
            {
                IssuerAddress = endpointAddress,
                IssuerMetadataAddress = issuerMetadataAddress,
                DefaultMessageSecurityVersion = MessageSecurityVersion,
                KeyType = SecurityKeyType.SymmetricKey,
                TokenType = @"http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1",
                IssuerBinding = binding
            };

        string additionalParam = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
                                    <xml>
                                        <trust:SecondaryParameters xmlns:trust=""http://docs.oasis-open.org/ws-sx/ws-trust/200512"">
                                          <trust:TokenType xmlns:trust=""http://docs.oasis-open.org/ws-sx/ws-trust/200512"">http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1</trust:TokenType>
                                          <trust:KeyType xmlns:trust=""http://docs.oasis-open.org/ws-sx/ws-trust/200512"">http://docs.oasis-open.org/ws-sx/ws-trust/200512/SymmetricKey</trust:KeyType>
                                        </trust:SecondaryParameters>
                                        <prodName:customCode xmlns:prodName=""http://fully-qualified-namespcae.com/11""></prodName:customCode>
                                        <prodName:customCode xmlns:prodName=""http://fully-qualified-namespcae.com/11""></prodName:customCode>
                                    </xml>";

        var doc = new XmlDocument();
        doc.LoadXml(additionalParam);
        doc.GetElementsByTagName("prodName:customCode").Item(0).InnerText = customCode;
        doc.GetElementsByTagName("prodName:MsLogon").Item(0).InnerText = msLogon;
        issuedSecurityTokenParams.AdditionalRequestParameters.Add((XmlElement)doc.GetElementsByTagName("trust:SecondaryParameters").Item(0));
        issuedSecurityTokenParams.AdditionalRequestParameters.Add((XmlElement)doc.GetElementsByTagName("prodName:customCode").Item(0));
        issuedSecurityTokenParams.AdditionalRequestParameters.Add((XmlElement)doc.GetElementsByTagName("prodName:MsLogon").Item(0));
        return issuedSecurityTokenParams;
    }

Не могли бы вы дать ссылку, как мы можем перенести это на .net 6?

0 ответов

Другие вопросы по тегам