public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext) { int found = request.Headers.FindHeader(Constants.SEC_HEADER, Constants.SEC_NS); if (found != -1) { AuthTokenHeader authToken = request.Headers.GetHeader <AuthTokenHeader>(Constants.SEC_HEADER, Constants.SEC_NS); if (authToken != null && authToken.UserName != null && authToken.HashPassword != null) { if (!SecHelpers.IsAuthenticated(authToken.UserName, authToken.HashPassword)) { throw new UnauthorizedAccessException("SM: You might not have permission to access this funtion."); } } } return(null); }
public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime) { ClientCredentials cred = null; foreach (IEndpointBehavior item in endpoint.EndpointBehaviors) { if (item is ClientCredentials) { cred = (ClientCredentials)item; break; } } AuthTokenHeader authToken = null; if (cred != null) { authToken = new AuthTokenHeader() { UserName = cred.UserName.UserName, HashPassword = cred.UserName.Password }; } clientRuntime.MessageInspectors.Add(new ClientMessageInspector(authToken)); }
public ClientMessageInspector(AuthTokenHeader authToken) { this.AuthToken = authToken; }