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;
}
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);
}
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);
}
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);
}
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());
}
Aggregations