Search in sources :

Example 6 with CreateApplicationEventRequest

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

the class CreateApplicationEventServiceITest method serviceCreateApplicationEventRequestSuccessTest.

/**
 * Service create application event request success test.
 *
 * @throws Exception
 *             the exception
 */
@Test
@PerfTest(threads = 4, duration = 3000, warmUp = 1500)
@Required(max = 1000, average = 400, percentile95 = 450, throughput = 10)
public void serviceCreateApplicationEventRequestSuccessTest() throws Exception {
    setAuthenticatedAnonymousUser();
    final CreateApplicationSessionRequest createSessionRequest = createTestApplicationSession();
    final CreateApplicationEventRequest serviceRequest = new CreateApplicationEventRequest();
    serviceRequest.setSessionId(createSessionRequest.getSessionId());
    serviceRequest.setApplicationMessage("applicationMessage");
    serviceRequest.setEventGroup(ApplicationEventGroup.USER);
    serviceRequest.setApplicationOperation(ApplicationOperationType.CREATE);
    serviceRequest.setPage("Test");
    serviceRequest.setPageMode("PageMode");
    serviceRequest.setElementId("ElementId");
    serviceRequest.setActionName("Content");
    serviceRequest.setApplicationMessage("applicationMessage");
    serviceRequest.setErrorMessage("errorMessage");
    final CreateApplicationEventResponse response = (CreateApplicationEventResponse) applicationManager.service(serviceRequest);
    assertNotNull(EXPECT_A_RESULT, response);
    assertEquals(EXPECT_SUCCESS, ServiceResult.SUCCESS, response.getResult());
    final List<ApplicationSession> findListByProperty = applicationSessionDAO.findListByProperty(ApplicationSession_.sessionId, serviceRequest.getSessionId());
    assertEquals(1, findListByProperty.size());
    final ApplicationSession applicationSession = findListByProperty.get(0);
    assertNotNull(applicationSession);
    assertEquals(1, applicationSession.getEvents().size());
}
Also used : ApplicationSession(com.hack23.cia.model.internal.application.system.impl.ApplicationSession) CreateApplicationEventResponse(com.hack23.cia.service.api.action.application.CreateApplicationEventResponse) CreateApplicationSessionRequest(com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest) CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest) Required(org.databene.contiperf.Required) PerfTest(org.databene.contiperf.PerfTest) Test(org.junit.Test) AbstractServiceFunctionalIntegrationTest(com.hack23.cia.service.impl.AbstractServiceFunctionalIntegrationTest) PerfTest(org.databene.contiperf.PerfTest)

Example 7 with CreateApplicationEventRequest

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

the class ManageUserAccountService method createApplicationEventForService.

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

Example 8 with CreateApplicationEventRequest

use of com.hack23.cia.service.api.action.application.CreateApplicationEventRequest 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;
}
Also used : RemoveDataResponse(com.hack23.cia.service.api.action.admin.RemoveDataResponse) 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 9 with CreateApplicationEventRequest

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

the class UpdateApplicationConfigurationService method createApplicationEventForService.

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

Example 10 with CreateApplicationEventRequest

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

the class AuthorizationFailureEventListener method onApplicationEvent.

@Override
public void onApplicationEvent(final AuthorizationFailureEvent authorizationFailureEvent) {
    final String sessionId = RequestContextHolder.currentRequestAttributes().getSessionId();
    final CreateApplicationEventRequest serviceRequest = new CreateApplicationEventRequest();
    serviceRequest.setSessionId(sessionId);
    serviceRequest.setEventGroup(ApplicationEventGroup.APPLICATION);
    serviceRequest.setApplicationOperation(ApplicationOperationType.AUTHORIZATION);
    serviceRequest.setUserId(UserContextUtil.getUserIdFromSecurityContext());
    final Page currentPageIfAny = Page.getCurrent();
    final String requestUrl = UserContextUtil.getRequestUrl(currentPageIfAny);
    final UI currentUiIfAny = UI.getCurrent();
    String methodInfo = "";
    if (currentPageIfAny != null && currentUiIfAny != null && currentUiIfAny.getNavigator() != null && currentUiIfAny.getNavigator().getCurrentView() != null) {
        serviceRequest.setPage(currentUiIfAny.getNavigator().getCurrentView().getClass().getSimpleName());
        serviceRequest.setPageMode(currentPageIfAny.getUriFragment());
    }
    if (authorizationFailureEvent.getSource() instanceof ReflectiveMethodInvocation) {
        final ReflectiveMethodInvocation methodInvocation = (ReflectiveMethodInvocation) authorizationFailureEvent.getSource();
        if (methodInvocation.getMethod() != null && methodInvocation.getThis() != null) {
            methodInfo = methodInvocation.getThis().getClass().getSimpleName() + "." + methodInvocation.getMethod().getName();
        }
    }
    final Collection<? extends GrantedAuthority> authorities = authorizationFailureEvent.getAuthentication().getAuthorities();
    final Collection<ConfigAttribute> configAttributes = authorizationFailureEvent.getConfigAttributes();
    serviceRequest.setErrorMessage(MessageFormat.format(ERROR_MESSAGE_FORMAT, requestUrl, methodInfo, AUTHORITIES, authorities, REQUIRED_AUTHORITIES, configAttributes, authorizationFailureEvent.getSource()));
    serviceRequest.setApplicationMessage(ACCESS_DENIED);
    applicationManager.service(serviceRequest);
    LOGGER.info(LOG_MSG_AUTHORIZATION_FAILURE_SESSION_ID_AUTHORITIES_REQUIRED_AUTHORITIES, requestUrl.replaceAll(CRLF, CRLF_REPLACEMENT), methodInfo.replaceAll(CRLF, CRLF_REPLACEMENT), sessionId.replaceAll(CRLF, CRLF_REPLACEMENT), authorities, configAttributes);
}
Also used : UI(com.vaadin.ui.UI) ConfigAttribute(org.springframework.security.access.ConfigAttribute) ReflectiveMethodInvocation(org.springframework.aop.framework.ReflectiveMethodInvocation) CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest) Page(com.vaadin.server.Page)

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