Search in sources :

Example 1 with SimbaUnavailableException

use of org.simbasecurity.dwclient.exception.SimbaUnavailableException in project simba-os by cegeka.

the class SimbaGateway method createAuthenticationService.

/**
	 * @return always creates a new client
	 * @throws SimbaUnavailableException
	 */
AuthenticationFilterService.Client createAuthenticationService() throws SimbaUnavailableException {
    try {
        tHttpClient = getTHttpClient();
        authenticationFilterService = simbaServiceFactory.createJSONAuthenticationFilterService(tHttpClient);
    } catch (TTransportException | RuntimeException e) {
        if (tHttpClient != null) {
            tHttpClient.close();
        }
        logger.error("Simba is down?", e);
        throw new SimbaUnavailableException(e);
    }
    return authenticationFilterService;
}
Also used : TTransportException(org.apache.thrift.transport.TTransportException) SimbaUnavailableException(org.simbasecurity.dwclient.exception.SimbaUnavailableException)

Example 2 with SimbaUnavailableException

use of org.simbasecurity.dwclient.exception.SimbaUnavailableException in project simba-os by cegeka.

the class SimbaGateway method processRequestInSimba.

private ActionDescriptor processRequestInSimba(RequestData requestData, String chain) throws SimbaUnavailableException {
    try {
        logger.debug("processRequest in simba with requestdata: {}", requestData);
        ActionDescriptor actionDescriptor = createAuthenticationService().processRequest(requestData, chain);
        return actionDescriptor;
    } catch (TException | RuntimeException e) {
        logger.error("Simba is down?", e);
        throw new SimbaUnavailableException(e);
    } finally {
        if (tHttpClient != null) {
            tHttpClient.close();
        }
    }
}
Also used : TException(org.apache.thrift.TException) ActionDescriptor(org.simbasecurity.api.service.thrift.ActionDescriptor) SimbaUnavailableException(org.simbasecurity.dwclient.exception.SimbaUnavailableException)

Example 3 with SimbaUnavailableException

use of org.simbasecurity.dwclient.exception.SimbaUnavailableException in project simba-os by cegeka.

the class SimbaUnavailableExceptionToJSONMapperTest method toResponse_ReturnsJSONValidationError.

@Test
public void toResponse_ReturnsJSONValidationError() throws Exception {
    SimbaUnavailableExceptionToJSONMapper mapperUnderTest = new SimbaUnavailableExceptionToJSONMapper();
    SimbaUnavailableException simbaUnavailableException = new SimbaUnavailableException();
    DWSimbaErrorR expectedEntity = new DWSimbaErrorR(HttpStatus.INTERNAL_SERVER_ERROR.getDescription(), SimbaUnavailableExceptionToJSONMapper.SIMBA_ERROR_MESSAGE, null);
    MediaType expectedMediaType = MediaType.APPLICATION_JSON_TYPE;
    int expectedStatus = 500;
    Response actual = mapperUnderTest.toResponse(simbaUnavailableException);
    assertThat(actual.getStatus()).isEqualTo(expectedStatus);
    assertThat((MediaType) actual.getMetadata().get("Content-Type").get(0)).isEqualTo(expectedMediaType);
    assertThat(actual.getEntity()).isEqualsToByComparingFields(expectedEntity);
}
Also used : Response(javax.ws.rs.core.Response) DWSimbaErrorR(org.simbasecurity.dwclient.dropwizard.representation.DWSimbaErrorR) MediaType(javax.ws.rs.core.MediaType) SimbaUnavailableException(org.simbasecurity.dwclient.exception.SimbaUnavailableException) SimbaUnavailableExceptionToJSONMapper(org.simbasecurity.dwclient.exception.mapper.SimbaUnavailableExceptionToJSONMapper) Test(org.junit.Test)

Example 4 with SimbaUnavailableException

use of org.simbasecurity.dwclient.exception.SimbaUnavailableException in project simba-os by cegeka.

the class SimbaAuthenticatorTest method authenticate_WhenConnectionToSimbaFails_ThrowAuthenticationException.

@Test
public void authenticate_WhenConnectionToSimbaFails_ThrowAuthenticationException() throws Exception {
    SimbaCredentials credentials = mock(SimbaCredentials.class);
    when(simbaGatewayMock.authenticate(credentials)).thenThrow(new SimbaUnavailableException());
    expectedException.expect(AuthenticationException.class);
    authenticator.authenticate(credentials);
}
Also used : SimbaCredentials(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials) SimbaUnavailableException(org.simbasecurity.dwclient.exception.SimbaUnavailableException) Test(org.junit.Test)

Aggregations

SimbaUnavailableException (org.simbasecurity.dwclient.exception.SimbaUnavailableException)4 Test (org.junit.Test)2 MediaType (javax.ws.rs.core.MediaType)1 Response (javax.ws.rs.core.Response)1 TException (org.apache.thrift.TException)1 TTransportException (org.apache.thrift.transport.TTransportException)1 ActionDescriptor (org.simbasecurity.api.service.thrift.ActionDescriptor)1 SimbaCredentials (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials)1 DWSimbaErrorR (org.simbasecurity.dwclient.dropwizard.representation.DWSimbaErrorR)1 SimbaUnavailableExceptionToJSONMapper (org.simbasecurity.dwclient.exception.mapper.SimbaUnavailableExceptionToJSONMapper)1