Search in sources :

Example 1 with CreateApplicationEventRequest

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;
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) LogoutResponse(com.hack23.cia.service.api.action.application.LogoutResponse) ArrayList(java.util.ArrayList) CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount) Secured(org.springframework.security.access.annotation.Secured)

Example 2 with CreateApplicationEventRequest

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;
}
Also used : RegisterUserRequest(com.hack23.cia.service.api.action.application.RegisterUserRequest) CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest)

Example 3 with CreateApplicationEventRequest

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;
}
Also used : ConstraintViolation(javax.validation.ConstraintViolation) ArrayList(java.util.ArrayList) ComplianceCheckResponse(com.hack23.cia.service.api.action.kpi.ComplianceCheckResponse) CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest) ComplianceCheck(com.hack23.cia.service.api.action.kpi.ComplianceCheck) RuleViolation(com.hack23.cia.service.api.action.kpi.RuleViolation) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount) Secured(org.springframework.security.access.annotation.Secured)

Example 4 with CreateApplicationEventRequest

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;
}
Also used : DisableGoogleAuthenticatorCredentialRequest(com.hack23.cia.service.api.action.user.DisableGoogleAuthenticatorCredentialRequest) CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest)

Example 5 with CreateApplicationEventRequest

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;
}
Also used : CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest) SetGoogleAuthenticatorCredentialRequest(com.hack23.cia.service.api.action.user.SetGoogleAuthenticatorCredentialRequest)

Aggregations

CreateApplicationEventRequest (com.hack23.cia.service.api.action.application.CreateApplicationEventRequest)32 UserAccount (com.hack23.cia.model.internal.application.user.impl.UserAccount)15 Secured (org.springframework.security.access.annotation.Secured)14 ArrayList (java.util.ArrayList)5 ConstraintViolation (javax.validation.ConstraintViolation)3 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)3 DocumentContentData (com.hack23.cia.model.external.riksdagen.documentcontent.impl.DocumentContentData)2 ApplicationConfiguration (com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration)2 ApplicationSession (com.hack23.cia.model.internal.application.system.impl.ApplicationSession)2 ManageUserAccountRequest (com.hack23.cia.service.api.action.admin.ManageUserAccountRequest)2 ManageUserAccountResponse (com.hack23.cia.service.api.action.admin.ManageUserAccountResponse)2 CreateApplicationEventResponse (com.hack23.cia.service.api.action.application.CreateApplicationEventResponse)2 Date (java.util.Date)2 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)2 DocumentElement (com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentElement)1 ApplicationActionEvent (com.hack23.cia.model.internal.application.system.impl.ApplicationActionEvent)1 ApplicationEventGroup (com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup)1 ApplicationOperationType (com.hack23.cia.model.internal.application.system.impl.ApplicationOperationType)1 UserAccount_ (com.hack23.cia.model.internal.application.user.impl.UserAccount_)1 UserLockStatus (com.hack23.cia.model.internal.application.user.impl.UserLockStatus)1