Search in sources :

Example 1 with DestroyApplicationSessionRequest

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

the class DestroyApplicationSessionServiceITest method serviceDestroyApplicationSessionRequestSuccessTest.

/**
 * Service destroy application session request success test.
 *
 * @throws Exception
 *             the exception
 */
@Test
@PerfTest(threads = 4, duration = 3000, warmUp = 1500)
@Required(max = 1000, average = 600, percentile95 = 850, throughput = 10)
public void serviceDestroyApplicationSessionRequestSuccessTest() throws Exception {
    setAuthenticatedAnonymousUser();
    final CreateApplicationSessionRequest createTestApplicationSession = createTestApplicationSession();
    final DestroyApplicationSessionRequest destroyApplicationSessionRequest = new DestroyApplicationSessionRequest();
    destroyApplicationSessionRequest.setSessionId(createTestApplicationSession.getSessionId());
    final ServiceResponse response = applicationManager.service(destroyApplicationSessionRequest);
    assertNotNull(EXPECT_A_RESULT, response);
    assertEquals(EXPECT_SUCCESS, ServiceResult.SUCCESS, response.getResult());
    final ApplicationSession applicationSession = applicationSessionDAO.findFirstByProperty(ApplicationSession_.sessionId, createTestApplicationSession.getSessionId());
    assertNotNull(EXPECT_A_RESULT, applicationSession);
    assertNotNull(EXPECT_A_RESULT, applicationSession.getDestroyedDate());
}
Also used : ApplicationSession(com.hack23.cia.model.internal.application.system.impl.ApplicationSession) ServiceResponse(com.hack23.cia.service.api.action.common.ServiceResponse) CreateApplicationSessionRequest(com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest) DestroyApplicationSessionRequest(com.hack23.cia.service.api.action.application.DestroyApplicationSessionRequest) 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 2 with DestroyApplicationSessionRequest

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

the class DestroyApplicationSessionService method processService.

@Override
@Secured({ "ROLE_ANONYMOUS" })
public DestroyApplicationSessionResponse processService(final DestroyApplicationSessionRequest serviceRequest) {
    final DestroyApplicationSessionResponse inputValidation = inputValidation(serviceRequest);
    if (inputValidation != null) {
        return inputValidation;
    }
    final ApplicationSession applicationSession = applicationSessionDAO.findFirstByProperty(ApplicationSession_.sessionId, serviceRequest.getSessionId());
    if (applicationSession != null) {
        LOGGER.info("Destroy Application session: {}", applicationSession.getSessionId());
        applicationSession.setDestroyedDate(new Date());
        applicationSessionDAO.persist(applicationSession);
        return new DestroyApplicationSessionResponse(ServiceResult.SUCCESS);
    } else {
        LOGGER.warn("Failed to destroy Application session, no session found for id: {}", serviceRequest.getSessionId());
        return new DestroyApplicationSessionResponse(ServiceResult.FAILURE);
    }
}
Also used : ApplicationSession(com.hack23.cia.model.internal.application.system.impl.ApplicationSession) DestroyApplicationSessionResponse(com.hack23.cia.service.api.action.application.DestroyApplicationSessionResponse) Date(java.util.Date) Secured(org.springframework.security.access.annotation.Secured)

Example 3 with DestroyApplicationSessionRequest

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

the class HttpSessionDestroyedEventListener method onApplicationEvent.

@Override
public void onApplicationEvent(final HttpSessionDestroyedEvent event) {
    final HttpSession httpSession = event.getSession();
    final Collection<SimpleGrantedAuthority> authorities = new ArrayList<>();
    authorities.add(new SimpleGrantedAuthority(ROLE_ANONYMOUS));
    final DestroyApplicationSessionRequest destroyApplicationSessionRequest = new DestroyApplicationSessionRequest();
    destroyApplicationSessionRequest.setSessionId(httpSession.getId());
    SecurityContextHolder.getContext().setAuthentication(new AnonymousAuthenticationToken(KEY, PRINCIPAL, authorities));
    applicationManager.service(destroyApplicationSessionRequest);
    SecurityContextHolder.getContext().setAuthentication(null);
    LOGGER.info(LOG_MSG_SESSION_DESTROYED_SESSION_ID, httpSession.getId());
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) HttpSession(javax.servlet.http.HttpSession) ArrayList(java.util.ArrayList) DestroyApplicationSessionRequest(com.hack23.cia.service.api.action.application.DestroyApplicationSessionRequest) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken)

Aggregations

ApplicationSession (com.hack23.cia.model.internal.application.system.impl.ApplicationSession)2 DestroyApplicationSessionRequest (com.hack23.cia.service.api.action.application.DestroyApplicationSessionRequest)2 CreateApplicationSessionRequest (com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest)1 DestroyApplicationSessionResponse (com.hack23.cia.service.api.action.application.DestroyApplicationSessionResponse)1 ServiceResponse (com.hack23.cia.service.api.action.common.ServiceResponse)1 AbstractServiceFunctionalIntegrationTest (com.hack23.cia.service.impl.AbstractServiceFunctionalIntegrationTest)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HttpSession (javax.servlet.http.HttpSession)1 PerfTest (org.databene.contiperf.PerfTest)1 Required (org.databene.contiperf.Required)1 Test (org.junit.Test)1 Secured (org.springframework.security.access.annotation.Secured)1 AnonymousAuthenticationToken (org.springframework.security.authentication.AnonymousAuthenticationToken)1 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)1