use of com.hack23.cia.service.api.action.application.CreateApplicationEventRequest 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);
}
}
use of com.hack23.cia.service.api.action.application.CreateApplicationEventRequest in project cia by Hack23.
the class LoginService method createApplicationEventForService.
@Override
protected CreateApplicationEventRequest createApplicationEventForService(final LoginRequest serviceRequest) {
final CreateApplicationEventRequest eventRequest = new CreateApplicationEventRequest();
eventRequest.setEventGroup(ApplicationEventGroup.USER);
eventRequest.setApplicationOperation(ApplicationOperationType.AUTHENTICATION);
eventRequest.setActionName(LoginRequest.class.getSimpleName());
eventRequest.setSessionId(serviceRequest.getSessionId());
eventRequest.setElementId(serviceRequest.getEmail());
return eventRequest;
}
use of com.hack23.cia.service.api.action.application.CreateApplicationEventRequest in project cia by Hack23.
the class LoginService method processService.
@Override
@Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
public LoginResponse processService(final LoginRequest serviceRequest) {
final LoginResponse inputValidation = inputValidation(serviceRequest);
if (inputValidation != null) {
return inputValidation;
}
final CreateApplicationEventRequest eventRequest = createApplicationEventForService(serviceRequest);
final UserAccount userExist = userDAO.findFirstByProperty(UserAccount_.email, serviceRequest.getEmail());
final LoginBlockResult loginBlockResult = loginBlockedAccess.isBlocked(serviceRequest.getSessionId(), serviceRequest.getEmail());
LoginResponse response;
if (!loginBlockResult.isBlocked() && userExist != null && userExist.getUserLockStatus() == UserLockStatus.UNLOCKED && verifyOtp(serviceRequest, userExist) && passwordEncoder.matches(userExist.getUserId() + ".uuid" + serviceRequest.getUserpassword(), userExist.getUserpassword())) {
final Collection<SimpleGrantedAuthority> authorities = new ArrayList<>();
if (UserRole.ADMIN == userExist.getUserRole()) {
authorities.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
} else if (UserRole.USER == userExist.getUserRole()) {
authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
}
eventRequest.setUserId(userExist.getUserId());
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(userExist, userExist.getUserpassword(), authorities));
userExist.setNumberOfVisits(userExist.getNumberOfVisits() + 1);
userDAO.persist(userExist);
response = new LoginResponse(ServiceResult.SUCCESS);
} else {
response = new LoginResponse(ServiceResult.FAILURE);
response.setErrorMessage(LoginResponse.ErrorMessage.USERNAME_OR_PASSWORD_DO_NOT_MATCH.toString());
if (loginBlockResult.isBlocked()) {
eventRequest.setErrorMessage(loginBlockResult.getMessages().toString());
} else {
eventRequest.setErrorMessage(LoginResponse.ErrorMessage.USERNAME_OR_PASSWORD_DO_NOT_MATCH.toString());
}
}
eventRequest.setApplicationMessage(response.getResult().toString());
createApplicationEventService.processService(eventRequest);
LOGGER.info("Event: {}", eventRequest);
return response;
}
use of com.hack23.cia.service.api.action.application.CreateApplicationEventRequest in project cia by Hack23.
the class LogoutService method createApplicationEventForService.
@Override
protected CreateApplicationEventRequest createApplicationEventForService(final LogoutRequest serviceRequest) {
final CreateApplicationEventRequest eventRequest = new CreateApplicationEventRequest();
eventRequest.setEventGroup(ApplicationEventGroup.USER);
eventRequest.setApplicationOperation(ApplicationOperationType.AUTHENTICATION);
eventRequest.setActionName(LogoutRequest.class.getSimpleName());
eventRequest.setSessionId(serviceRequest.getSessionId());
return eventRequest;
}
use of com.hack23.cia.service.api.action.application.CreateApplicationEventRequest in project cia by Hack23.
the class RegisterUserService method processService.
@Override
@Secured({ "ROLE_ANONYMOUS" })
public RegisterUserResponse processService(final RegisterUserRequest serviceRequest) {
final RegisterUserResponse inputValidation = inputValidation(serviceRequest);
if (inputValidation != null) {
return inputValidation;
}
final CreateApplicationEventRequest eventRequest = createApplicationEventForService(serviceRequest);
RegisterUserResponse response;
final ApplicationConfiguration registeredUsersGetAdminConfig = applicationConfigurationService.checkValueOrLoadDefault("Registered User All get Role Admin", "Registered User All get Role Admin", ConfigurationGroup.AUTHORIZATION, RegisterUserService.class.getSimpleName(), "Register User Service", "Responsible for create of useraccounts", "registered.users.get.admin", "true");
final UserAccount userNameExist = userDAO.findFirstByProperty(UserAccount_.username, serviceRequest.getUsername());
final UserAccount userEmailExist = userDAO.findFirstByProperty(UserAccount_.email, serviceRequest.getEmail());
final RuleResult passwordRuleResults = passwordValidator.validate(new PasswordData(serviceRequest.getUserpassword()));
if (userEmailExist == null && userNameExist == null && passwordRuleResults.isValid()) {
final UserAccount userAccount = new UserAccount();
userAccount.setCountry(serviceRequest.getCountry());
userAccount.setEmail(serviceRequest.getEmail());
userAccount.setUsername(serviceRequest.getUsername());
userAccount.setUserId(UUID.randomUUID().toString());
userAccount.setUserpassword(passwordEncoder.encode(userAccount.getUserId() + ".uuid" + serviceRequest.getUserpassword()));
userAccount.setNumberOfVisits(1);
if (serviceRequest.getUserType() == null) {
userAccount.setUserType(UserType.PRIVATE);
} else {
userAccount.setUserType(serviceRequest.getUserType());
}
userAccount.setUserEmailStatus(UserEmailStatus.UNKNOWN);
userAccount.setUserLockStatus(UserLockStatus.UNLOCKED);
userAccount.setCreatedDate(new Date());
userDAO.persist(userAccount);
if ("true".equals(registeredUsersGetAdminConfig.getPropertyValue())) {
userAccount.setUserRole(UserRole.ADMIN);
} else {
userAccount.setUserRole(UserRole.USER);
}
final Collection<SimpleGrantedAuthority> authorities = new ArrayList<>();
if (UserRole.ADMIN == userAccount.getUserRole()) {
authorities.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
} else if (UserRole.USER == userAccount.getUserRole()) {
authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
}
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(userAccount, userAccount.getUserpassword(), authorities));
eventRequest.setUserId(userAccount.getUserId());
response = new RegisterUserResponse(ServiceResult.SUCCESS);
} else {
response = new RegisterUserResponse(ServiceResult.FAILURE);
if (passwordRuleResults.isValid()) {
response.setErrorMessage(RegisterUserResponse.ErrorMessage.USER_ALREADY_EXIST.toString());
eventRequest.setErrorMessage(RegisterUserResponse.ErrorMessage.USER_ALREADY_EXIST.toString());
} else {
final String errorMessage = passwordValidator.getMessages(passwordRuleResults).toString();
response.setErrorMessage(errorMessage);
eventRequest.setErrorMessage(errorMessage);
}
}
eventRequest.setApplicationMessage(response.getResult().toString());
createApplicationEventService.processService(eventRequest);
LOGGER.info("Event: {}", eventRequest);
return response;
}
Aggregations