Search in sources :

Example 6 with SSOToken

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

the class MakeCookieAction method execute.

@Override
public void execute() throws ServletException, IOException {
    final SSOToken token = getActionDescriptor().getSsoToken();
    assertNotNull(token, "SSOToken should be present");
    Cookie cookie = new Cookie(RequestConstants.SIMBA_SSO_TOKEN, token.getToken());
    cookie.setHttpOnly(true);
    if (ENABLE_SECURE_COOKIES) {
        cookie.setSecure(true);
    }
    cookie.setPath("/");
    response.addCookie(cookie);
}
Also used : Cookie(javax.servlet.http.Cookie) SSOToken(org.simbasecurity.api.service.thrift.SSOToken)

Example 7 with SSOToken

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

the class UserService method changePassword.

@RequestMapping("changePassword")
@ResponseBody
public void changePassword(@RequestHeader(value = SIMBA_SSO_TOKEN, required = false) String ssoTokenFromHeader, @CookieValue(value = SIMBA_SSO_TOKEN, required = false) String ssoTokenFromCookie, @RequestBody ChangePasswordDTO changePasswordDTO, HttpServletResponse response) {
    String ssoToken = (ssoTokenFromHeader != null ? ssoTokenFromHeader : ssoTokenFromCookie);
    if (ssoToken == null || changePasswordDTO.getUserName() == null) {
        sendUnauthorizedError(response);
        return;
    }
    Session activeSession = sessionRepository.findBySSOToken(new SSOToken(ssoToken));
    if (activeSession == null) {
        sendUnauthorizedError(response);
        return;
    } else {
        User sessionUser = activeSession.getUser();
        User userThatNeedsPasswordChange = userRepository.findByName(changePasswordDTO.getUserName());
        if (!sessionUser.getUserName().equals(userThatNeedsPasswordChange.getUserName())) {
            sendUnauthorizedError(response);
            return;
        } else {
            try {
                userThatNeedsPasswordChange.changePassword(changePasswordDTO.getNewPassword(), changePasswordDTO.getNewPasswordConfirmation());
            } catch (SimbaException ex) {
                sendError(ErrorSender.UNABLE_TO_CHANGE_PASSWORD_ERROR_CODE, response, ex.getMessage());
                return;
            }
            userRepository.flush();
        }
    }
}
Also used : SimbaException(org.simbasecurity.core.exception.SimbaException) SSOToken(org.simbasecurity.api.service.thrift.SSOToken) User(org.simbasecurity.core.domain.User) Session(org.simbasecurity.core.domain.Session)

Example 8 with SSOToken

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

the class ChainContextImplTest method redirectToChangePasswordDirect_userIsInTheApplication_ClicksChangePwd.

@Test
public void redirectToChangePasswordDirect_userIsInTheApplication_ClicksChangePwd() {
    when(requestDataMock.getRequestURL()).thenReturn(URL_APPLICATION);
    SSOToken ssoToken = new SSOToken();
    when(requestDataMock.getSsoToken()).thenReturn(ssoToken);
    LoginMapping loginMapping = new LoginMappingEntity(URL_APPLICATION);
    when(loginMappingServiceMock.createMapping(URL_APPLICATION)).thenReturn(loginMapping);
    chainContextImpl.redirectToChangePasswordDirect();
    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(3, parameterMap.size());
    assertTrue(parameterMap.containsKey(USERNAME));
    assertTrue(parameterMap.containsKey(SIMBA_SSO_TOKEN));
    assertTrue(parameterMap.containsKey(LOGIN_TOKEN));
    Mockito.verify(loginMappingServiceMock).createMapping(URL_APPLICATION);
}
Also used : SSOToken(org.simbasecurity.api.service.thrift.SSOToken) 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 9 with SSOToken

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

the class DatabaseAuditLogProviderTest method auditEventIsPersisted_digestNotEnabled.

@Test
public void auditEventIsPersisted_digestNotEnabled() {
    when(configurationServiceMock.getValue(SimbaConfigurationParameter.AUDIT_LOG_INTEGRITY_ENABLED)).thenReturn(Boolean.FALSE);
    SSOToken ssoToken = new SSOToken();
    AuditLogEvent event = new AuditLogEvent(AuditLogEventCategory.SESSION, "username", ssoToken, "remoteIP", "message", "userAgent", "hostServerName", "surname", "firstname", "requestURL", "CHAINID");
    provider.log(event);
    jdbcTemplate.query("SELECT * FROM SIMBA_AUDIT_LOG WHERE ssoToken=?", getRowMapper(true), ssoToken.getToken());
}
Also used : AuditLogEvent(org.simbasecurity.core.audit.AuditLogEvent) SSOToken(org.simbasecurity.api.service.thrift.SSOToken) Test(org.junit.Test)

Example 10 with SSOToken

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

the class SimbaGatewayTest method login_WithUsernameAndPassword.

@Test
public void login_WithUsernameAndPassword() throws Exception {
    String username = "appUser";
    String password = "appPassword";
    Client authenticationServicemock = setupSimbaServiceToReturnASimbaAuthenticationService();
    SimbaCredentials simbaCredentials = mock(SimbaCredentials.class);
    RequestData requestData = mock(RequestData.class);
    SSOToken ssoToken = new SSOToken("token");
    ActionDescriptor actionDescriptor = new ActionDescriptorBuilderForTests().withActionTypes(ActionType.MAKE_COOKIE).withSsoToken(ssoToken).build();
    when(simbaCredentialsFactoryMock.createForLogin(username, password)).thenReturn(simbaCredentials);
    when(simbaCredentials.asRequestData()).thenReturn(requestData);
    when(authenticationServicemock.processRequest(requestData, LOGIN_AUTHENTICATE_CHAIN)).thenReturn(actionDescriptor);
    Optional<String> actual = simbaGateway.login(username, password);
    assertThat(actual.get()).isEqualTo(ssoToken.getToken());
}
Also used : SSOToken(org.simbasecurity.api.service.thrift.SSOToken) ActionDescriptorBuilderForTests(org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests) SimbaCredentials(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials) RequestData(org.simbasecurity.api.service.thrift.RequestData) ActionDescriptor(org.simbasecurity.api.service.thrift.ActionDescriptor) Client(org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client) THttpClient(org.apache.thrift.transport.THttpClient) Test(org.junit.Test)

Aggregations

SSOToken (org.simbasecurity.api.service.thrift.SSOToken)19 Test (org.junit.Test)14 RequestData (org.simbasecurity.api.service.thrift.RequestData)7 ActionDescriptor (org.simbasecurity.api.service.thrift.ActionDescriptor)5 THttpClient (org.apache.thrift.transport.THttpClient)4 Client (org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client)4 AuditLogEvent (org.simbasecurity.core.audit.AuditLogEvent)4 Session (org.simbasecurity.core.domain.Session)4 SimbaCredentials (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials)4 ActionDescriptorBuilderForTests (org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests)4 User (org.simbasecurity.core.domain.User)3 State (org.simbasecurity.core.chain.Command.State)2 SessionEntity (org.simbasecurity.core.domain.SessionEntity)2 SimbaPrincipal (org.simbasecurity.dwclient.dropwizard.credentials.SimbaPrincipal)2 ContainerRequest (com.sun.jersey.spi.container.ContainerRequest)1 Cookie (javax.servlet.http.Cookie)1 ActionType (org.simbasecurity.api.service.thrift.ActionType)1 TSession (org.simbasecurity.api.service.thrift.TSession)1 TUser (org.simbasecurity.api.service.thrift.TUser)1 LoginMapping (org.simbasecurity.core.domain.LoginMapping)1