Search in sources :

Example 1 with Authenticator

use of io.aeron.security.Authenticator in project Aeron by real-logic.

the class ArchiveAuthenticationTest method shouldBeAbleToRecordWithAuthenticateOnConnectRequestWithCredentials.

@Test
@InterruptAfter(10)
public void shouldBeAbleToRecordWithAuthenticateOnConnectRequestWithCredentials() {
    final MutableLong authenticatorSessionId = new MutableLong(-1L);
    final CredentialsSupplier credentialsSupplier = spy(new CredentialsSupplier() {

        public byte[] encodedCredentials() {
            return encodedCredentials;
        }

        public byte[] onChallenge(final byte[] encodedChallenge) {
            fail();
            return null;
        }
    });
    final Authenticator authenticator = spy(new Authenticator() {

        public void onConnectRequest(final long sessionId, final byte[] encodedCredentials, final long nowMs) {
            authenticatorSessionId.value = sessionId;
            assertEquals(CREDENTIALS_STRING, new String(encodedCredentials));
        }

        public void onChallengeResponse(final long sessionId, final byte[] encodedCredentials, final long nowMs) {
            fail();
        }

        public void onConnectedSession(final SessionProxy sessionProxy, final long nowMs) {
            assertEquals(sessionProxy.sessionId(), authenticatorSessionId.value);
            sessionProxy.authenticate(PRINCIPAL_STRING.getBytes());
        }

        public void onChallengedSession(final SessionProxy sessionProxy, final long nowMs) {
            fail();
        }
    });
    launchArchivingMediaDriver(() -> authenticator);
    connectClient(credentialsSupplier);
    assertEquals(aeronArchive.controlSessionId(), authenticatorSessionId.value);
    createRecording();
}
Also used : MutableLong(org.agrona.collections.MutableLong) CredentialsSupplier(io.aeron.security.CredentialsSupplier) SessionProxy(io.aeron.security.SessionProxy) Authenticator(io.aeron.security.Authenticator) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 2 with Authenticator

use of io.aeron.security.Authenticator in project Aeron by real-logic.

the class ArchiveAuthenticationTest method shouldNotBeAbleToConnectWithRejectOnConnectRequest.

@Test
@InterruptAfter(10)
public void shouldNotBeAbleToConnectWithRejectOnConnectRequest() {
    final MutableLong authenticatorSessionId = new MutableLong(-1L);
    final CredentialsSupplier credentialsSupplier = spy(new CredentialsSupplier() {

        public byte[] encodedCredentials() {
            return NULL_CREDENTIAL;
        }

        public byte[] onChallenge(final byte[] encodedChallenge) {
            assertEquals(CHALLENGE_STRING, new String(encodedChallenge));
            return encodedCredentials;
        }
    });
    final Authenticator authenticator = spy(new Authenticator() {

        public void onConnectRequest(final long sessionId, final byte[] encodedCredentials, final long nowMs) {
            authenticatorSessionId.value = sessionId;
            assertEquals(0, encodedCredentials.length);
        }

        public void onChallengeResponse(final long sessionId, final byte[] encodedCredentials, final long nowMs) {
            fail();
        }

        public void onConnectedSession(final SessionProxy sessionProxy, final long nowMs) {
            assertEquals(sessionProxy.sessionId(), authenticatorSessionId.value);
            sessionProxy.reject();
        }

        public void onChallengedSession(final SessionProxy sessionProxy, final long nowMs) {
            fail();
        }
    });
    launchArchivingMediaDriver(() -> authenticator);
    try {
        connectClient(credentialsSupplier);
    } catch (final ArchiveException ex) {
        assertEquals(ArchiveException.AUTHENTICATION_REJECTED, ex.errorCode());
        return;
    }
    fail("should have seen exception");
}
Also used : MutableLong(org.agrona.collections.MutableLong) CredentialsSupplier(io.aeron.security.CredentialsSupplier) SessionProxy(io.aeron.security.SessionProxy) ArchiveException(io.aeron.archive.client.ArchiveException) Authenticator(io.aeron.security.Authenticator) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 3 with Authenticator

use of io.aeron.security.Authenticator in project aeron by real-logic.

the class ArchiveAuthenticationTest method shouldBeAbleToRecordWithAuthenticateOnConnectRequestWithCredentials.

@Test
@InterruptAfter(10)
public void shouldBeAbleToRecordWithAuthenticateOnConnectRequestWithCredentials() {
    final MutableLong authenticatorSessionId = new MutableLong(-1L);
    final CredentialsSupplier credentialsSupplier = spy(new CredentialsSupplier() {

        public byte[] encodedCredentials() {
            return encodedCredentials;
        }

        public byte[] onChallenge(final byte[] encodedChallenge) {
            fail();
            return null;
        }
    });
    final Authenticator authenticator = spy(new Authenticator() {

        public void onConnectRequest(final long sessionId, final byte[] encodedCredentials, final long nowMs) {
            authenticatorSessionId.value = sessionId;
            assertEquals(CREDENTIALS_STRING, new String(encodedCredentials));
        }

        public void onChallengeResponse(final long sessionId, final byte[] encodedCredentials, final long nowMs) {
            fail();
        }

        public void onConnectedSession(final SessionProxy sessionProxy, final long nowMs) {
            assertEquals(sessionProxy.sessionId(), authenticatorSessionId.value);
            sessionProxy.authenticate(PRINCIPAL_STRING.getBytes());
        }

        public void onChallengedSession(final SessionProxy sessionProxy, final long nowMs) {
            fail();
        }
    });
    launchArchivingMediaDriver(() -> authenticator);
    connectClient(credentialsSupplier);
    assertEquals(aeronArchive.controlSessionId(), authenticatorSessionId.value);
    createRecording();
}
Also used : MutableLong(org.agrona.collections.MutableLong) CredentialsSupplier(io.aeron.security.CredentialsSupplier) SessionProxy(io.aeron.security.SessionProxy) Authenticator(io.aeron.security.Authenticator) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 4 with Authenticator

use of io.aeron.security.Authenticator in project Aeron by real-logic.

the class ArchiveAuthenticationTest method shouldNotBeAbleToConnectWithRejectOnChallengeResponse.

@Test
@InterruptAfter(10)
public void shouldNotBeAbleToConnectWithRejectOnChallengeResponse() {
    final MutableLong authenticatorSessionId = new MutableLong(-1L);
    final CredentialsSupplier credentialsSupplier = spy(new CredentialsSupplier() {

        public byte[] encodedCredentials() {
            return NULL_CREDENTIAL;
        }

        public byte[] onChallenge(final byte[] encodedChallenge) {
            assertEquals(CHALLENGE_STRING, new String(encodedChallenge));
            return encodedCredentials;
        }
    });
    final Authenticator authenticator = spy(new Authenticator() {

        boolean challengeRespondedTo = false;

        public void onConnectRequest(final long sessionId, final byte[] encodedCredentials, final long nowMs) {
            authenticatorSessionId.value = sessionId;
            assertEquals(0, encodedCredentials.length);
        }

        public void onChallengeResponse(final long sessionId, final byte[] encodedCredentials, final long nowMs) {
            assertEquals(sessionId, authenticatorSessionId.value);
            assertEquals(CREDENTIALS_STRING, new String(encodedCredentials));
            challengeRespondedTo = true;
        }

        public void onConnectedSession(final SessionProxy sessionProxy, final long nowMs) {
            assertEquals(sessionProxy.sessionId(), authenticatorSessionId.value);
            sessionProxy.challenge(encodedChallenge);
        }

        public void onChallengedSession(final SessionProxy sessionProxy, final long nowMs) {
            if (challengeRespondedTo) {
                assertEquals(sessionProxy.sessionId(), authenticatorSessionId.value);
                sessionProxy.reject();
            }
        }
    });
    launchArchivingMediaDriver(() -> authenticator);
    try {
        connectClient(credentialsSupplier);
    } catch (final ArchiveException ex) {
        assertEquals(ArchiveException.AUTHENTICATION_REJECTED, ex.errorCode());
        return;
    }
    fail("should have seen exception");
}
Also used : MutableLong(org.agrona.collections.MutableLong) CredentialsSupplier(io.aeron.security.CredentialsSupplier) SessionProxy(io.aeron.security.SessionProxy) ArchiveException(io.aeron.archive.client.ArchiveException) Authenticator(io.aeron.security.Authenticator) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 5 with Authenticator

use of io.aeron.security.Authenticator in project Aeron by real-logic.

the class ArchiveAuthenticationTest method shouldBeAbleToRecordWithAuthenticateOnChallengeResponse.

@Test
@InterruptAfter(10)
public void shouldBeAbleToRecordWithAuthenticateOnChallengeResponse() {
    final MutableLong authenticatorSessionId = new MutableLong(-1L);
    final CredentialsSupplier credentialsSupplier = spy(new CredentialsSupplier() {

        public byte[] encodedCredentials() {
            return NULL_CREDENTIAL;
        }

        public byte[] onChallenge(final byte[] encodedChallenge) {
            assertEquals(CHALLENGE_STRING, new String(encodedChallenge));
            return encodedCredentials;
        }
    });
    final Authenticator authenticator = spy(new Authenticator() {

        boolean challengeSuccessful = false;

        public void onConnectRequest(final long sessionId, final byte[] encodedCredentials, final long nowMs) {
            authenticatorSessionId.value = sessionId;
            assertEquals(0, encodedCredentials.length);
        }

        public void onChallengeResponse(final long sessionId, final byte[] encodedCredentials, final long nowMs) {
            assertEquals(sessionId, authenticatorSessionId.value);
            assertEquals(CREDENTIALS_STRING, new String(encodedCredentials));
            challengeSuccessful = true;
        }

        public void onConnectedSession(final SessionProxy sessionProxy, final long nowMs) {
            assertEquals(sessionProxy.sessionId(), authenticatorSessionId.value);
            sessionProxy.challenge(encodedChallenge);
        }

        public void onChallengedSession(final SessionProxy sessionProxy, final long nowMs) {
            if (challengeSuccessful) {
                assertEquals(sessionProxy.sessionId(), authenticatorSessionId.value);
                sessionProxy.authenticate(PRINCIPAL_STRING.getBytes());
            }
        }
    });
    launchArchivingMediaDriver(() -> authenticator);
    connectClient(credentialsSupplier);
    assertEquals(aeronArchive.controlSessionId(), authenticatorSessionId.value);
    createRecording();
}
Also used : MutableLong(org.agrona.collections.MutableLong) CredentialsSupplier(io.aeron.security.CredentialsSupplier) SessionProxy(io.aeron.security.SessionProxy) Authenticator(io.aeron.security.Authenticator) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Aggregations

Authenticator (io.aeron.security.Authenticator)8 CredentialsSupplier (io.aeron.security.CredentialsSupplier)8 SessionProxy (io.aeron.security.SessionProxy)8 InterruptAfter (io.aeron.test.InterruptAfter)8 MutableLong (org.agrona.collections.MutableLong)8 Test (org.junit.jupiter.api.Test)8 ArchiveException (io.aeron.archive.client.ArchiveException)4