Exemple #1
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));
        }
Exemple #2
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);
            }
        }
Exemple #3
0
 protected virtual ValueTask ValidateDispatchContextAsync(DispatchContext context)
 {
     // TODO: validate dispatch context
     // write this with tests
     return(new ValueTask());
 }