Search in sources :

Example 31 with CreateApplicationEventRequest

use of com.hack23.cia.service.api.action.application.CreateApplicationEventRequest in project cia by Hack23.

the class SearchDocumentService method processService.

@Override
@Secured({ "ROLE_USER", "ROLE_ADMIN", "ROLE_ANONYMOUS" })
public SearchDocumentResponse processService(final SearchDocumentRequest serviceRequest) {
    final SearchDocumentResponse inputValidation = inputValidation(serviceRequest);
    if (inputValidation != null) {
        return inputValidation;
    }
    LOGGER.info("{}:{}", serviceRequest.getClass().getSimpleName(), serviceRequest.getSearchExpression());
    final CreateApplicationEventRequest eventRequest = createApplicationEventForService(serviceRequest);
    final UserAccount userAccount = getUserAccountFromSecurityContext();
    if (userAccount != null) {
        eventRequest.setUserId(userAccount.getUserId());
    }
    final SearchDocumentResponse response = new SearchDocumentResponse(ServiceResult.SUCCESS);
    final List<DocumentElement> searchResultTitles = documentElementDAO.search(serviceRequest.getSearchExpression(), serviceRequest.getMaxResults(), "id", "title", "subTitle");
    if (!searchResultTitles.isEmpty()) {
        response.setResultElement(searchResultTitles);
    } else {
        final List<DocumentContentData> searchResultContent = documentContentDataDAO.search(serviceRequest.getSearchExpression(), serviceRequest.getMaxResults(), "id", "content");
        if (!searchResultContent.isEmpty()) {
            final List<DocumentElement> searchResultTitlesForContent = new ArrayList<>();
            for (final DocumentContentData documentContent : searchResultContent) {
                searchResultTitlesForContent.add(documentElementDAO.load(documentContent.getId()));
            }
            response.setResultElement(searchResultTitlesForContent);
        }
    }
    eventRequest.setApplicationMessage(response.getResult().toString());
    createApplicationEventService.processService(eventRequest);
    return response;
}
Also used : DocumentElement(com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentElement) SearchDocumentResponse(com.hack23.cia.service.api.action.user.SearchDocumentResponse) ArrayList(java.util.ArrayList) CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount) DocumentContentData(com.hack23.cia.model.external.riksdagen.documentcontent.impl.DocumentContentData) Secured(org.springframework.security.access.annotation.Secured)

Example 32 with CreateApplicationEventRequest

use of com.hack23.cia.service.api.action.application.CreateApplicationEventRequest in project cia by Hack23.

the class SearchDocumentService method createApplicationEventForService.

@Override
protected CreateApplicationEventRequest createApplicationEventForService(final SearchDocumentRequest serviceRequest) {
    final CreateApplicationEventRequest eventRequest = new CreateApplicationEventRequest();
    eventRequest.setEventGroup(ApplicationEventGroup.USER);
    eventRequest.setApplicationOperation(ApplicationOperationType.READ);
    eventRequest.setActionName(SearchDocumentRequest.class.getSimpleName());
    eventRequest.setSessionId(serviceRequest.getSessionId());
    return eventRequest;
}
Also used : SearchDocumentRequest(com.hack23.cia.service.api.action.user.SearchDocumentRequest) CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest)

Example 33 with CreateApplicationEventRequest

use of com.hack23.cia.service.api.action.application.CreateApplicationEventRequest in project cia by Hack23.

the class SetGoogleAuthenticatorCredentialService method processService.

@Override
@Secured({ "ROLE_USER", "ROLE_ADMIN" })
public SetGoogleAuthenticatorCredentialResponse processService(final SetGoogleAuthenticatorCredentialRequest serviceRequest) {
    final SetGoogleAuthenticatorCredentialResponse inputValidation = inputValidation(serviceRequest);
    if (inputValidation != null) {
        return inputValidation;
    }
    LOGGER.info("{}:{}", serviceRequest.getClass().getSimpleName(), serviceRequest.getSessionId());
    final CreateApplicationEventRequest eventRequest = createApplicationEventForService(serviceRequest);
    final UserAccount userAccount = getUserAccountFromSecurityContext();
    final SetGoogleAuthenticatorCredentialResponse response = new SetGoogleAuthenticatorCredentialResponse(ServiceResult.SUCCESS);
    if (userAccount != null) {
        eventRequest.setUserId(userAccount.getUserId());
        final GoogleAuthenticator gAuth = new GoogleAuthenticator();
        final GoogleAuthenticatorKey gKey = gAuth.createCredentials();
        final UserAccount updateUserAccount = userDAO.load(userAccount.getHjid());
        updateUserAccount.setGoogleAuthKey(gKey.getKey());
        updateUserAccount.setGoogleAuthVerificationCode(gKey.getVerificationCode());
        updateUserAccount.setGoogleAuthScratchCodes(gKey.getScratchCodes());
        userDAO.merge(updateUserAccount);
        final String otpAuthTotpURL = GoogleAuthenticatorQRGenerator.getOtpAuthTotpURL(agencyDAO.getAll().get(0).getAgencyName(), updateUserAccount.getEmail(), gKey);
        response.setOtpAuthTotpURL(otpAuthTotpURL);
        response.setGoogleAuthKey(gKey.getKey());
        response.setGoogleAuthVerificationCode(gKey.getVerificationCode());
        response.setGoogleAuthScratchCodes(gKey.getScratchCodes());
    }
    eventRequest.setApplicationMessage(response.getResult().toString());
    createApplicationEventService.processService(eventRequest);
    return response;
}
Also used : GoogleAuthenticatorKey(com.warrenstrange.googleauth.GoogleAuthenticatorKey) GoogleAuthenticator(com.warrenstrange.googleauth.GoogleAuthenticator) SetGoogleAuthenticatorCredentialResponse(com.hack23.cia.service.api.action.user.SetGoogleAuthenticatorCredentialResponse) CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount) Secured(org.springframework.security.access.annotation.Secured)

Example 34 with CreateApplicationEventRequest

use of com.hack23.cia.service.api.action.application.CreateApplicationEventRequest in project cia by Hack23.

the class PageActionEventHelperImpl method createPageEvent.

@Override
public void createPageEvent(final ViewAction viewAction, final ApplicationEventGroup applicationEventGroup, final String page, final String pageMode, final String elementId) {
    String pageModeToUse;
    if (pageMode != null && elementId != null && pageMode.contains(elementId)) {
        pageModeToUse = pageMode.replace(elementId, "").replace("/", "");
    } else {
        pageModeToUse = pageMode;
    }
    if ((pageModeToUse == null || "".equals(pageModeToUse)) && ApplicationEventGroup.USER == applicationEventGroup) {
        pageModeToUse = "Overview";
    }
    final CreateApplicationEventRequest serviceRequest = new CreateApplicationEventRequest();
    serviceRequest.setSessionId(RequestContextHolder.currentRequestAttributes().getSessionId());
    serviceRequest.setEventGroup(applicationEventGroup);
    serviceRequest.setApplicationOperation(ApplicationOperationType.READ);
    serviceRequest.setPage(StringUtils.defaultString(page));
    serviceRequest.setPageMode(StringUtils.defaultString(pageModeToUse));
    serviceRequest.setElementId(StringUtils.defaultString(elementId));
    serviceRequest.setActionName(viewAction.toString());
    serviceRequest.setUserId(UserContextUtil.getUserIdFromSecurityContext());
    serviceRequest.setApplicationMessage(viewAction.toString());
    applicationManager.service(serviceRequest);
}
Also used : CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest)

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