Search in sources :

Example 1 with ActionType

use of org.simbasecurity.api.service.thrift.ActionType in project simba-os by cegeka.

the class AddParameterToTargetActionTest method testExecute.

@Test
public void testExecute() throws Exception {
    ActionDescriptor actionDescriptor = new ActionDescriptor(new HashSet<ActionType>(), new HashMap<String, String>(), null, null, null, null);
    actionDescriptor.getActionTypes().add(ActionType.ADD_PARAMETER_TO_TARGET);
    String redirectURL = "http://localhost/redirect";
    actionDescriptor.setRedirectURL(redirectURL);
    actionDescriptor.getParameterMap().put("param1", "firstParam");
    actionDescriptor.getParameterMap().put("param2", "secondParam");
    AddParameterToTargetAction action = new AddParameterToTargetAction(actionDescriptor);
    action.execute();
    String resultUrl = action.getActionDescriptor().getRedirectURL();
    String expectedRedirectURL = redirectURL + "?param1=firstParam&param2=secondParam";
    assertEquals(expectedRedirectURL, resultUrl);
}
Also used : ActionType(org.simbasecurity.api.service.thrift.ActionType) ActionDescriptor(org.simbasecurity.api.service.thrift.ActionDescriptor) Test(org.junit.Test)

Example 2 with ActionType

use of org.simbasecurity.api.service.thrift.ActionType in project simba-os by cegeka.

the class RequestActionFactory method create.

@Override
public List<Action> create(final ActionDescriptor actionDescriptor) {
    EnumSet<ActionType> orderedActionTypes = EnumSet.noneOf(ActionType.class);
    orderedActionTypes.addAll(actionDescriptor.getActionTypes());
    final List<Action> actions = new ArrayList<Action>(4);
    for (final ActionType actionType : orderedActionTypes) {
        actions.add(createInstance(this.actionMap.get(actionType), actionDescriptor));
    }
    return actions;
}
Also used : ActionType(org.simbasecurity.api.service.thrift.ActionType) ArrayList(java.util.ArrayList)

Example 3 with ActionType

use of org.simbasecurity.api.service.thrift.ActionType in project simba-os by cegeka.

the class DoFilterAndSetPrincipalActionTest method testExecute_withPrincipal.

@Test
public void testExecute_withPrincipal() 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);
    actionDescriptor.setPrincipal("principal");
    DoFilterAndSetPrincipalAction action = new DoFilterAndSetPrincipalAction(actionDescriptor);
    action.setRequest(request);
    action.setResponse(response);
    action.setFilterChain(filterChain);
    action.execute();
    verify(filterChain).doFilter(any(HttpServletRequestWithPrincipal.class), any(HttpServletResponse.class));
}
Also used : ActionType(org.simbasecurity.api.service.thrift.ActionType) FilterChain(javax.servlet.FilterChain) ActionDescriptor(org.simbasecurity.api.service.thrift.ActionDescriptor) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpServletRequestWithPrincipal(org.simbasecurity.client.filter.request.HttpServletRequestWithPrincipal) Test(org.junit.Test)

Example 4 with ActionType

use of org.simbasecurity.api.service.thrift.ActionType in project simba-os by cegeka.

the class ChainContextImplTest method redirectToChangePasswordWithFilter_noToken.

@Test
public void redirectToChangePasswordWithFilter_noToken() {
    when(requestDataMock.getRequestURL()).thenReturn(URL_APPLICATION);
    when(requestDataMock.getLoginToken()).thenReturn(null);
    when(requestDataMock.getRequestParameters()).thenReturn(Collections.singletonMap(USERNAME, USERNAME));
    LoginMapping loginMapping = new LoginMappingEntity(URL_APPLICATION);
    when(loginMappingServiceMock.createMapping(URL_APPLICATION)).thenReturn(loginMapping);
    chainContextImpl.redirectToChangePasswordWithFilter();
    ActionDescriptor actionDescriptor = chainContextImpl.getActionDescriptor();
    Set<ActionType> actionTypes = actionDescriptor.getActionTypes();
    assertEquals(2, actionTypes.size());
    assertTrue(actionTypes.contains(ADD_PARAMETER_TO_TARGET));
    assertTrue(actionTypes.contains(REDIRECT));
    assertEquals(SIMBA_WEB_URL + SIMBA_CHANGEPASSWORD_PAGE_URL, actionDescriptor.getRedirectURL());
    Map<String, String> parameterMap = actionDescriptor.getParameterMap();
    assertEquals(2, parameterMap.size());
    assertTrue(parameterMap.containsKey(USERNAME));
    assertTrue(parameterMap.containsKey(LOGIN_TOKEN));
    Mockito.verify(loginMappingServiceMock).createMapping(URL_APPLICATION);
}
Also used : ActionType(org.simbasecurity.api.service.thrift.ActionType) ActionDescriptor(org.simbasecurity.api.service.thrift.ActionDescriptor) LoginMappingEntity(org.simbasecurity.core.domain.LoginMappingEntity) LoginMapping(org.simbasecurity.core.domain.LoginMapping) Test(org.junit.Test)

Example 5 with ActionType

use of org.simbasecurity.api.service.thrift.ActionType in project simba-os by cegeka.

the class ChainContextImplTest method redirectToLogin.

@Test
public void redirectToLogin() {
    when(requestDataMock.getRequestURL()).thenReturn(URL_APPLICATION);
    when(requestDataMock.getRequestParameters()).thenReturn(Collections.singletonMap(USERNAME, USERNAME));
    LoginMapping loginMapping = new LoginMappingEntity(URL_APPLICATION);
    when(loginMappingServiceMock.createMapping(URL_APPLICATION)).thenReturn(loginMapping);
    chainContextImpl.redirectToLogin();
    ActionDescriptor actionDescriptor = chainContextImpl.getActionDescriptor();
    Set<ActionType> actionTypes = actionDescriptor.getActionTypes();
    assertEquals(2, actionTypes.size());
    assertTrue(actionTypes.contains(ADD_PARAMETER_TO_TARGET));
    assertTrue(actionTypes.contains(REDIRECT));
    assertEquals(SIMBA_WEB_URL + SIMBA_LOGIN_PAGE_URL, actionDescriptor.getRedirectURL());
    Map<String, String> parameterMap = actionDescriptor.getParameterMap();
    assertEquals(1, parameterMap.size());
    assertTrue(parameterMap.containsKey(LOGIN_TOKEN));
    Mockito.verify(loginMappingServiceMock).createMapping(URL_APPLICATION);
}
Also used : ActionType(org.simbasecurity.api.service.thrift.ActionType) ActionDescriptor(org.simbasecurity.api.service.thrift.ActionDescriptor) LoginMappingEntity(org.simbasecurity.core.domain.LoginMappingEntity) LoginMapping(org.simbasecurity.core.domain.LoginMapping) Test(org.junit.Test)

Aggregations

ActionType (org.simbasecurity.api.service.thrift.ActionType)11 Test (org.junit.Test)10 ActionDescriptor (org.simbasecurity.api.service.thrift.ActionDescriptor)10 LoginMapping (org.simbasecurity.core.domain.LoginMapping)4 LoginMappingEntity (org.simbasecurity.core.domain.LoginMappingEntity)4 FilterChain (javax.servlet.FilterChain)2 ArrayList (java.util.ArrayList)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Ignore (org.junit.Ignore)1 SSOToken (org.simbasecurity.api.service.thrift.SSOToken)1 HttpServletRequestWithPrincipal (org.simbasecurity.client.filter.request.HttpServletRequestWithPrincipal)1