Пример #1
0
        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);
        }
Пример #2
0
        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));
        }
Пример #3
0
 public ClientMessageInspector(AuthTokenHeader authToken)
 {
     this.AuthToken = authToken;
 }