Search in sources :

Example 11 with Role

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

the class PageControllerTest method createMockUser.

private WebCertUser createMockUser(boolean doctor, String... features) {
    Role role = AUTHORITIES_RESOLVER.getRole(AuthoritiesConstants.ROLE_LAKARE);
    if (!doctor) {
        role = AUTHORITIES_RESOLVER.getRole(AuthoritiesConstants.ROLE_ADMIN);
    }
    WebCertUser user = new WebCertUser();
    user.setRoles(AuthoritiesResolverUtil.toMap(role));
    user.setAuthorities(AuthoritiesResolverUtil.toMap(role.getPrivileges(), Privilege::getName));
    user.setVardgivare(Collections.singletonList(createMockVardgivare()));
    user.setFeatures(Stream.of(features).collect(Collectors.toMap(Function.identity(), s -> {
        Feature feature = new Feature();
        feature.setName(s);
        feature.setGlobal(true);
        feature.setIntygstyper(Collections.singletonList(INTYG_TYP_FK7263));
        return feature;
    })));
    return user;
}
Also used : Role(se.inera.intyg.infra.security.common.model.Role) Feature(se.inera.intyg.infra.security.common.model.Feature) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 12 with Role

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

the class IntygIntegrationControllerTest method createUser.

private WebCertUser createUser(String roleName, Privilege p, Map<String, Feature> features, String origin) {
    WebCertUser user = new WebCertUser();
    HashMap<String, Privilege> pMap = new HashMap<>();
    pMap.put(p.getName(), p);
    user.setAuthorities(pMap);
    user.setOrigin(origin);
    user.setFeatures(features);
    HashMap<String, Role> rMap = new HashMap<>();
    Role role = new Role();
    role.setName(roleName);
    rMap.put(roleName, role);
    user.setRoles(rMap);
    Vardgivare vg = new Vardgivare();
    vg.setId("vg1");
    Vardenhet ve = new Vardenhet();
    ve.setVardgivareHsaId("vg1");
    ve.setId(ENHETSID);
    vg.setVardenheter(Arrays.asList(ve));
    user.setVardgivare(Arrays.asList(vg));
    return user;
}
Also used : Role(se.inera.intyg.infra.security.common.model.Role) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Privilege(se.inera.intyg.infra.security.common.model.Privilege) Vardgivare(se.inera.intyg.infra.integration.hsa.model.Vardgivare) Vardenhet(se.inera.intyg.infra.integration.hsa.model.Vardenhet) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 13 with Role

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

the class IntygIntegrationServiceImplTest method createUser.

private WebCertUser createUser(String roleName, Privilege p, Map<String, Feature> features, String origin) {
    WebCertUser user = new WebCertUser();
    HashMap<String, Privilege> pMap = new HashMap<>();
    pMap.put(p.getName(), p);
    user.setAuthorities(pMap);
    user.setOrigin(origin);
    user.setFeatures(features);
    HashMap<String, Role> rMap = new HashMap<>();
    Role role = new Role();
    role.setName(roleName);
    rMap.put(roleName, role);
    user.setRoles(rMap);
    return user;
}
Also used : Role(se.inera.intyg.infra.security.common.model.Role) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Privilege(se.inera.intyg.infra.security.common.model.Privilege) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 14 with Role

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

the class StatModuleApiControllerTest method setupDataAndExpectations.

@Before
public void setupDataAndExpectations() {
    fragaSvarStatsMap = new HashMap<>();
    fragaSvarStatsMap.put("VE1", 2L);
    fragaSvarStatsMap.put("VE1M1", 3L);
    fragaSvarStatsMap.put("VE1M2", 3L);
    fragaSvarStatsMap.put("VE2", 2L);
    fragaSvarStatsMap.put("VE3", 1L);
    arendeStatsMap = new HashMap<>();
    arendeStatsMap.put("VE1", 2L);
    arendeStatsMap.put("VE1M1", 3L);
    arendeStatsMap.put("VE1M2", 3L);
    arendeStatsMap.put("VE2", 2L);
    arendeStatsMap.put("VE3", 1L);
    intygStatsMap = new HashMap<>();
    intygStatsMap.put("VE1M1", 1L);
    intygStatsMap.put("VE1M2", 2L);
    intygStatsMap.put("VE2", 2L);
    mockUser = new WebCertUser();
    Role role = AUTHORITIES_RESOLVER.getRole(AuthoritiesConstants.ROLE_LAKARE);
    mockUser.setRoles(AuthoritiesResolverUtil.toMap(role));
    mockUser.setAuthorities(AuthoritiesResolverUtil.toMap(role.getPrivileges(), Privilege::getName));
    ve1 = new Vardenhet("VE1", "Vardenhet1");
    ve1.getMottagningar().add(new Mottagning("VE1M1", "Mottagning1"));
    ve1.getMottagningar().add(new Mottagning("VE1M2", "Mottagning2"));
    ve2 = new Vardenhet("VE2", "Vardenhet2");
    ve2.getMottagningar().add(new Mottagning("VE2M1", "Mottagning3"));
    ve3 = new Vardenhet("VE3", "Vardenhet3");
    ve4 = new Vardenhet("VE4", "Vardenhet4");
    Vardgivare vg = new Vardgivare("VG1", "Vardgivaren");
    vg.setVardenheter(Arrays.asList(ve1, ve2, ve3, ve4));
    mockUser.setVardgivare(Collections.singletonList(vg));
    mockUser.setValdVardgivare(vg);
    when(authoritiesHelper.getIntygstyperForPrivilege(any(UserDetails.class), anyString())).thenReturn(Stream.of("fk7263").collect(Collectors.toSet()));
    when(webCertUserService.getUser()).thenReturn(mockUser);
}
Also used : Role(se.inera.intyg.infra.security.common.model.Role) UserDetails(se.inera.intyg.infra.security.common.model.UserDetails) Vardenhet(se.inera.intyg.infra.integration.hsa.model.Vardenhet) Vardgivare(se.inera.intyg.infra.integration.hsa.model.Vardgivare) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Mottagning(se.inera.intyg.infra.integration.hsa.model.Mottagning) Before(org.junit.Before)

Example 15 with Role

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

the class ElegWebCertUserDetailsService method createUser.

// - - - - - Default scope - - - - -
protected WebCertUser createUser(SAMLCredential samlCredential) {
    String personId = elegAuthenticationAttributeHelper.getAttribute(samlCredential, CgiElegAssertion.PERSON_ID_ATTRIBUTE);
    assertHosPersonIsAuthorized(personId);
    HoSPersonType hosPerson = getHosPerson(personId);
    if (hosPerson == null) {
        throw new IllegalArgumentException("No HSAPerson found for personId specified in SAML ticket");
    }
    // Lookup user's role
    Role role = lookupUserRole();
    return createWebCertUser(hosPerson, role, samlCredential);
}
Also used : Role(se.inera.intyg.infra.security.common.model.Role) HoSPersonType(se.riv.infrastructure.directory.privatepractitioner.v1.HoSPersonType)

Aggregations

Role (se.inera.intyg.infra.security.common.model.Role)22 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)18 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 Vardenhet (se.inera.intyg.infra.integration.hsa.model.Vardenhet)5 Vardgivare (se.inera.intyg.infra.integration.hsa.model.Vardgivare)5 Privilege (se.inera.intyg.infra.security.common.model.Privilege)5 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 IntegrationParameters (se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters)3 Authentication (org.springframework.security.core.Authentication)2 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1 JsonPropertyDescription (com.fasterxml.jackson.annotation.JsonPropertyDescription)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Before (org.junit.Before)1 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)1