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);
}
}
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);
}
}
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());
}
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());
}
Aggregations