Search in sources :

Example 1 with ClientPartitionServiceImpl

use of com.hazelcast.client.impl.spi.impl.ClientPartitionServiceImpl in project hazelcast by hazelcast.

the class TcpClientConnectionManager method checkAuthenticationResponse.

/**
 * Checks the response from the server to see if authentication needs to be continued,
 * closes the connection and throws exception if the authentication needs to be cancelled.
 */
private void checkAuthenticationResponse(TcpClientConnection connection, ClientAuthenticationCodec.ResponseParameters response) {
    AuthenticationStatus authenticationStatus = AuthenticationStatus.getById(response.status);
    if (failoverConfigProvided && !response.failoverSupported) {
        logger.warning("Cluster does not support failover. This feature is available in Hazelcast Enterprise");
        authenticationStatus = NOT_ALLOWED_IN_CLUSTER;
    }
    switch(authenticationStatus) {
        case AUTHENTICATED:
            break;
        case CREDENTIALS_FAILED:
            AuthenticationException authException = new AuthenticationException("Authentication failed. The configured " + "cluster name on the client (see ClientConfig.setClusterName()) does not match the one configured " + "in the cluster or the credentials set in the Client security config could not be authenticated");
            connection.close("Failed to authenticate connection", authException);
            throw authException;
        case NOT_ALLOWED_IN_CLUSTER:
            ClientNotAllowedInClusterException notAllowedException = new ClientNotAllowedInClusterException("Client is not allowed in the cluster");
            connection.close("Failed to authenticate connection", notAllowedException);
            throw notAllowedException;
        default:
            AuthenticationException exception = new AuthenticationException("Authentication status code not supported. status: " + authenticationStatus);
            connection.close("Failed to authenticate connection", exception);
            throw exception;
    }
    ClientPartitionServiceImpl partitionService = (ClientPartitionServiceImpl) client.getClientPartitionService();
    if (!partitionService.checkAndSetPartitionCount(response.partitionCount)) {
        ClientNotAllowedInClusterException exception = new ClientNotAllowedInClusterException("Client can not work with this cluster" + " because it has a different partition count. " + "Expected partition count: " + partitionService.getPartitionCount() + ", Member partition count: " + response.partitionCount);
        connection.close("Failed to authenticate connection", exception);
        throw exception;
    }
}
Also used : AuthenticationStatus(com.hazelcast.client.impl.protocol.AuthenticationStatus) ClientNotAllowedInClusterException(com.hazelcast.client.ClientNotAllowedInClusterException) AuthenticationException(com.hazelcast.client.AuthenticationException) ClientPartitionServiceImpl(com.hazelcast.client.impl.spi.impl.ClientPartitionServiceImpl)

Aggregations

AuthenticationException (com.hazelcast.client.AuthenticationException)1 ClientNotAllowedInClusterException (com.hazelcast.client.ClientNotAllowedInClusterException)1 AuthenticationStatus (com.hazelcast.client.impl.protocol.AuthenticationStatus)1 ClientPartitionServiceImpl (com.hazelcast.client.impl.spi.impl.ClientPartitionServiceImpl)1