use of org.apache.thrift.transport.THttpClient in project simba-os by cegeka.
the class SimbaGatewayTest method authenticate_THttpClientAlwaysGetsClosed.
@Test
public void authenticate_THttpClientAlwaysGetsClosed() throws Exception {
Client expectedClient = mock(Client.class);
THttpClient tHttpClientMock = mock(THttpClient.class);
when(simbaServiceFactoryMock.createTHttpClient(SIMBA_WEB_URL + "/" + SIMBA_AUTHENTICATION_SERVICE)).thenReturn(tHttpClientMock);
when(simbaServiceFactoryMock.createJSONAuthenticationFilterService(tHttpClientMock)).thenReturn(expectedClient);
Client authenticationServiceMock = expectedClient;
when(authenticationServiceMock.processRequest(any(RequestData.class), eq(SimbaGateway.SESSION_AUTHENTICATE_CHAIN))).thenReturn(new ActionDescriptorBuilderForTests().withActionTypes().build());
simbaGateway.authenticate(new SimbaCredentialsBuilderForTests().build());
verify(tHttpClientMock, times(1)).close();
}
use of org.apache.thrift.transport.THttpClient in project simba-os by cegeka.
the class JerseyBasicAuthenticationFilter method filter.
@Override
public void filter(ContainerRequestContext containerRequestContext) throws IOException {
ContainerRequest containerRequest = (ContainerRequest) containerRequestContext.getRequest();
Map<String, String> requestParameters = toMap(containerRequestContext.getUriInfo().getQueryParameters());
List<String> auth = containerRequest.getRequestHeader("authorization");
if (auth == null || auth.isEmpty()) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
String[] credentials = decode(auth.get(0));
requestParameters.put(AuthenticationConstants.USERNAME, credentials[0]);
requestParameters.put(AuthenticationConstants.PASSWORD, credentials[1]);
RequestData requestData = new RequestData(requestParameters, toMap(containerRequest.getRequestHeaders()), containerRequest.getAbsolutePath().toString(), simbaWebURL, null, /* SSO Token */
null, /* Client IP */
false, false, false, false, false, containerRequest.getMethod(), RequestUtil.HOST_SERVER_NAME, null, null);
THttpClient tHttpClient = null;
try {
tHttpClient = new THttpClient(SimbaConfiguration.getSimbaAuthenticationURL());
TProtocol tProtocol = new TJSONProtocol(tHttpClient);
AuthenticationFilterService.Client authenticationClient = new AuthenticationFilterService.Client(tProtocol);
ActionDescriptor actionDescriptor = authenticationClient.processRequest(requestData, "wsLoginChain");
if (!actionDescriptor.getActionTypes().contains(ActionType.DO_FILTER_AND_SET_PRINCIPAL)) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
} catch (Exception e) {
e.printStackTrace();
throw new WebApplicationException(e, Response.Status.UNAUTHORIZED);
} finally {
if (tHttpClient != null) {
tHttpClient.close();
}
}
}
use of org.apache.thrift.transport.THttpClient in project simba-os by cegeka.
the class BaseRESTService method cl.
T cl(String ssoToken) throws TException {
THttpClient tHttpClient = new THttpClient(serviceURL);
tHttpClient.setCustomHeader("Cookie", SIMBA_SSO_TOKEN + "=" + ssoToken);
TProtocol tProtocol = new TJSONProtocol(tHttpClient);
return clientFactory.getClient(tProtocol);
}
use of org.apache.thrift.transport.THttpClient in project sw360portal by sw360.
the class TestUserClient method main.
public static void main(String[] args) throws TException, IOException {
THttpClient thriftClient = new THttpClient("http://127.0.0.1:8080/users/thrift");
TProtocol protocol = new TCompactProtocol(thriftClient);
UserService.Iface client = new UserService.Client(protocol);
System.out.println(client.getByEmail("cedric.bodet@tngtech.com"));
}
use of org.apache.thrift.transport.THttpClient in project sw360portal by sw360.
the class TestModerationClient method main.
public static void main(String[] args) throws TException, IOException {
THttpClient thriftClient = new THttpClient("http://127.0.0.1:8080//moderation/thrift");
TProtocol protocol = new TCompactProtocol(thriftClient);
ModerationService.Iface client = new ModerationService.Client(protocol);
List<ModerationRequest> requestsByModerator = client.getRequestsByModerator(new User().setId("").setEmail("cedric.bodet@tngtech.com").setDepartment("BB"));
System.out.println("Fetched " + requestsByModerator.size() + " moderation requests from moderation service");
}
Aggregations