Search in sources :

Example 51 with WebCertUser

use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.

the class RoleConverter method convert.

@Override
public String convert(ILoggingEvent event) {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (auth == null) {
        return NO_ROLE;
    }
    Object principal = auth.getPrincipal();
    if (principal instanceof WebCertUser) {
        WebCertUser user = (WebCertUser) auth.getPrincipal();
        Set<String> keys = user.getRoles().keySet();
        if (keys.size() == 1) {
            return keys.toArray(new String[0])[0];
        }
    }
    return NO_ROLE;
}
Also used : Authentication(org.springframework.security.core.Authentication) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 52 with WebCertUser

use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.

the class TermsFilter method doFilterInternal.

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
    HttpSession session = request.getSession(false);
    if (session == null) {
        return;
    }
    if (session.getAttribute(PRIVATE_PRACTITIONER_TERMS_INPROGRESS) == null) {
        session.setAttribute(PRIVATE_PRACTITIONER_TERMS_INPROGRESS, false);
    }
    if (session.getAttribute(PRIVATE_PRACTITIONER_TERMS_ACCEPTED) == null) {
        session.setAttribute(PRIVATE_PRACTITIONER_TERMS_ACCEPTED, false);
    }
    boolean ppTermsAccepted = (boolean) session.getAttribute(PRIVATE_PRACTITIONER_TERMS_ACCEPTED);
    // if we've accepted the terms then in progress is definetly false
    if (ppTermsAccepted) {
        session.setAttribute(PRIVATE_PRACTITIONER_TERMS_INPROGRESS, false);
    }
    boolean ppTermsInprogress = (boolean) session.getAttribute(PRIVATE_PRACTITIONER_TERMS_INPROGRESS);
    if (hasSessionWithSpringContext(session)) {
        if (!ppTermsInprogress && !ppTermsAccepted) {
            Object principal = ((SecurityContextImpl) session.getAttribute(SPRING_SECURITY_CONTEXT)).getAuthentication().getPrincipal();
            if (principal != null && principal instanceof WebCertUser) {
                WebCertUser webCertUser = (WebCertUser) principal;
                if (isElegAuthContext(webCertUser)) {
                    boolean avtalApproved = avtalService.userHasApprovedLatestAvtal(webCertUser.getHsaId());
                    if (avtalApproved) {
                        session.setAttribute(PRIVATE_PRACTITIONER_TERMS_ACCEPTED, true);
                        session.setAttribute(PRIVATE_PRACTITIONER_TERMS_INPROGRESS, false);
                        webCertUser.setPrivatLakareAvtalGodkand(true);
                    } else {
                        session.setAttribute(PRIVATE_PRACTITIONER_TERMS_ACCEPTED, false);
                        session.setAttribute(PRIVATE_PRACTITIONER_TERMS_INPROGRESS, true);
                        // REDIRECT. Note that we have gotten IllegalStateExceptions after redirect due to response
                        // already have been commited. Hopefully the return (breaking the filter chain) can mitigate
                        // this.
                        response.sendRedirect("/#/terms");
                        return;
                    }
                }
            }
        }
    }
    filterChain.doFilter(request, response);
}
Also used : HttpSession(javax.servlet.http.HttpSession) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 53 with WebCertUser

use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.

the class WebcertLoggingSessionRegistryImpl method removeSessionInformation.

@Override
public void removeSessionInformation(String sessionId) {
    LOGGER.debug("Attempting to remove session '{}'", sessionId);
    SessionInformation sessionInformation = getSessionInformation(sessionId);
    if (sessionInformation == null) {
        super.removeSessionInformation(sessionId);
        return;
    }
    Object principal = sessionInformation.getPrincipal();
    if (principal instanceof WebCertUser) {
        WebCertUser user = (WebCertUser) principal;
        if (sessionInformation.isExpired()) {
            monitoringService.logUserSessionExpired(user.getHsaId(), user.getAuthenticationScheme());
        } else {
            monitoringService.logUserLogout(user.getHsaId(), user.getAuthenticationScheme());
        }
    }
    super.removeSessionInformation(sessionId);
}
Also used : SessionInformation(org.springframework.security.core.session.SessionInformation) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 54 with WebCertUser

use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.

the class WebcertLoggingSessionRegistryImpl method registerNewSession.

@Override
public void registerNewSession(String sessionId, Object principal) {
    LOGGER.debug("Attempting to register new session '{}'", sessionId);
    if (principal != null && principal instanceof WebCertUser) {
        WebCertUser user = (WebCertUser) principal;
        monitoringService.logUserLogin(user.getHsaId(), user.getAuthenticationScheme(), user.getOrigin());
    }
    super.registerNewSession(sessionId, principal);
}
Also used : WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 55 with WebCertUser

use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.

the class FragaSvarServiceImplTest method testFilterFragaSvarWithEnhetsIdAsParam.

@Test
public void testFilterFragaSvarWithEnhetsIdAsParam() {
    WebCertUser webCertUser = createUser();
    List<FragaSvar> queryResults = new ArrayList<>();
    queryResults.add(buildFragaSvar(1L, MAY, null));
    queryResults.add(buildFragaSvar(2L, MAY, null));
    when(fragasvarRepositoryMock.filterFragaSvar(any(Filter.class))).thenReturn(queryResults);
    when(fragasvarRepositoryMock.filterCountFragaSvar(any(Filter.class))).thenReturn(queryResults.size());
    Filter params = new Filter();
    params.setEnhetsIds(Arrays.asList(webCertUser.getValdVardenhet().getId()));
    QueryFragaSvarResponse response = service.filterFragaSvar(params);
    verify(fragasvarRepositoryMock).filterFragaSvar(any(Filter.class));
    verify(fragasvarRepositoryMock).filterCountFragaSvar(any(Filter.class));
    assertNotNull(response);
    assertEquals(2, response.getResults().size());
}
Also used : Filter(se.inera.intyg.webcert.persistence.model.Filter) FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) QueryFragaSvarResponse(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse) Test(org.junit.Test)

Aggregations

WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)217 Test (org.junit.Test)123 IntegrationParameters (se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters)32 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)31 Personnummer (se.inera.intyg.schemas.contract.Personnummer)24 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)23 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)23 Role (se.inera.intyg.infra.security.common.model.Role)18 HoSPersonal (se.inera.intyg.common.support.model.common.internal.HoSPersonal)16 Arende (se.inera.intyg.webcert.persistence.arende.model.Arende)15 CopyIntygRequest (se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest)15 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)14 Vardenhet (se.inera.intyg.infra.integration.hsa.model.Vardenhet)14 CopyUtkastBuilderResponse (se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse)14 Vardgivare (se.inera.intyg.infra.integration.hsa.model.Vardgivare)13 Feature (se.inera.intyg.infra.security.common.model.Feature)13 HashMap (java.util.HashMap)12 MedicinsktArende (se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende)12 Transactional (org.springframework.transaction.annotation.Transactional)11 Path (javax.ws.rs.Path)10