Search in sources :

Example 1 with ApplicationActionEvent

use of com.hack23.cia.model.internal.application.system.impl.ApplicationActionEvent in project cia by Hack23.

the class AdminApplicationEventsPageModContentFactoryImpl method createContent.

@Secured({ "ROLE_ADMIN" })
@Override
public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
    final VerticalLayout content = createPanelContent();
    final String pageId = getPageId(parameters);
    final int pageNr = getPageNr(parameters);
    getMenuItemFactory().createMainPageMenuBar(menuBar);
    LabelFactory.createHeader2Label(content, ADMIN_APPLICATION_ACTION_EVENT);
    final DataContainer<ApplicationActionEvent, Long> dataContainer = getApplicationManager().getDataContainer(ApplicationActionEvent.class);
    final List<ApplicationActionEvent> pageOrderBy = dataContainer.getPageOrderBy(pageNr, DEFAULT_RESULTS_PER_PAGE, ApplicationActionEvent_.createdDate);
    createPagingControls(content, NAME, pageId, dataContainer.getSize(), pageNr, DEFAULT_RESULTS_PER_PAGE);
    getGridFactory().createBasicBeanItemGrid(content, ApplicationActionEvent.class, pageOrderBy, APPLICATION_ACTION_EVENT, COLUMN_ORDER, HIDE_COLUMNS, LISTENER, null, null);
    if (pageId != null && !pageId.isEmpty()) {
        final ApplicationActionEvent applicationActionEvent = dataContainer.load(Long.valueOf(pageId));
        if (applicationActionEvent != null) {
            getFormFactory().addFormPanelTextFields(content, applicationActionEvent, ApplicationActionEvent.class, AS_LIST);
        }
    }
    getPageActionEventHelper().createPageEvent(ViewAction.VISIT_ADMIN_APPLICATION_EVENTS_VIEW, ApplicationEventGroup.ADMIN, NAME, null, pageId);
    return content;
}
Also used : ApplicationActionEvent(com.hack23.cia.model.internal.application.system.impl.ApplicationActionEvent) VerticalLayout(com.vaadin.ui.VerticalLayout) Secured(org.springframework.security.access.annotation.Secured)

Example 2 with ApplicationActionEvent

use of com.hack23.cia.model.internal.application.system.impl.ApplicationActionEvent in project cia by Hack23.

the class LoginBlockedAccessImpl method blockByUserFailedLoginAttempts.

/**
 * Block by user failed login attempts.
 *
 * @param email
 *            the email
 * @param loginBlockResultImpl
 *            the login block result impl
 */
private void blockByUserFailedLoginAttempts(final String email, final LoginBlockResultImpl loginBlockResultImpl) {
    final UserAccount userExist = userDAO.findFirstByProperty(UserAccount_.email, email);
    if (userExist != null) {
        final ApplicationConfiguration maxLoginAttemptsByUser = applicationConfigurationService.checkValueOrLoadDefault(MAX_FAILED_LOGIN_ATTEMPTS_RECENT_HOUR_PER_USER, BLOCKS_ANY_LOGIN_ATTEMPTS_AFTER_THIS_NUMBER_IS_REACHED, ConfigurationGroup.AUTHENTICATION, LoginBlockedAccessImpl.class.getSimpleName(), LOGIN_BLOCKER, BLOCKS_LOGIN_ATTEMPTS, APPLICATION_AUTHENTICATION_ALLOW_MAX_RECENT_FAILED_LOGINS_BY_USER, DEFAULT_MAX_LOGIN_ATTEMPTS);
        final List<ApplicationActionEvent> failedLoginsByThisUser = applicationActionEventDAO.findListByProperty(new Object[] { email, ApplicationOperationType.AUTHENTICATION, ServiceResult.FAILURE.toString() }, ApplicationActionEvent_.elementId, ApplicationActionEvent_.applicationOperation, ApplicationActionEvent_.applicationMessage);
        final Date oneHourAgo = new Date(System.currentTimeMillis() - ONE_HOUR);
        final Map<Boolean, List<ApplicationActionEvent>> recentOldLoginAttemptsMap = failedLoginsByThisUser.stream().collect(Collectors.groupingBy((final ApplicationActionEvent x) -> x.getCreatedDate().after(oneHourAgo)));
        final List<ApplicationActionEvent> recentFailedLogins = recentOldLoginAttemptsMap.get(Boolean.TRUE);
        if (recentFailedLogins != null && recentFailedLogins.size() > NumberUtils.toInt(maxLoginAttemptsByUser.getPropertyValue(), DEFAULT_MAX_LOGINS)) {
            loginBlockResultImpl.setBlocked(true);
            loginBlockResultImpl.addMessages(BLOCKED_BY_MORE_THAN_5_RECENT_LOGIN_ATTEMPTS_BY_THIS_USER);
        }
    }
}
Also used : ApplicationActionEvent(com.hack23.cia.model.internal.application.system.impl.ApplicationActionEvent) ArrayList(java.util.ArrayList) List(java.util.List) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount) ApplicationConfiguration(com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration) Date(java.util.Date)

Example 3 with ApplicationActionEvent

use of com.hack23.cia.model.internal.application.system.impl.ApplicationActionEvent in project cia by Hack23.

the class CreateApplicationEventService method processService.

@Override
public CreateApplicationEventResponse processService(final CreateApplicationEventRequest serviceRequest) {
    final CreateApplicationEventResponse inputValidation = inputValidation(serviceRequest);
    if (inputValidation != null) {
        return inputValidation;
    }
    final ApplicationSession applicationSession = applicationSessionDAO.findFirstByProperty(ApplicationSession_.sessionId, serviceRequest.getSessionId());
    if (applicationSession != null) {
        final ApplicationActionEvent applicationActionEvent = new ApplicationActionEvent();
        applicationActionEvent.setEventGroup(serviceRequest.getEventGroup());
        applicationActionEvent.setCreatedDate(new Date());
        applicationActionEvent.setSessionId(serviceRequest.getSessionId());
        applicationActionEvent.setPage(serviceRequest.getPage());
        applicationActionEvent.setPageMode(serviceRequest.getPageMode());
        applicationActionEvent.setElementId(serviceRequest.getElementId());
        applicationActionEvent.setApplicationOperation(serviceRequest.getApplicationOperation());
        applicationActionEvent.setActionName(serviceRequest.getActionName());
        applicationActionEvent.setUserId(serviceRequest.getUserId());
        if (serviceRequest.getUserId() != null && ApplicationSessionType.ANONYMOUS == applicationSession.getSessionType()) {
            applicationSession.setSessionType(ApplicationSessionType.REGISTERED_USER);
            applicationSession.setUserId(serviceRequest.getUserId());
        }
        applicationActionEvent.setApplicationMessage(serviceRequest.getApplicationMessage());
        applicationActionEvent.setErrorMessage(serviceRequest.getErrorMessage());
        applicationSession.getEvents().add(applicationActionEvent);
        applicationSessionDAO.persist(applicationSession);
        return new CreateApplicationEventResponse(ServiceResult.SUCCESS);
    } else {
        return new CreateApplicationEventResponse(ServiceResult.FAILURE);
    }
}
Also used : ApplicationSession(com.hack23.cia.model.internal.application.system.impl.ApplicationSession) ApplicationActionEvent(com.hack23.cia.model.internal.application.system.impl.ApplicationActionEvent) CreateApplicationEventResponse(com.hack23.cia.service.api.action.application.CreateApplicationEventResponse) Date(java.util.Date)

Example 4 with ApplicationActionEvent

use of com.hack23.cia.model.internal.application.system.impl.ApplicationActionEvent in project cia by Hack23.

the class LoginBlockedAccessImpl method blockBySessionOrIpFailedLoginAttempts.

/**
 * Block by session or ip failed login attempts.
 *
 * @param sessionId
 *            the session id
 * @param loginBlockResultImpl
 *            the login block result impl
 */
private void blockBySessionOrIpFailedLoginAttempts(final String sessionId, final LoginBlockResultImpl loginBlockResultImpl) {
    final ApplicationSession applicationSession = applicationSessionDAO.findFirstByProperty(ApplicationSession_.sessionId, sessionId);
    if (applicationSession != null) {
        final ApplicationConfiguration maxLoginAttemptsBySession = applicationConfigurationService.checkValueOrLoadDefault(MAX_FAILED_LOGIN_ATTEMPTS_RECENT_HOUR_PER_SESSION, BLOCKS_ANY_LOGIN_ATTEMPTS_AFTER_THIS_NUMBER_IS_REACHED, ConfigurationGroup.AUTHENTICATION, LoginBlockedAccessImpl.class.getSimpleName(), LOGIN_BLOCKER, BLOCKS_LOGIN_ATTEMPTS, APPLICATION_AUTHENTICATION_ALLOW_MAX_RECENT_FAILED_LOGINS_BY_SESSION, DEFAULT_MAX_LOGIN_ATTEMPTS);
        final List<ApplicationActionEvent> failedLoginsByThisSession = applicationActionEventDAO.findListByProperty(new Object[] { sessionId, ApplicationOperationType.AUTHENTICATION, ServiceResult.FAILURE.toString() }, ApplicationActionEvent_.sessionId, ApplicationActionEvent_.applicationOperation, ApplicationActionEvent_.applicationMessage);
        if (failedLoginsByThisSession.size() > NumberUtils.toInt(maxLoginAttemptsBySession.getPropertyValue(), DEFAULT_MAX_LOGINS)) {
            loginBlockResultImpl.setBlocked(true);
            loginBlockResultImpl.addMessages(BLOCKED_BY_MORE_THAN_5_LOGIN_ATTEMPTS_BY_THIS_SESSION);
        }
        if (!("0:0:0:0:0:0:0:1".equals(applicationSession.getIpInformation()) || "127.0.0.1".equals(applicationSession.getIpInformation()))) {
            final List<ApplicationSession> applicationSessionsByIp = applicationSessionDAO.findListByProperty(ApplicationSession_.ipInformation, applicationSession.getIpInformation());
            final List<String> sessionIdsWithIp = applicationSessionsByIp.stream().map(ApplicationSession::getSessionId).collect(Collectors.toList());
            final List<ApplicationActionEvent> applicationEventsWithIp = applicationActionEventDAO.findListByPropertyInList(ApplicationActionEvent_.sessionId, sessionIdsWithIp.toArray(new Object[sessionIdsWithIp.size()]));
            final Date oneHourAgo = new Date(System.currentTimeMillis() - ONE_HOUR);
            final Map<Boolean, List<ApplicationActionEvent>> recentOldLoginAttemptsMap = applicationEventsWithIp.stream().filter((final ApplicationActionEvent x) -> x.getApplicationOperation() == ApplicationOperationType.AUTHENTICATION && x.getApplicationMessage().equals(ServiceResult.FAILURE.toString())).collect(Collectors.groupingBy((final ApplicationActionEvent x) -> x.getCreatedDate().after(oneHourAgo)));
            final List<ApplicationActionEvent> recentFailedLogins = recentOldLoginAttemptsMap.get(Boolean.TRUE);
            final ApplicationConfiguration maxLoginAttemptsByIp = applicationConfigurationService.checkValueOrLoadDefault(MAX_FAILED_LOGIN_ATTEMPTS_RECENT_HOUR_PER_IP, BLOCKS_ANY_LOGIN_ATTEMPTS_AFTER_THIS_NUMBER_IS_REACHED, ConfigurationGroup.AUTHENTICATION, LoginBlockedAccessImpl.class.getSimpleName(), LOGIN_BLOCKER, BLOCKS_LOGIN_ATTEMPTS, APPLICATION_AUTHENTICATION_ALLOW_MAX_RECENT_FAILED_LOGINS_BY_IP, DEFAULT_MAX_LOGIN_ATTEMPTS);
            if (recentFailedLogins != null && recentFailedLogins.size() > NumberUtils.toInt(maxLoginAttemptsByIp.getPropertyValue(), DEFAULT_MAX_LOGINS_BY_IP)) {
                loginBlockResultImpl.setBlocked(true);
                loginBlockResultImpl.addMessages(BLOCKED_BY_MORE_THAN_5_RECENT_LOGIN_ATTEMPTS_BY_THIS_IP);
            }
        }
    }
}
Also used : ApplicationSession(com.hack23.cia.model.internal.application.system.impl.ApplicationSession) Date(java.util.Date) ApplicationActionEvent(com.hack23.cia.model.internal.application.system.impl.ApplicationActionEvent) ArrayList(java.util.ArrayList) List(java.util.List) ApplicationConfiguration(com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration)

Example 5 with ApplicationActionEvent

use of com.hack23.cia.model.internal.application.system.impl.ApplicationActionEvent in project cia by Hack23.

the class ManageUserAccountServiceITest method manageUserAccountSuccessDeleteTest.

@Test
public void manageUserAccountSuccessDeleteTest() throws Exception {
    setAuthenticatedAnonymousUser();
    final CreateApplicationSessionRequest createSessionRequest = createTestApplicationSession();
    final RegisterUserRequest createAccountRequest = new RegisterUserRequest();
    createAccountRequest.setCountry("Sweden");
    createAccountRequest.setUsername(UUID.randomUUID().toString());
    createAccountRequest.setEmail(createAccountRequest.getUsername() + "@email.com");
    createAccountRequest.setUserpassword("Userpassword1!");
    createAccountRequest.setUserType(UserType.PRIVATE);
    createAccountRequest.setSessionId(createSessionRequest.getSessionId());
    final RegisterUserResponse response = (RegisterUserResponse) applicationManager.service(createAccountRequest);
    assertNotNull("Expect a result", response);
    assertEquals(EXPECT_SUCCESS, ServiceResult.SUCCESS, response.getResult());
    setAuthenticatedAdminuser();
    final DataContainer<UserAccount, Long> userContainer = applicationManager.getDataContainer(UserAccount.class);
    final List<UserAccount> firstCreatedUsed = userContainer.getAllBy(UserAccount_.username, createAccountRequest.getUsername());
    assertEquals(1, firstCreatedUsed.size());
    final ManageUserAccountRequest deleteAccountRequest = new ManageUserAccountRequest();
    deleteAccountRequest.setSessionId(createSessionRequest.getSessionId());
    deleteAccountRequest.setAccountOperation(AccountOperation.DELETE);
    deleteAccountRequest.setUserAcountId(firstCreatedUsed.get(0).getUserId());
    final ManageUserAccountResponse deleteAccountResponse = (ManageUserAccountResponse) applicationManager.service(deleteAccountRequest);
    assertNotNull(EXPECT_A_RESULT, deleteAccountResponse);
    assertEquals(EXPECT_SUCCESS, ServiceResult.SUCCESS, deleteAccountResponse.getResult());
    final List<UserAccount> allByAfterDelete = userContainer.getAllBy(UserAccount_.username, createAccountRequest.getUsername());
    assertEquals(0, allByAfterDelete.size());
    final DataContainer<ApplicationActionEvent, Long> eventContainer = applicationManager.getDataContainer(ApplicationActionEvent.class);
    final List<ApplicationActionEvent> events = eventContainer.getAllBy(ApplicationActionEvent_.userId, firstCreatedUsed.get(0).getUserId());
    assertEquals(0, events.size());
    final DataContainer<ApplicationSession, Serializable> sessionContainer = applicationManager.getDataContainer(ApplicationSession.class);
    final List<ApplicationSession> sessions = sessionContainer.getAllBy(ApplicationSession_.userId, firstCreatedUsed.get(0).getUserId());
    assertEquals(0, sessions.size());
}
Also used : ApplicationSession(com.hack23.cia.model.internal.application.system.impl.ApplicationSession) Serializable(java.io.Serializable) RegisterUserRequest(com.hack23.cia.service.api.action.application.RegisterUserRequest) ApplicationActionEvent(com.hack23.cia.model.internal.application.system.impl.ApplicationActionEvent) CreateApplicationSessionRequest(com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest) ManageUserAccountRequest(com.hack23.cia.service.api.action.admin.ManageUserAccountRequest) RegisterUserResponse(com.hack23.cia.service.api.action.application.RegisterUserResponse) ManageUserAccountResponse(com.hack23.cia.service.api.action.admin.ManageUserAccountResponse) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount) Test(org.junit.Test) AbstractServiceFunctionalIntegrationTest(com.hack23.cia.service.impl.AbstractServiceFunctionalIntegrationTest)

Aggregations

ApplicationActionEvent (com.hack23.cia.model.internal.application.system.impl.ApplicationActionEvent)6 ApplicationSession (com.hack23.cia.model.internal.application.system.impl.ApplicationSession)3 UserAccount (com.hack23.cia.model.internal.application.user.impl.UserAccount)3 Date (java.util.Date)3 ApplicationConfiguration (com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration)2 VerticalLayout (com.vaadin.ui.VerticalLayout)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Secured (org.springframework.security.access.annotation.Secured)2 ManageUserAccountRequest (com.hack23.cia.service.api.action.admin.ManageUserAccountRequest)1 ManageUserAccountResponse (com.hack23.cia.service.api.action.admin.ManageUserAccountResponse)1 CreateApplicationEventResponse (com.hack23.cia.service.api.action.application.CreateApplicationEventResponse)1 CreateApplicationSessionRequest (com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest)1 RegisterUserRequest (com.hack23.cia.service.api.action.application.RegisterUserRequest)1 RegisterUserResponse (com.hack23.cia.service.api.action.application.RegisterUserResponse)1 AbstractServiceFunctionalIntegrationTest (com.hack23.cia.service.impl.AbstractServiceFunctionalIntegrationTest)1 Serializable (java.io.Serializable)1 Test (org.junit.Test)1