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());
}
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());
}
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;
}
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;
}
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;
}
Aggregations