Search in sources :

Example 1 with GlobalGroupId

use of ee.ria.xroad.common.identifier.GlobalGroupId in project X-Road by nordic-institute.

the class ServiceClientServiceIntegrationTest method getClientServiceClientsHasCorrectRightsGiven.

@Test
public void getClientServiceClientsHasCorrectRightsGiven() throws Exception {
    ClientId clientId = ClientId.create("FI", "GOV", "M1", "SS1");
    List<ServiceClientDto> serviceClients = serviceClientService.getServiceClientsByClient(clientId);
    XRoadId globalGroupId = GlobalGroupId.create("FI", "test-globalgroup");
    Optional<ServiceClientDto> groupServiceClient = serviceClients.stream().filter(dto -> dto.getSubjectId().equals(globalGroupId)).findFirst();
    assertTrue(groupServiceClient.isPresent());
    // data.sql populates times in local time zone
    ZonedDateTime correctRightsGiven = LocalDateTime.parse("2020-01-01T09:07:22").atZone(ZoneId.systemDefault());
    // persistence layer gives times in utc time zone, so compare instants
    assertEquals(correctRightsGiven.toInstant(), groupServiceClient.get().getRightsGiven().toInstant());
}
Also used : ServiceClientDto(org.niis.xroad.securityserver.restapi.dto.ServiceClientDto) GlobalGroupId(ee.ria.xroad.common.identifier.GlobalGroupId) XRoadObjectType(ee.ria.xroad.common.identifier.XRoadObjectType) ZonedDateTime(java.time.ZonedDateTime) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) ServiceClientAccessRightDto(org.niis.xroad.securityserver.restapi.dto.ServiceClientAccessRightDto) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) ServiceClientDto(org.niis.xroad.securityserver.restapi.dto.ServiceClientDto) TestUtils(org.niis.xroad.securityserver.restapi.util.TestUtils) XRoadId(ee.ria.xroad.common.identifier.XRoadId) Optional(java.util.Optional) ClientId(ee.ria.xroad.common.identifier.ClientId) Assert.assertEquals(org.junit.Assert.assertEquals) ZonedDateTime(java.time.ZonedDateTime) XRoadId(ee.ria.xroad.common.identifier.XRoadId) ClientId(ee.ria.xroad.common.identifier.ClientId) Test(org.junit.Test)

Example 2 with GlobalGroupId

use of ee.ria.xroad.common.identifier.GlobalGroupId in project X-Road by nordic-institute.

the class ServiceClientIdentifierConverterTest method convertGlobalGroup.

@Test
public void convertGlobalGroup() throws Exception {
    ServiceClientIdentifierDto dto = converter.convertId("DEV:security-server-owners");
    assertEquals(false, dto.isLocalGroup());
    assertEquals(null, dto.getLocalGroupId());
    assertEquals(XRoadObjectType.GLOBALGROUP, dto.getXRoadId().getObjectType());
    assertTrue(dto.getXRoadId() instanceof GlobalGroupId);
    GlobalGroupId globalGroupId = (GlobalGroupId) dto.getXRoadId();
    assertEquals("security-server-owners", globalGroupId.getGroupCode());
    assertEquals("DEV", globalGroupId.getXRoadInstance());
}
Also used : ServiceClientIdentifierDto(org.niis.xroad.securityserver.restapi.dto.ServiceClientIdentifierDto) GlobalGroupId(ee.ria.xroad.common.identifier.GlobalGroupId) Test(org.junit.Test)

Example 3 with GlobalGroupId

use of ee.ria.xroad.common.identifier.GlobalGroupId in project X-Road by nordic-institute.

the class AccessRightService method accessRightTypeToServiceClientDto.

/**
 * Makes an {@link ServiceClientDto} out of {@link AccessRightType}
 * @param accessRightType The AccessRightType to convert from
 * @param localGroupMap A Map containing {@link LocalGroupType LocalGroupTypes} mapped by
 * their corresponding {@link LocalGroupType#getGroupCode()}
 * @return
 */
ServiceClientDto accessRightTypeToServiceClientDto(AccessRightType accessRightType, Map<String, LocalGroupType> localGroupMap) {
    ServiceClientDto serviceClientDto = new ServiceClientDto();
    XRoadId subjectId = accessRightType.getSubjectId();
    serviceClientDto.setRightsGiven(FormatUtils.fromDateToOffsetDateTime(accessRightType.getRightsGiven()));
    serviceClientDto.setSubjectId(subjectId);
    if (subjectId.getObjectType() == XRoadObjectType.LOCALGROUP) {
        LocalGroupId localGroupId = (LocalGroupId) subjectId;
        LocalGroupType localGroupType = localGroupMap.get(localGroupId.getGroupCode());
        serviceClientDto.setLocalGroupId(localGroupType.getId().toString());
        serviceClientDto.setLocalGroupCode(localGroupType.getGroupCode());
        serviceClientDto.setLocalGroupDescription(localGroupType.getDescription());
    } else if (subjectId.getObjectType() == XRoadObjectType.GLOBALGROUP) {
        GlobalGroupId globalGroupId = (GlobalGroupId) subjectId;
        serviceClientDto.setGlobalGroupDescription(globalConfFacade.getGlobalGroupDescription(globalGroupId));
    }
    return serviceClientDto;
}
Also used : ServiceClientDto(org.niis.xroad.securityserver.restapi.dto.ServiceClientDto) LocalGroupType(ee.ria.xroad.common.conf.serverconf.model.LocalGroupType) GlobalGroupId(ee.ria.xroad.common.identifier.GlobalGroupId) XRoadId(ee.ria.xroad.common.identifier.XRoadId) LocalGroupId(ee.ria.xroad.common.identifier.LocalGroupId)

Example 4 with GlobalGroupId

use of ee.ria.xroad.common.identifier.GlobalGroupId in project X-Road by nordic-institute.

the class ServiceClientIdentifierConverter method convertId.

/**
 * Convert encoded service client id into ServiceClientIdentifierDto (based on serviceClientType,
 * id and localGroupCode).
 * Correct ServiceClientIdentifierDto is determined based solely on number of encoded id separators
 * and whether the whole string is numeric or not
 * @param encodedServiceClientIdentifier encoded service client id
 * @return ServiceClientIdentifierDto object
 * @throws BadServiceClientIdentifierException if encoded service client id was badly formatted
 */
public ServiceClientIdentifierDto convertId(String encodedServiceClientIdentifier) throws BadServiceClientIdentifierException {
    ServiceClientIdentifierDto dto = new ServiceClientIdentifierDto();
    if (clientConverter.isEncodedSubsystemId(encodedServiceClientIdentifier)) {
        // subsystem
        ClientId clientId = clientConverter.convertId(encodedServiceClientIdentifier);
        dto.setXRoadId(clientId);
    } else if (globalGroupConverter.isEncodedGlobalGroupId(encodedServiceClientIdentifier)) {
        GlobalGroupId globalGroupId = globalGroupConverter.convertId(encodedServiceClientIdentifier);
        dto.setXRoadId(globalGroupId);
    } else if (StringUtils.isNumeric(encodedServiceClientIdentifier)) {
        // local group
        Long id;
        try {
            id = Long.parseLong(encodedServiceClientIdentifier);
        } catch (NumberFormatException e) {
            throw new BadServiceClientIdentifierException(encodedServiceClientIdentifier);
        }
        dto.setLocalGroupId(id);
    } else {
        throw new BadServiceClientIdentifierException(encodedServiceClientIdentifier);
    }
    return dto;
}
Also used : ServiceClientIdentifierDto(org.niis.xroad.securityserver.restapi.dto.ServiceClientIdentifierDto) GlobalGroupId(ee.ria.xroad.common.identifier.GlobalGroupId) ClientId(ee.ria.xroad.common.identifier.ClientId)

Example 5 with GlobalGroupId

use of ee.ria.xroad.common.identifier.GlobalGroupId in project X-Road by nordic-institute.

the class ServiceClientConverter method convertServiceClientDto.

/**
 * Convert ServiceClientDto to ServiceClient.
 * @param serviceClientDto
 * @return {@link ServiceClient}
 */
public ServiceClient convertServiceClientDto(ServiceClientDto serviceClientDto) {
    ServiceClient serviceClient = new ServiceClient();
    serviceClient.setRightsGivenAt(serviceClientDto.getRightsGiven());
    XRoadId subjectId = serviceClientDto.getSubjectId();
    switch(subjectId.getObjectType()) {
        case SUBSYSTEM:
            ClientId serviceClientId = (ClientId) subjectId;
            serviceClient.setName(globalConfFacade.getMemberName(serviceClientId));
            serviceClient.setId(clientConverter.convertId(serviceClientId));
            serviceClient.setServiceClientType(ServiceClientType.SUBSYSTEM);
            break;
        case GLOBALGROUP:
            GlobalGroupId globalGroupId = (GlobalGroupId) subjectId;
            serviceClient.setName(serviceClientDto.getGlobalGroupDescription());
            serviceClient.setId(globalGroupConverter.convertId(globalGroupId));
            serviceClient.setServiceClientType(ServiceClientType.GLOBALGROUP);
            break;
        case LOCALGROUP:
            serviceClient.setId(serviceClientDto.getLocalGroupId());
            serviceClient.setLocalGroupCode(serviceClientDto.getLocalGroupCode());
            serviceClient.setName(serviceClientDto.getLocalGroupDescription());
            serviceClient.setServiceClientType(ServiceClientType.LOCALGROUP);
            break;
        default:
            break;
    }
    return serviceClient;
}
Also used : GlobalGroupId(ee.ria.xroad.common.identifier.GlobalGroupId) ServiceClient(org.niis.xroad.securityserver.restapi.openapi.model.ServiceClient) XRoadId(ee.ria.xroad.common.identifier.XRoadId) ClientId(ee.ria.xroad.common.identifier.ClientId)

Aggregations

GlobalGroupId (ee.ria.xroad.common.identifier.GlobalGroupId)7 ClientId (ee.ria.xroad.common.identifier.ClientId)5 XRoadId (ee.ria.xroad.common.identifier.XRoadId)4 LocalGroupId (ee.ria.xroad.common.identifier.LocalGroupId)3 Test (org.junit.Test)3 ServiceClientDto (org.niis.xroad.securityserver.restapi.dto.ServiceClientDto)3 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertNull (org.junit.Assert.assertNull)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 ServiceClientAccessRightDto (org.niis.xroad.securityserver.restapi.dto.ServiceClientAccessRightDto)2 ServiceClientIdentifierDto (org.niis.xroad.securityserver.restapi.dto.ServiceClientIdentifierDto)2 TestUtils (org.niis.xroad.securityserver.restapi.util.TestUtils)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 GlobalGroupInfo (ee.ria.xroad.common.conf.globalconf.GlobalGroupInfo)1 MemberInfo (ee.ria.xroad.common.conf.globalconf.MemberInfo)1 AccessRightType (ee.ria.xroad.common.conf.serverconf.model.AccessRightType)1