SetOwner() public method

public SetOwner ( ) : void
return void
Exemplo n.º 1
0
        private void Authenticate(ClientConnection connection, bool isOwnerConnection)
        {
            if (Logger.IsFinestEnabled())
            {
                Logger.Finest(string.Format("Authenticating against the {0} node", isOwnerConnection?"owner":"non-owner"));
            }
            string uuid      = null;
            string ownerUuid = null;

            if (ClientPrincipal != null)
            {
                uuid      = ClientPrincipal.GetUuid();
                ownerUuid = ClientPrincipal.GetOwnerUuid();
            }

            var           ss = _client.GetSerializationService();
            ClientMessage request;
            var           credentials = _credentialsFactory.NewCredentials();

            LastCredentials = credentials;
            if (credentials.GetType() == typeof(UsernamePasswordCredentials))
            {
                var usernamePasswordCr = (UsernamePasswordCredentials)credentials;
                request = ClientAuthenticationCodec.EncodeRequest(usernamePasswordCr.Username, usernamePasswordCr.Password, uuid,
                                                                  ownerUuid, isOwnerConnection, ClientTypes.Csharp, ss.GetVersion(), VersionUtil.GetDllVersion());
            }
            else
            {
                var data = ss.ToData(credentials);
                request = ClientAuthenticationCustomCodec.EncodeRequest(data, uuid, ownerUuid, isOwnerConnection,
                                                                        ClientTypes.Csharp, ss.GetVersion(), VersionUtil.GetDllVersion());
            }

            IClientMessage response;

            try
            {
                var invocationService = (ClientInvocationService)_client.GetInvocationService();
                response = ThreadUtil.GetResult(invocationService.InvokeOnConnection(request, connection), _heartbeatTimeout);
            }
            catch (Exception e)
            {
                var ue = ExceptionUtil.Rethrow(e);
                Logger.Finest("Member returned an exception during authentication.", ue);
                throw ue;
            }
            var result = ClientAuthenticationCodec.DecodeResponse(response);

            if (result.address == null)
            {
                throw new HazelcastException("Could not resolve address for member.");
            }
            switch (result.status)
            {
            case AuthenticationStatus.Authenticated:
                if (isOwnerConnection)
                {
                    var member = new Member(result.address, result.ownerUuid);
                    ClientPrincipal   = new ClientPrincipal(result.uuid, result.ownerUuid);
                    connection.Member = member;
                    connection.SetOwner();
                    connection.ConnectedServerVersionStr = result.serverHazelcastVersion;
                }
                else
                {
                    var member = _client.GetClientClusterService().GetMember(result.address);
                    if (member == null)
                    {
                        throw new HazelcastException(string.Format("Node with address '{0}' was not found in the member list",
                                                                   result.address));
                    }
                    connection.Member = member;
                }
                break;

            case AuthenticationStatus.CredentialsFailed:
                throw new AuthenticationException("Invalid credentials! Principal: " + ClientPrincipal);

            case AuthenticationStatus.SerializationVersionMismatch:
                throw new InvalidOperationException("Server serialization version does not match to client");

            default:
                throw new AuthenticationException("Authentication status code not supported. status: " + result.status);
            }
        }
        private void ManagerAuthenticator(ClientConnection connection)
        {
            Logger.Finest("Authenticating against the owner node");
            var ss = _client.GetSerializationService();

            string uuid = null;
            string ownerUuid = null;
            if (_principal != null)
            {
                uuid = _principal.GetUuid();
                ownerUuid = _principal.GetOwnerUuid();
            }
            ClientMessage request;
            if (_credentials is UsernamePasswordCredentials)
            {
                var usernamePasswordCr = (UsernamePasswordCredentials) _credentials;
                request = ClientAuthenticationCodec.EncodeRequest(usernamePasswordCr.GetUsername(),
                    usernamePasswordCr.GetPassword(), uuid, ownerUuid, true,
                    ClientTypes.Csharp, _client.GetSerializationService().GetVersion());
            }
            else
            {
                var data = ss.ToData(_credentials);
                request = ClientAuthenticationCustomCodec.EncodeRequest(data, uuid, ownerUuid, false,
                    ClientTypes.Csharp, _client.GetSerializationService().GetVersion());
            }

            IClientMessage response;
            try
            {
                var invocationService = (ClientInvocationService) _client.GetInvocationService();
                response = ThreadUtil.GetResult(invocationService.InvokeOnConnection(request, connection));
            }
            catch (Exception e)
            {
                throw ExceptionUtil.Rethrow(e);
            }
            var result = ClientAuthenticationCodec.DecodeResponse(response);

            var member = new Member(result.address, result.ownerUuid);
            _principal = new ClientPrincipal(result.uuid, result.ownerUuid);

            connection.SetRemoteMember(member);
            connection.SetOwner();
        }