use of com.hack23.cia.service.api.action.application.CreateApplicationEventRequest 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.service.api.action.application.CreateApplicationEventRequest in project cia by Hack23.
the class RegisterUserService method createApplicationEventForService.
@Override
protected final CreateApplicationEventRequest createApplicationEventForService(final RegisterUserRequest serviceRequest) {
final CreateApplicationEventRequest eventRequest = new CreateApplicationEventRequest();
eventRequest.setEventGroup(ApplicationEventGroup.USER);
eventRequest.setApplicationOperation(ApplicationOperationType.CREATE);
eventRequest.setActionName(RegisterUserRequest.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 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.service.api.action.application.CreateApplicationEventRequest in project cia by Hack23.
the class DisableGoogleAuthenticatorCredentialService method createApplicationEventForService.
@Override
protected CreateApplicationEventRequest createApplicationEventForService(final DisableGoogleAuthenticatorCredentialRequest serviceRequest) {
final CreateApplicationEventRequest eventRequest = new CreateApplicationEventRequest();
eventRequest.setEventGroup(ApplicationEventGroup.USER);
eventRequest.setApplicationOperation(ApplicationOperationType.CREATE);
eventRequest.setActionName(DisableGoogleAuthenticatorCredentialRequest.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 SetGoogleAuthenticatorCredentialService method createApplicationEventForService.
@Override
protected CreateApplicationEventRequest createApplicationEventForService(final SetGoogleAuthenticatorCredentialRequest serviceRequest) {
final CreateApplicationEventRequest eventRequest = new CreateApplicationEventRequest();
eventRequest.setEventGroup(ApplicationEventGroup.USER);
eventRequest.setApplicationOperation(ApplicationOperationType.CREATE);
eventRequest.setActionName(SetGoogleAuthenticatorCredentialRequest.class.getSimpleName());
eventRequest.setSessionId(serviceRequest.getSessionId());
return eventRequest;
}
Aggregations