Search in sources :

Example 1 with AuthenticationException

use of io.dropwizard.auth.AuthenticationException in project keywhiz by square.

the class AutomationClientAuthFactory method provide.

public AutomationClient provide(ContainerRequest request) {
    Optional<String> possibleClientName = ClientAuthFactory.getClientName(request);
    if (!possibleClientName.isPresent()) {
        throw new NotAuthorizedException("Not authorized as a AutomationClient");
    }
    String clientName = possibleClientName.get();
    try {
        return authenticator.authenticate(clientName).orElseThrow(() -> new ForbiddenException(format("ClientCert name %s not authorized as a AutomationClient", clientName)));
    } catch (AuthenticationException e) {
        throw Throwables.propagate(e);
    }
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) AuthenticationException(io.dropwizard.auth.AuthenticationException) NotAuthorizedException(javax.ws.rs.NotAuthorizedException)

Example 2 with AuthenticationException

use of io.dropwizard.auth.AuthenticationException in project keywhiz by square.

the class ClientAuthFactory method provide.

public Client provide(ContainerRequest request) {
    Optional<String> possibleClientName = getClientName(request);
    if (!possibleClientName.isPresent()) {
        throw new NotAuthorizedException("ClientCert not authorized as a Client");
    }
    String clientName = possibleClientName.get();
    try {
        return authenticator.authenticate(clientName).orElseThrow(() -> new NotAuthorizedException(format("ClientCert name %s not authorized as a Client", clientName)));
    } catch (AuthenticationException e) {
        throw Throwables.propagate(e);
    }
}
Also used : AuthenticationException(io.dropwizard.auth.AuthenticationException) NotAuthorizedException(javax.ws.rs.NotAuthorizedException)

Example 3 with AuthenticationException

use of io.dropwizard.auth.AuthenticationException in project thunder by RohanNagar.

the class ThunderAuthenticatorTest method testAuthenticateWithInvalidCredentials.

@Test
public void testAuthenticateWithInvalidCredentials() {
    BasicCredentials credentials = new BasicCredentials("invalidApplication", "secret");
    Optional<Key> result = Optional.empty();
    try {
        result = authenticator.authenticate(credentials);
    } catch (AuthenticationException e) {
        // This shouldn't happen, so fail the test.
        fail();
    }
    assertFalse(result.isPresent());
}
Also used : AuthenticationException(io.dropwizard.auth.AuthenticationException) BasicCredentials(io.dropwizard.auth.basic.BasicCredentials) Test(org.junit.Test)

Example 4 with AuthenticationException

use of io.dropwizard.auth.AuthenticationException in project thunder by RohanNagar.

the class ThunderAuthenticatorTest method testAuthenticateWithValidCredentials.

@Test
public void testAuthenticateWithValidCredentials() {
    BasicCredentials credentials = new BasicCredentials("application", "secret");
    Optional<Key> result = Optional.empty();
    try {
        result = authenticator.authenticate(credentials);
    } catch (AuthenticationException e) {
        // This shouldn't happen, so fail the test.
        fail();
    }
    assertTrue(result.isPresent());
    assertEquals(key, result.get());
}
Also used : AuthenticationException(io.dropwizard.auth.AuthenticationException) BasicCredentials(io.dropwizard.auth.basic.BasicCredentials) Test(org.junit.Test)

Aggregations

AuthenticationException (io.dropwizard.auth.AuthenticationException)4 BasicCredentials (io.dropwizard.auth.basic.BasicCredentials)2 NotAuthorizedException (javax.ws.rs.NotAuthorizedException)2 Test (org.junit.Test)2 ForbiddenException (javax.ws.rs.ForbiddenException)1