Search in sources :

Example 11 with Feature

use of se.inera.intyg.infra.security.common.model.Feature in project webcert by sklintyg.

the class UserApiControllerTest method testUserFeaturesDisableEnabled.

@Test
public void testUserFeaturesDisableEnabled() {
    // Given
    final WebUserFeaturesRequest webUserFeaturesRequest = new WebUserFeaturesRequest();
    webUserFeaturesRequest.setJsLoggning(false);
    final HashMap<String, Feature> features = new HashMap<>();
    Feature f1 = new Feature();
    f1.setName(AuthoritiesConstants.FEATURE_JS_LOGGNING);
    features.put(f1.getName(), f1);
    when(webCertUser.getFeatures()).thenReturn(features);
    // When
    userApiController.userFeatures(webUserFeaturesRequest);
    // Then
    Mockito.verify(webCertUser, times(1)).setFeatures(captor.capture());
    assertFalse(captor.getValue().containsKey(AuthoritiesConstants.FEATURE_JS_LOGGNING));
}
Also used : WebUserFeaturesRequest(se.inera.intyg.webcert.web.web.controller.api.dto.WebUserFeaturesRequest) HashMap(java.util.HashMap) Feature(se.inera.intyg.infra.security.common.model.Feature) Test(org.junit.Test)

Example 12 with Feature

use of se.inera.intyg.infra.security.common.model.Feature in project webcert by sklintyg.

the class UserApiControllerTest method testUserFeaturesEnableEnabled.

@Test
public void testUserFeaturesEnableEnabled() {
    // Given
    final WebUserFeaturesRequest webUserFeaturesRequest = new WebUserFeaturesRequest();
    webUserFeaturesRequest.setJsLoggning(true);
    final HashMap<String, Feature> features = new HashMap<>();
    Feature f1 = new Feature();
    f1.setName(AuthoritiesConstants.FEATURE_JS_LOGGNING);
    features.put(f1.getName(), f1);
    when(webCertUser.getFeatures()).thenReturn(features);
    // When
    userApiController.userFeatures(webUserFeaturesRequest);
    // Then
    Mockito.verify(webCertUser, times(1)).setFeatures(captor.capture());
    assertTrue(captor.getValue().containsKey(AuthoritiesConstants.FEATURE_JS_LOGGNING));
}
Also used : WebUserFeaturesRequest(se.inera.intyg.webcert.web.web.controller.api.dto.WebUserFeaturesRequest) HashMap(java.util.HashMap) Feature(se.inera.intyg.infra.security.common.model.Feature) Test(org.junit.Test)

Example 13 with Feature

use of se.inera.intyg.infra.security.common.model.Feature in project webcert by sklintyg.

the class UtkastApiControllerTest method setupUser.

private void setupUser(String privilegeString, String intygType, String... features) {
    WebCertUser user = new WebCertUser();
    user.setAuthorities(new HashMap<>());
    user.getFeatures().putAll(Stream.of(features).collect(Collectors.toMap(Function.identity(), s -> {
        Feature feature = new Feature();
        feature.setName(s);
        feature.setIntygstyper(Arrays.asList(intygType));
        feature.setGlobal(true);
        return feature;
    })));
    Privilege privilege = new Privilege();
    privilege.setIntygstyper(Arrays.asList(intygType));
    RequestOrigin requestOrigin = new RequestOrigin();
    requestOrigin.setName("NORMAL");
    requestOrigin.setIntygstyper(privilege.getIntygstyper());
    privilege.setRequestOrigins(Arrays.asList(requestOrigin));
    user.getAuthorities().put(privilegeString, privilege);
    user.setOrigin("NORMAL");
    user.setValdVardenhet(buildVardenhet());
    user.setValdVardgivare(buildVardgivare());
    when(webcertUserService.getUser()).thenReturn(user);
}
Also used : RequestOrigin(se.inera.intyg.infra.security.common.model.RequestOrigin) Privilege(se.inera.intyg.infra.security.common.model.Privilege) Feature(se.inera.intyg.infra.security.common.model.Feature) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 14 with Feature

use of se.inera.intyg.infra.security.common.model.Feature in project webcert by sklintyg.

the class UtkastModuleApiControllerTest method setupUser.

private void setupUser(String privilegeString, String intygType, boolean coherentJournaling, String... features) {
    WebCertUser user = new WebCertUser();
    user.setAuthorities(new HashMap<>());
    user.setFeatures(Stream.of(features).collect(Collectors.toMap(Function.identity(), s -> {
        Feature feature = new Feature();
        feature.setName(s);
        feature.setIntygstyper(Arrays.asList(intygType));
        return feature;
    })));
    user.setParameters(new IntegrationParameters("", "", "", "", "", "", "", "", "", coherentJournaling, false, false, true));
    Privilege privilege = new Privilege();
    privilege.setIntygstyper(Arrays.asList(intygType));
    RequestOrigin requestOrigin = new RequestOrigin();
    requestOrigin.setName("NORMAL");
    requestOrigin.setIntygstyper(privilege.getIntygstyper());
    privilege.setRequestOrigins(Arrays.asList(requestOrigin));
    user.getAuthorities().put(privilegeString, privilege);
    user.setOrigin("NORMAL");
    when(webcertUserService.getUser()).thenReturn(user);
}
Also used : IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) RequestOrigin(se.inera.intyg.infra.security.common.model.RequestOrigin) Privilege(se.inera.intyg.infra.security.common.model.Privilege) Feature(se.inera.intyg.infra.security.common.model.Feature) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 15 with Feature

use of se.inera.intyg.infra.security.common.model.Feature in project webcert by sklintyg.

the class UserApiControllerTest method testUserFeaturesEnableDisabled.

@Test
public void testUserFeaturesEnableDisabled() {
    // Given
    final WebUserFeaturesRequest webUserFeaturesRequest = new WebUserFeaturesRequest();
    webUserFeaturesRequest.setJsLoggning(true);
    final HashMap<String, Feature> features = new HashMap<>();
    when(webCertUser.getFeatures()).thenReturn(features);
    // When
    userApiController.userFeatures(webUserFeaturesRequest);
    // Then
    Mockito.verify(webCertUser, times(1)).setFeatures(captor.capture());
    assertTrue(captor.getValue().containsKey(AuthoritiesConstants.FEATURE_JS_LOGGNING));
}
Also used : WebUserFeaturesRequest(se.inera.intyg.webcert.web.web.controller.api.dto.WebUserFeaturesRequest) HashMap(java.util.HashMap) Feature(se.inera.intyg.infra.security.common.model.Feature) Test(org.junit.Test)

Aggregations

Feature (se.inera.intyg.infra.security.common.model.Feature)25 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)13 Test (org.junit.Test)10 HashMap (java.util.HashMap)6 WebUserFeaturesRequest (se.inera.intyg.webcert.web.web.controller.api.dto.WebUserFeaturesRequest)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Privilege (se.inera.intyg.infra.security.common.model.Privilege)2 RequestOrigin (se.inera.intyg.infra.security.common.model.RequestOrigin)2 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)2 Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Vardenhet (se.inera.intyg.infra.integration.hsa.model.Vardenhet)1 Vardgivare (se.inera.intyg.infra.integration.hsa.model.Vardgivare)1 Role (se.inera.intyg.infra.security.common.model.Role)1 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)1 Signatur (se.inera.intyg.webcert.persistence.utkast.model.Signatur)1 LogRequest (se.inera.intyg.webcert.web.service.log.dto.LogRequest)1 SignaturTicket (se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket)1