36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IdentityModel.Selectors;
|
|
using System.Linq;
|
|
using System.Security.Principal;
|
|
using System.ServiceModel.Web;
|
|
using System.Web;
|
|
using Taloyhtio.GeneralApi.Common;
|
|
using WcfRestContrib.ServiceModel.Web.Exceptions;
|
|
|
|
namespace Taloyhtio.GeneralApi.WcfService
|
|
{
|
|
public class CustomAuthenticationHandler : WcfRestContrib.ServiceModel.Dispatcher.IWebAuthenticationHandler
|
|
{
|
|
public IIdentity Authenticate(
|
|
IncomingWebRequestContext request,
|
|
OutgoingWebResponseContext response,
|
|
object[] parameters,
|
|
UserNamePasswordValidator validator,
|
|
bool secure,
|
|
bool requiresTransportLayerSecurity,
|
|
string source)
|
|
{
|
|
if (requiresTransportLayerSecurity && !secure)
|
|
{
|
|
throw new BasicRequiresTransportSecurityException();
|
|
}
|
|
|
|
string username = request.Headers[Constants.HttpHeaders.Username];
|
|
string password = request.Headers[Constants.HttpHeaders.Password];
|
|
validator.Validate(username, password);
|
|
return new GenericIdentity(username, "CustomAuthenticationHandler");
|
|
}
|
|
}
|
|
}
|