use of org.simbasecurity.api.service.thrift.ActionDescriptor in project simba-os by cegeka.
the class SimbaJAXWSHandlerTest method soapAuthenticationSuccessful.
@Test
@Ignore
public // TODO: Create integration test
void soapAuthenticationSuccessful() throws Exception {
ActionDescriptor actionDescriptor = new ActionDescriptor(new HashSet<ActionType>(), new HashMap<String, String>(), null, null, null, null);
actionDescriptor.getActionTypes().add(ActionType.DO_FILTER_AND_SET_PRINCIPAL);
actionDescriptor.setPrincipal("principal");
// when(simbaServiceMock.processRequest(getChainConfiguration())).thenReturn(actionDescriptor);
handler.handleMessage(messageContextMock);
verify(messageContextMock).put(SimbaPrincipal.SIMBA_USER_CTX_KEY, "principal");
}
use of org.simbasecurity.api.service.thrift.ActionDescriptor 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(simbaWebURL + "/authenticationService");
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.simbasecurity.api.service.thrift.ActionDescriptor in project simba-os by cegeka.
the class RedirectActionTest method testExecute.
@Test
public void testExecute() throws Exception {
ActionDescriptor actionDescriptor = new ActionDescriptor(new HashSet<>(), new HashMap<>(), null, null, null, null);
actionDescriptor.getActionTypes().add(ActionType.REDIRECT);
String redirectURL = "redirectURL";
actionDescriptor.setRedirectURL(redirectURL);
RedirectAction action = new RedirectAction(actionDescriptor);
action.setRequest(request);
action.setResponse(response);
action.execute();
Mockito.verify(response).sendRedirect(redirectURL);
}
use of org.simbasecurity.api.service.thrift.ActionDescriptor in project simba-os by cegeka.
the class MakeCookieActionTest method testExecute.
@Test
public void testExecute() throws Exception {
ActionDescriptor actionDescriptor = new ActionDescriptor(new HashSet<>(), new HashMap<>(), null, null, null, null);
actionDescriptor.getActionTypes().add(ActionType.MAKE_COOKIE);
actionDescriptor.setSsoToken(SSO_TOKEN);
MakeCookieAction action = new MakeCookieAction(actionDescriptor);
action.setRequest(request);
action.setResponse(response);
action.execute();
ArgumentCaptor<Cookie> captor = ArgumentCaptor.forClass(Cookie.class);
verify(response).addCookie(captor.capture());
Cookie cookie = captor.getValue();
assertThat(cookie.getName()).isEqualTo(RequestConstants.SIMBA_SSO_TOKEN);
assertThat(cookie.getValue()).isEqualTo(SSO_TOKEN.getToken());
assertThat(cookie.getSecure()).isFalse();
assertThat(cookie.isHttpOnly()).isTrue();
assertThat(cookie.getPath()).isEqualTo("/");
}
use of org.simbasecurity.api.service.thrift.ActionDescriptor in project simba-os by cegeka.
the class DoFilterAndSetPrincipalActionTest method testExecute_withoutPrincipal.
@Test
public void testExecute_withoutPrincipal() throws Exception {
FilterChain filterChain = mock(FilterChain.class);
ActionDescriptor actionDescriptor = new ActionDescriptor(new HashSet<ActionType>(), new HashMap<String, String>(), null, null, null, null);
actionDescriptor.getActionTypes().add(ActionType.DO_FILTER_AND_SET_PRINCIPAL);
DoFilterAndSetPrincipalAction action = new DoFilterAndSetPrincipalAction(actionDescriptor);
action.setRequest(request);
action.setResponse(response);
action.setFilterChain(filterChain);
action.execute();
verify(filterChain).doFilter(request, response);
}
Aggregations