Search in sources :

Example 1 with UserFacade

use of de.symeda.sormas.api.user.UserFacade in project SORMAS-Project by hzi-braunschweig.

the class SessionFilter method doFilter.

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    HttpSession session = ((HttpServletRequest) request).getSession();
    final HttpServletResponse res = (HttpServletResponse) response;
    res.addHeader("X-Content-Type-Options", "nosniff");
    res.addHeader("X-Frame-Options", "SAMEORIGIN");
    res.addHeader("Referrer-Policy", "same-origin");
    ControllerProvider controllerProvider = Optional.of(session).map(s -> (ControllerProvider) s.getAttribute("controllerProvider")).orElseGet(() -> {
        ControllerProvider cp = new ControllerProvider();
        session.setAttribute("controllerProvider", cp);
        return cp;
    });
    try {
        sessionFilterBean.doFilter((req, resp) -> {
            Language userLanguage = Optional.of(FacadeProvider.getUserFacade()).map(UserFacade::getCurrentUser).map(UserDto::getLanguage).orElse(null);
            I18nProperties.setUserLanguage(userLanguage);
            FacadeProvider.getI18nFacade().setUserLanguage(userLanguage);
            try (Closeable bc = BaseControllerProvider.requestStart(controllerProvider)) {
                chain.doFilter(req, response);
            }
        }, request, response);
    } finally {
        I18nProperties.removeUserLanguage();
        FacadeProvider.getI18nFacade().removeUserLanguage();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpSession(javax.servlet.http.HttpSession) FilterChain(javax.servlet.FilterChain) ServletRequest(javax.servlet.ServletRequest) ServletException(javax.servlet.ServletException) FacadeProvider(de.symeda.sormas.api.FacadeProvider) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) UserDto(de.symeda.sormas.api.user.UserDto) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) Language(de.symeda.sormas.api.Language) UserFacade(de.symeda.sormas.api.user.UserFacade) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletResponse(javax.servlet.ServletResponse) WebFilter(javax.servlet.annotation.WebFilter) Closeable(java.io.Closeable) Optional(java.util.Optional) Filter(javax.servlet.Filter) BaseControllerProvider(de.symeda.sormas.ui.utils.BaseControllerProvider) EJB(javax.ejb.EJB) UserFacade(de.symeda.sormas.api.user.UserFacade) Language(de.symeda.sormas.api.Language) HttpSession(javax.servlet.http.HttpSession) Closeable(java.io.Closeable) HttpServletResponse(javax.servlet.http.HttpServletResponse) BaseControllerProvider(de.symeda.sormas.ui.utils.BaseControllerProvider)

Example 2 with UserFacade

use of de.symeda.sormas.api.user.UserFacade in project SORMAS-Project by hzi-braunschweig.

the class UserFacadeEjbTest method testGetByUserName.

@Test
public void testGetByUserName() {
    final UserFacade userFacade = getUserFacade();
    assertNull(userFacade.getByUserName("HansPeter"));
    RDCF rdcf = creator.createRDCF();
    UserDto user = creator.createUser(rdcf, "Hans", "Peter", SURVEILLANCE_OFFICER);
    assertEquals(user, userFacade.getByUserName("HANSPETER"));
    assertEquals(user, userFacade.getByUserName("hanspeter"));
    assertEquals(user, userFacade.getByUserName("HansPeter"));
    assertEquals(user, userFacade.getByUserName("hansPETER"));
}
Also used : UserFacade(de.symeda.sormas.api.user.UserFacade) RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) UserDto(de.symeda.sormas.api.user.UserDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 3 with UserFacade

use of de.symeda.sormas.api.user.UserFacade in project SORMAS-Project by hzi-braunschweig.

the class UserFacadeEjbTest method testLoginUnique.

@Test
public void testLoginUnique() {
    final UserFacade userFacade = getUserFacade();
    assertNull(userFacade.getByUserName("HansPeter"));
    RDCF rdcf = creator.createRDCF();
    creator.createUser(rdcf, "Hans", "Peter", SURVEILLANCE_OFFICER);
    assertTrue(userFacade.isLoginUnique(String.valueOf(UUID.randomUUID()), "MarieLisa"));
    assertFalse(userFacade.isLoginUnique(String.valueOf(UUID.randomUUID()), "HansPeter"));
    assertFalse(userFacade.isLoginUnique(String.valueOf(UUID.randomUUID()), "hanspeter"));
}
Also used : UserFacade(de.symeda.sormas.api.user.UserFacade) RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 4 with UserFacade

use of de.symeda.sormas.api.user.UserFacade in project SORMAS-Project by hzi-braunschweig.

the class UserFacadeEjbTest method testFailOnSavingDuplicateUser.

@Test
public void testFailOnSavingDuplicateUser() {
    final UserFacade userFacade = getUserFacade();
    assertNull(userFacade.getByUserName("HansPeter"));
    RDCF rdcf = creator.createRDCF();
    creator.createUser(rdcf, "Hans", "Peter", SURVEILLANCE_OFFICER);
    assertThrows("User name is not unique!", ValidationException.class, () -> creator.createUser(rdcf, "Hans", "Peter", SURVEILLANCE_OFFICER));
    assertThrows("User name is not unique!", ValidationException.class, () -> creator.createUser(rdcf, "hans", "peter", SURVEILLANCE_OFFICER));
    assertThrows("User name is not unique!", ValidationException.class, () -> creator.createUser(rdcf, "HANS", "PETER", SURVEILLANCE_OFFICER));
}
Also used : UserFacade(de.symeda.sormas.api.user.UserFacade) RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Aggregations

UserFacade (de.symeda.sormas.api.user.UserFacade)4 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)3 RDCF (de.symeda.sormas.backend.TestDataCreator.RDCF)3 Test (org.junit.Test)3 UserDto (de.symeda.sormas.api.user.UserDto)2 FacadeProvider (de.symeda.sormas.api.FacadeProvider)1 Language (de.symeda.sormas.api.Language)1 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)1 BaseControllerProvider (de.symeda.sormas.ui.utils.BaseControllerProvider)1 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 Optional (java.util.Optional)1 EJB (javax.ejb.EJB)1 Filter (javax.servlet.Filter)1 FilterChain (javax.servlet.FilterChain)1 ServletException (javax.servlet.ServletException)1 ServletRequest (javax.servlet.ServletRequest)1 ServletResponse (javax.servlet.ServletResponse)1 WebFilter (javax.servlet.annotation.WebFilter)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1