public static RequestInterceptor Create(string realm, MembershipProvider membershipProvider)
 {
     var basicAuthenticationCredentialsExtractor = new BasicAuthenticationCredentialsExtractor(new Base64Decoder(), new DecodedCredentialsExtractor());
      var httpRequestAuthorizationExtractor = new AuthorizationStringExtractor();
      var responseMessageFactory = new ResponseMessageFactory(realm);
      var serviceSecurityContextFactory = new ServiceSecurityContextFactory(new AuthorizationPolicyFactory());
      var basicAuthenticationManager = new BasicAuthenticationManager(basicAuthenticationCredentialsExtractor, httpRequestAuthorizationExtractor, membershipProvider, responseMessageFactory, serviceSecurityContextFactory);
      return new BasicAuthenticationInterceptor(basicAuthenticationManager);
 }
 internal BasicAuthenticationManager(BasicAuthenticationCredentialsExtractor basicAuthenticationCredentialsExtractor,
  AuthorizationStringExtractor httpRequestAuthorizationExtractor, 
  MembershipProvider membershipProvider, 
  ResponseMessageFactory responseMessageFactory, 
  ServiceSecurityContextFactory serviceSecurityContextFactory)
 {
     this.basicAuthenticationCredentialsExtractor = basicAuthenticationCredentialsExtractor;
      this.httpRequestAuthorizationExtractor = httpRequestAuthorizationExtractor;
      this.membershipProvider = membershipProvider;
      this.responseMessageFactory = responseMessageFactory;
      this.serviceSecurityContextFactory = serviceSecurityContextFactory;
 }
        public void ShouldCreateSecurityContextFromCredentials()
        {
            var mockRepository = new MockRepository();

             const string UserName = "******";
             const string Password = "******";
             var credentials = new Credentials(UserName, Password);

             var genericPrincipal = mockRepository.Stub<IPrincipal>();
             Expect.Call(genericPrincipal.Identity.Name).Return(UserName);

             var authorizationPolicyFactory = mockRepository.StrictMock<AuthorizationPolicyFactory>();
             Expect.Call(authorizationPolicyFactory.Create(credentials)).Return(new PrincipalAuthorizationPolicy(genericPrincipal));

             mockRepository.ReplayAll();
             var serviceSecurityContextFactory = new ServiceSecurityContextFactory(authorizationPolicyFactory);
             ServiceSecurityContext serviceSecurityContext = serviceSecurityContextFactory.Create(credentials);
             Assert.AreEqual(UserName, serviceSecurityContext.PrimaryIdentity.Name);
             mockRepository.VerifyAll();
        }