|
//-----------------------------------------------------------------------
// <copyright file="DigestAuthenticationInterceptor.cs" company="http://www.semanticarchitecture.net">
// (C) Patrick Kalkman pkalkie@gmail.com
// </copyright>
//-----------------------------------------------------------------------
using System.ServiceModel.Channels;
using Microsoft.ServiceModel.Web;
namespace DigestAuthenticationOnWCF
{
/// <summary>
/// This class connects to the extension point of WCF, the RequestInterceptor.
/// RequestInterceptor is a class that processes each request that is sent
/// to the WCF service.
/// </summary>
internal class DigestAuthenticationInterceptor : RequestInterceptor
{
private readonly DigestAuthenticationManager authenticationManager;
public DigestAuthenticationInterceptor(DigestAuthenticationManager authenticationManager) : base(false)
{
this.authenticationManager = authenticationManager;
}
public override void ProcessRequest(ref RequestContext requestContext)
{
if (requestContext == null || !authenticationManager.AuthenticateRequest(requestContext.RequestMessage))
{
requestContext = CreateAndSendInvalidAuthenticationRequest(requestContext);
}
}
private RequestContext CreateAndSendInvalidAuthenticationRequest(RequestContext requestContext)
{
using (Message responseMessage = authenticationManager.CreateInvalidAuthenticationRequest(requestContext.RequestMessage))
{
requestContext.Reply(responseMessage);
requestContext = null;
return requestContext;
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Patrick Kalkman is a senior Software Architect with more than 20 years professional development experience. He works for
SimpleTechture where he helps teams develop state of the art web applications.
Patrick enjoys writing his
blog. It discusses agile software development. Patrick can be reached at patrick@simpletechture.nl.
Published Windows 8 apps:
Published Windows Phone apps:
Awards:
Best Mobile article of March 2012
Best Mobile article of June 2012