use of com.hack23.cia.model.internal.application.user.impl.UserAccount in project cia by Hack23.
the class LogoutService method processService.
@Override
@Secured({ "ROLE_USER", "ROLE_ADMIN" })
public LogoutResponse processService(final LogoutRequest serviceRequest) {
final LogoutResponse inputValidation = inputValidation(serviceRequest);
if (inputValidation != null) {
return inputValidation;
}
final CreateApplicationEventRequest eventRequest = createApplicationEventForService(serviceRequest);
final UserAccount userAccount = getUserAccountFromSecurityContext();
LogoutResponse response;
if (userAccount != null) {
eventRequest.setElementId(userAccount.getEmail());
eventRequest.setUserId(userAccount.getUserId());
final Collection<SimpleGrantedAuthority> authorities = new ArrayList<>();
authorities.add(new SimpleGrantedAuthority("ROLE_ANONYMOUS"));
final AnonymousAuthenticationToken anonymousAuthenticationToken = new AnonymousAuthenticationToken(serviceRequest.getSessionId(), "ROLE_ANONYMOUS", authorities);
SecurityContextHolder.getContext().setAuthentication(anonymousAuthenticationToken);
response = new LogoutResponse(ServiceResult.SUCCESS);
} else {
response = new LogoutResponse(ServiceResult.FAILURE);
}
eventRequest.setApplicationMessage(response.getResult().toString());
createApplicationEventService.processService(eventRequest);
LOGGER.info("Event: {}", eventRequest);
return response;
}
use of com.hack23.cia.model.internal.application.user.impl.UserAccount 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);
}
}
}
use of com.hack23.cia.model.internal.application.user.impl.UserAccount in project cia by Hack23.
the class ComplianceCheckServiceImpl method processService.
@Override
@Secured({ "ROLE_USER", "ROLE_ADMIN", "ROLE_ANONYMOUS" })
public ComplianceCheckResponse processService(final ComplianceCheckRequest serviceRequest) {
final ComplianceCheckResponse inputValidation = inputValidation(serviceRequest);
if (inputValidation != null) {
return inputValidation;
}
LOGGER.info("{}", serviceRequest.getClass().getSimpleName());
final CreateApplicationEventRequest eventRequest = createApplicationEventForService(serviceRequest);
final UserAccount userAccount = getUserAccountFromSecurityContext();
if (userAccount != null) {
eventRequest.setUserId(userAccount.getUserId());
}
final ComplianceCheckResponse response;
final Set<ConstraintViolation<ComplianceCheckRequest>> requestConstraintViolations = validateRequest(serviceRequest);
if (!requestConstraintViolations.isEmpty()) {
response = handleInputViolations(eventRequest, requestConstraintViolations, new ComplianceCheckResponse(ServiceResult.FAILURE));
} else {
final List<ComplianceCheck> complianceList = rulesEngine.checkRulesCompliance();
final List<RuleViolation> ruleViolations = new ArrayList<>();
for (final ComplianceCheck check : complianceList) {
ruleViolations.addAll(check.getRuleViolations());
}
Collections.sort(complianceList, new Comparator<ComplianceCheck>() {
@Override
public int compare(final ComplianceCheck o1, final ComplianceCheck o2) {
return Integer.compare(o2.getRuleViolations().size(), o1.getRuleViolations().size());
}
});
response = new ComplianceCheckResponse(ServiceResult.SUCCESS);
response.setList(complianceList);
response.setStatusMap(ruleViolations.stream().collect(Collectors.groupingBy(RuleViolation::getStatus)));
response.setResourceTypeMap(ruleViolations.stream().collect(Collectors.groupingBy(RuleViolation::getResourceType)));
eventRequest.setApplicationMessage(response.getResult().toString());
}
getCreateApplicationEventService().processService(eventRequest);
return response;
}
use of com.hack23.cia.model.internal.application.user.impl.UserAccount in project cia by Hack23.
the class ManageUserAccountServiceITest method manageUserAccountSuccessUnLockTest.
@Test
public void manageUserAccountSuccessUnLockTest() 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.UNLOCK);
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(1, allByAfterDelete.size());
assertEquals(allByAfterDelete.get(0).getUserLockStatus(), UserLockStatus.UNLOCKED);
}
use of com.hack23.cia.model.internal.application.user.impl.UserAccount in project cia by Hack23.
the class RemoveDataService method processService.
@Override
@Secured({ "ROLE_ADMIN" })
public RemoveDataResponse processService(final RemoveDataRequest serviceRequest) {
final RemoveDataResponse inputValidation = inputValidation(serviceRequest);
if (inputValidation != null) {
return inputValidation;
}
final CreateApplicationEventRequest eventRequest = createApplicationEventForService(serviceRequest);
final UserAccount userAccount = getUserAccountFromSecurityContext();
if (userAccount != null) {
eventRequest.setUserId(userAccount.getUserId());
}
final RemoveDataResponse response = new RemoveDataResponse(ServiceResult.SUCCESS);
switch(serviceRequest.getDataType()) {
case POLITICIAN:
removeDataManager.removePersonData();
break;
case DOCUMENTS:
removeDataManager.removeDocuments();
removeDataManager.removeCommitteeProposals();
removeDataManager.removeDocumentStatus();
break;
case APPLICATION_HISTORY:
removeDataManager.removeApplicationHistory();
break;
}
eventRequest.setApplicationMessage(response.getResult().toString());
createApplicationEventService.processService(eventRequest);
return response;
}
Aggregations