Search in sources :

Example 1 with ClientAuthenticationException

use of org.apache.ignite.client.ClientAuthenticationException in project ignite by apache.

the class AdditionalSecurityCheckTest method testClientInfoIgniteClientFail.

/**
 */
@Test
public void testClientInfoIgniteClientFail() throws Exception {
    Ignite ignite = startGrids(2);
    assertEquals(2, ignite.cluster().topologyVersion());
    startGrid(2);
    assertEquals(3, ignite.cluster().topologyVersion());
    fail = true;
    try (IgniteClient client = Ignition.startClient(getClientConfiguration())) {
        fail();
    } catch (ClientAuthenticationException e) {
        assertTrue(e.getMessage().contains("Client version is not found"));
    }
}
Also used : GridClientAuthenticationException(org.apache.ignite.internal.client.GridClientAuthenticationException) ClientAuthenticationException(org.apache.ignite.client.ClientAuthenticationException) IgniteClient(org.apache.ignite.client.IgniteClient) Ignite(org.apache.ignite.Ignite) Test(org.junit.Test)

Example 2 with ClientAuthenticationException

use of org.apache.ignite.client.ClientAuthenticationException in project ignite by apache.

the class TcpClientChannel method handshakeRes.

/**
 * Receive and handle handshake response.
 */
private void handshakeRes(ByteBuffer buf, ProtocolVersion proposedVer, String user, String pwd, Map<String, String> userAttrs) throws ClientConnectionException, ClientAuthenticationException, ClientProtocolError {
    BinaryInputStream res = BinaryByteBufferInputStream.create(buf);
    try (BinaryReaderExImpl reader = ClientUtils.createBinaryReader(null, res)) {
        boolean success = res.readBoolean();
        if (success) {
            byte[] features = EMPTY_BYTES;
            if (ProtocolContext.isFeatureSupported(proposedVer, BITMAP_FEATURES))
                features = reader.readByteArray();
            protocolCtx = new ProtocolContext(proposedVer, ProtocolBitmaskFeature.enumSet(features));
            if (protocolCtx.isFeatureSupported(PARTITION_AWARENESS)) {
                // Reading server UUID
                srvNodeId = reader.readUuid();
            }
        } else {
            ProtocolVersion srvVer = new ProtocolVersion(res.readShort(), res.readShort(), res.readShort());
            String err = reader.readString();
            int errCode = ClientStatus.FAILED;
            if (res.remaining() > 0)
                errCode = reader.readInt();
            if (errCode == ClientStatus.AUTH_FAILED)
                throw new ClientAuthenticationException(err);
            else if (proposedVer.equals(srvVer))
                throw new ClientProtocolError(err);
            else if (!supportedVers.contains(srvVer) || (!ProtocolContext.isFeatureSupported(srvVer, AUTHORIZATION) && !F.isEmpty(user)))
                // authentication and authentication is required.
                throw new ClientProtocolError(String.format("Protocol version mismatch: client %s / server %s. Server details: %s", proposedVer, srvVer, err));
            else {
                // Retry with server version.
                handshake(srvVer, user, pwd, userAttrs);
            }
        }
    } catch (IOException e) {
        throw handleIOError(e);
    }
}
Also used : ClientAuthenticationException(org.apache.ignite.client.ClientAuthenticationException) BinaryReaderExImpl(org.apache.ignite.internal.binary.BinaryReaderExImpl) BinaryInputStream(org.apache.ignite.internal.binary.streams.BinaryInputStream) IOException(java.io.IOException)

Aggregations

ClientAuthenticationException (org.apache.ignite.client.ClientAuthenticationException)2 IOException (java.io.IOException)1 Ignite (org.apache.ignite.Ignite)1 IgniteClient (org.apache.ignite.client.IgniteClient)1 BinaryReaderExImpl (org.apache.ignite.internal.binary.BinaryReaderExImpl)1 BinaryInputStream (org.apache.ignite.internal.binary.streams.BinaryInputStream)1 GridClientAuthenticationException (org.apache.ignite.internal.client.GridClientAuthenticationException)1 Test (org.junit.Test)1