Search in sources :

Example 21 with Feature

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

the class FragaSvarServiceImplTest method buildUserOfRole.

private WebCertUser buildUserOfRole(Role role) {
    WebCertUser user = new WebCertUser();
    user.setRoles(AuthoritiesResolverUtil.toMap(role));
    user.setAuthorities(AuthoritiesResolverUtil.toMap(role.getPrivileges(), Privilege::getName));
    user.setOrigin("NORMAL");
    user.setHsaId("testuser");
    user.setNamn("test userman");
    Feature feature = new Feature();
    feature.setName(AuthoritiesConstants.FEATURE_HANTERA_FRAGOR);
    feature.setGlobal(true);
    feature.setIntygstyper(ImmutableList.of("fk7263"));
    user.setFeatures(ImmutableMap.of(AuthoritiesConstants.FEATURE_HANTERA_FRAGOR, feature));
    Vardenhet vardenhet = new Vardenhet("enhet", "Enhet");
    Vardgivare vardgivare = new Vardgivare("vardgivare", "Vardgivaren");
    vardgivare.getVardenheter().add(vardenhet);
    user.setVardgivare(Collections.singletonList(vardgivare));
    user.setValdVardenhet(vardenhet);
    return user;
}
Also used : Vardenhet(se.inera.intyg.infra.integration.hsa.model.Vardenhet) Vardgivare(se.inera.intyg.infra.integration.hsa.model.Vardgivare) Feature(se.inera.intyg.infra.security.common.model.Feature) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 22 with Feature

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

the class BaseCreateDraftCertificateValidatorTest method buildUser.

protected WebCertUser buildUser() {
    WebCertUser user = new WebCertUser();
    user.setAuthorities(new HashMap<>());
    user.getAuthorities().put(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, createPrivilege(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT));
    user.getAuthorities().put(AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG, createPrivilege(AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG));
    Feature feature = new Feature();
    feature.setName(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST);
    feature.setIntygstyper(Arrays.asList(Fk7263EntryPoint.MODULE_ID, TsBasEntryPoint.MODULE_ID));
    user.setFeatures(Collections.singletonMap(feature.getName(), feature));
    user.setOrigin(UserOriginType.DJUPINTEGRATION.name());
    return user;
}
Also used : Feature(se.inera.intyg.infra.security.common.model.Feature) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 23 with Feature

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

the class AuthoritiesValidatorTest method createDefaultUser.

private WebCertUser createDefaultUser() {
    Map<String, Feature> featureMap = new HashMap<>();
    Feature feature1 = new Feature();
    feature1.setName(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST);
    feature1.setIntygstyper(Collections.singletonList("fk7263"));
    featureMap.put(feature1.getName(), feature1);
    Feature feature2 = new Feature();
    feature2.setName("base_feature");
    feature2.setIntygstyper(Collections.emptyList());
    featureMap.put(feature2.getName(), feature2);
    return createUser(AuthoritiesConstants.ROLE_LAKARE, createPrivilege("p1", // p1 is restricted to these intygstyper
    Arrays.asList("fk7263", "ts-bas"), Arrays.asList(createRequestOrigin(UserOriginType.NORMAL.name(), Arrays.asList("fk7263")), // Normal restricted to fk7263
    createRequestOrigin(UserOriginType.DJUPINTEGRATION.name(), Arrays.asList("ts-bas")))), featureMap, // is not.
    UserOriginType.NORMAL.name());
}
Also used : HashMap(java.util.HashMap) Feature(se.inera.intyg.infra.security.common.model.Feature)

Example 24 with Feature

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

the class AuthoritiesValidatorTest method testMustHaveSomeFeature.

@Test
public void testMustHaveSomeFeature() {
    WebCertUser user = createDefaultUser();
    user.setFeatures(Stream.of(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST, AuthoritiesConstants.FEATURE_HANTERA_FRAGOR).collect(Collectors.toMap(Function.identity(), s -> {
        Feature feature = new Feature();
        feature.setName(s);
        feature.setIntygstyper(Collections.singletonList("fk7263"));
        return feature;
    })));
    assertTrue(validator.given(user, "fk7263").features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST, AuthoritiesConstants.FEATURE_ARBETSGIVARUTSKRIFT).isVerified());
}
Also used : Feature(se.inera.intyg.infra.security.common.model.Feature) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 25 with Feature

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

the class AuthoritiesValidatorTest method testMustHaveFeature.

@Test
public void testMustHaveFeature() {
    WebCertUser user = createDefaultUser();
    user.setFeatures(Stream.of(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST, AuthoritiesConstants.FEATURE_HANTERA_FRAGOR).collect(Collectors.toMap(Function.identity(), s -> {
        Feature feature = new Feature();
        feature.setName(s);
        feature.setIntygstyper(Collections.singletonList("fk7263"));
        return feature;
    })));
    assertTrue(validator.given(user, "fk7263").features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST).features(AuthoritiesConstants.FEATURE_HANTERA_FRAGOR).notFeatures(AuthoritiesConstants.FEATURE_FORNYA_INTYG).isVerified());
}
Also used : Feature(se.inera.intyg.infra.security.common.model.Feature) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) 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