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 ShouldExtractCredentialsFromBasicAuthenticationString() { var mockRepository = new MockRepository(); const string BasicAuthenticationCredentialString = "Basic SGVsbG8gQmFzZTY0"; string authenticationStringOnly = BasicAuthenticationCredentialString.Replace("Basic", string.Empty); const string DecodedCredentialString = "DummyUser:DummyPassword"; var base64Decoder = mockRepository.StrictMock<Base64Decoder>(); Expect.Call(base64Decoder.Decode(authenticationStringOnly)).Return(DecodedCredentialString); var credentials = new Credentials("DummyUser", "DummyPassword"); var credentialsExtractor = mockRepository.StrictMock<DecodedCredentialsExtractor>(); Expect.Call(credentialsExtractor.Extract(DecodedCredentialString)).Return(credentials); var basicCredentialsExtractor = new BasicAuthenticationCredentialsExtractor(base64Decoder, credentialsExtractor); mockRepository.ReplayAll(); basicCredentialsExtractor.Extract(BasicAuthenticationCredentialString); mockRepository.VerifyAll(); }