private void AddSecurityContextToMessage(Message requestMessage, Credentials credentials) { if (requestMessage.Properties.Security == null) { requestMessage.Properties.Security = new SecurityMessageProperty(); } requestMessage.Properties.Security.ServiceSecurityContext = serviceSecurityContextFactory.Create(credentials); }
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(); }
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(); }
internal ServiceSecurityContext Create(Credentials credentials) { var authorizationPolicies = new List<IAuthorizationPolicy>(); authorizationPolicies.Add(authorizationPolicyFactory.Create(credentials)); return new ServiceSecurityContext(authorizationPolicies.AsReadOnly()); }
public virtual IAuthorizationPolicy Create(Credentials credentials) { var genericIdentity = new GenericIdentity(credentials.UserName); var genericPrincipal = new GenericPrincipal(genericIdentity, new string[] { }); return new PrincipalAuthorizationPolicy(genericPrincipal); }