public ISecurityTokenService Create(WsTrustConstants constants)
        {
            var sts = _services.GetService <SecurityTokenService>();

            sts.Initialize(constants);
            return(sts);
        }
        public WsTrustChannel(WsTrustVersion version, IWsTrustContract contract, WsTrustSerializer serializer)
            : base(contract as IChannel)
        {
            // TODO: add null guards
            _version   = version;
            _constants = GetConstants(version);
            // TODO: get message version from binding
            _messageVersion = MessageVersion.Default;
            _contract       = contract;

            _serializer = serializer;
        }
 internal void Initialize(WsTrustConstants constants)
 => Constants = constants;
예제 #4
0
        protected virtual ValueTask <DispatchContext> CreateDispatchContextAsync(Message requestMessage, string requestAction, string responseAction, WsTrustConstants constants)
        {
            var serializer  = _serializerFactory.Create();
            var soapContext = _soapContextAccessor.SoapContext;
            var context     = new DispatchContext
            {
                Principal            = soapContext.User,
                RequestAction        = requestAction,
                ResponseAction       = responseAction,
                TrustNamespace       = constants.Namespace,
                SecurityTokenService = _stsFactory.Create(constants),
                MessageVersion       = soapContext.MessageVersion,
                CancellationToken    = soapContext.CancellationToken
            };

            using (var reader = requestMessage.GetReaderAtBodyContents())
            {
                if (reader.IsStartElement(WsTrustElements.RequestSecurityToken, constants.Namespace))
                {
                    context.RequestMessage = serializer.ReadRequest(reader);
                }
                //else if (reader.IsStartElement(WsTrustElements.RequestSecurityTokenResponse))
                //    context.ResponseMessage = serializer.ReadResponse(reader);
                else
                {
                    throw new InvalidRequestException(ErrorMessages.ID3114);
                }
            }

            return(new ValueTask <DispatchContext>(context));
        }
예제 #5
0
        /// <summary>
        /// Processes a WS-Trust request message, and optionally determines the appropriate
        /// response message and the WS-Addressing action for the response message.
        /// </summary>
        /// <param name="dispatchContext">Defines the request parameters to process and exposes properties
        /// that determine the response message and action.</param>
        protected virtual async ValueTask DispatchRequestAsync(DispatchContext dispatchContext, WsTrustConstants constants)
        {
            var request = dispatchContext.RequestMessage as WsTrustRequest;
            var action  = dispatchContext.RequestAction;
            var sts     = dispatchContext.SecurityTokenService;

            if (request == null)
            {
                throw new InvalidRequestException(ErrorMessages.ID3022);
            }

            if (action == constants.WsTrustActions.CancelRequest)
            {
                dispatchContext.ResponseMessage = await sts.CancelAsync(dispatchContext.Principal, request, dispatchContext.CancellationToken);
            }
            else if (action == constants.WsTrustActions.IssueRequest)
            {
                dispatchContext.ResponseMessage = await sts.IssueAsync(dispatchContext.Principal, request, dispatchContext.CancellationToken);
            }
            else if (action == constants.WsTrustActions.RenewRequest)
            {
                dispatchContext.ResponseMessage = await sts.RenewAsync(dispatchContext.Principal, request, dispatchContext.CancellationToken);
            }
            else if (action == constants.WsTrustActions.ValidateRequest)
            {
                dispatchContext.ResponseMessage = await sts.ValidateAsync(dispatchContext.Principal, request, dispatchContext.CancellationToken);
            }
            else
            {
                throw new InvalidRequestException(ErrorMessages.ID3112, request.RequestType);
            }
        }