Search in sources :

Example 51 with ResultCodeException

use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.

the class SysSystemController method getAvailableRemoteConnectors.

/**
 * Rest endpoints return available remote connectors.
 * If entity hasn't set for remote or isn't exists return empty map of connectors
 *
 * @param backendId
 * @return
 */
@RequestMapping(method = RequestMethod.GET, value = "{backendId}/search/remote")
@PreAuthorize("hasAuthority('" + AccGroupPermission.SYSTEM_READ + "')")
@ApiOperation(value = "Get available remote connectors", nickname = "getAvailableRemoteConnectors", tags = { SysSystemController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = AccGroupPermission.SYSTEM_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = AccGroupPermission.SYSTEM_READ, description = "") }) }, notes = "Supported remote conectors (by remote server configuration).")
public ResponseEntity<Map<String, Set<IcConnectorInfo>>> getAvailableRemoteConnectors(@ApiParam(value = "System's uuid identifier or code.", required = true) @PathVariable @NotNull String backendId) {
    SysSystemDto dto = this.getDto(backendId);
    Map<String, Set<IcConnectorInfo>> infos = new HashMap<>();
    // if entity hasn't set up for remote return empty map
    if (dto == null || !dto.isRemote()) {
        return new ResponseEntity<Map<String, Set<IcConnectorInfo>>>(infos, HttpStatus.OK);
    }
    Assert.notNull(dto.getConnectorServer());
    // 
    try {
        for (IcConfigurationService config : icConfiguration.getIcConfigs().values()) {
            SysConnectorServerDto server = dto.getConnectorServer();
            server.setPassword(this.confidentialStorage.getGuardedString(dto.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD));
            infos.put(config.getFramework(), config.getAvailableRemoteConnectors(server));
        }
    } catch (IcInvalidCredentialException e) {
        throw new ResultCodeException(AccResultCode.REMOTE_SERVER_INVALID_CREDENTIAL, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
    } catch (IcServerNotFoundException e) {
        throw new ResultCodeException(AccResultCode.REMOTE_SERVER_NOT_FOUND, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
    } catch (IcCantConnectException e) {
        throw new ResultCodeException(AccResultCode.REMOTE_SERVER_CANT_CONNECT, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
    } catch (IcRemoteServerException e) {
        throw new ResultCodeException(AccResultCode.REMOTE_SERVER_UNEXPECTED_ERROR, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
    }
    // 
    return new ResponseEntity<Map<String, Set<IcConnectorInfo>>>(infos, HttpStatus.OK);
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) IcServerNotFoundException(eu.bcvsolutions.idm.ic.exception.IcServerNotFoundException) IcInvalidCredentialException(eu.bcvsolutions.idm.ic.exception.IcInvalidCredentialException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSystem(eu.bcvsolutions.idm.acc.entity.SysSystem) ResponseEntity(org.springframework.http.ResponseEntity) IcConfigurationService(eu.bcvsolutions.idm.ic.service.api.IcConfigurationService) IcCantConnectException(eu.bcvsolutions.idm.ic.exception.IcCantConnectException) IcRemoteServerException(eu.bcvsolutions.idm.ic.exception.IcRemoteServerException) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 52 with ResultCodeException

use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.

the class SysSystemController method getConnectorFormValues.

/**
 * Returns filled connector configuration
 * or throws exception with code {@code CONNECTOR_CONFIGURATION_FOR_SYSTEM_NOT_FOUND}, when system is wrong configured
 *
 * @param backendId
 * @return
 */
@ResponseBody
@PreAuthorize("hasAuthority('" + AccGroupPermission.SYSTEM_READ + "')")
@RequestMapping(value = "/{backendId}/connector-form-values", method = RequestMethod.GET)
@ApiOperation(value = "Connector configuration - read values", nickname = "getConnectorFormValues", tags = { SysSystemController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = AccGroupPermission.SYSTEM_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = AccGroupPermission.SYSTEM_READ, description = "") }) })
public Resource<?> getConnectorFormValues(@ApiParam(value = "System's uuid identifier or code.", required = true) @PathVariable @NotNull String backendId) {
    SysSystemDto entity = getDto(backendId);
    if (entity == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
    }
    IdmFormDefinitionDto formDefinition = getConnectorFormDefinition(entity);
    return formDefinitionController.getFormValues(entity, formDefinition);
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 53 with ResultCodeException

use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.

the class SysSystemController method generateSchema.

@ResponseBody
@PreAuthorize("hasAuthority('" + AccGroupPermission.SYSTEM_UPDATE + "')")
@RequestMapping(value = "/{backendId}/generate-schema", method = RequestMethod.POST)
@ApiOperation(value = "Generate system schema", nickname = "generateSystemSchema", tags = { SysSystemController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = AccGroupPermission.SYSTEM_UPDATE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = AccGroupPermission.SYSTEM_UPDATE, description = "") }) }, notes = "Genetares schema by system's connector configuration")
public ResponseEntity<?> generateSchema(@ApiParam(value = "System's uuid identifier or code.", required = true) @PathVariable @NotNull String backendId) {
    SysSystemDto system = getDto(backendId);
    if (system == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
    }
    systemService.generateSchema(system);
    return new ResponseEntity<>(toResource(system), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 54 with ResultCodeException

use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.

the class DefaultSysSystemMappingService method validate.

/**
 * Validate system mapping
 *
 * @param id(UUID
 *            system mapping)
 */
@Override
public void validate(UUID id) {
    Assert.notNull(id);
    // 
    Map<String, Object> errors = new HashMap<>();
    SysSystemMappingDto systemMapping = this.get(id);
    List<SysSystemAttributeMappingDto> attributesList = getAttributeMappingService().findBySystemMapping(systemMapping);
    // 
    errors = validateIdentifier(errors, systemMapping, attributesList);
    errors = validateSynchronizationContracts(errors, systemMapping, attributesList);
    if (!errors.isEmpty()) {
        throw new ResultCodeException(AccResultCode.SYSTEM_MAPPING_VALIDATION, errors);
    }
}
Also used : HashMap(java.util.HashMap) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)

Example 55 with ResultCodeException

use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.

the class DefaultSysSystemService method generateSchema.

@Override
@Transactional
public List<SysSchemaObjectClassDto> generateSchema(SysSystemDto system) {
    Assert.notNull(system);
    Assert.notNull(system.getId());
    // Find connector identification persisted in system
    IcConnectorKey connectorKey = system.getConnectorKey();
    if (connectorKey == null) {
        throw new ResultCodeException(AccResultCode.CONNECTOR_KEY_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
    }
    // Find connector configuration persisted in system
    IcConnectorConfiguration connectorConfig = getConnectorConfiguration(system);
    if (connectorConfig == null) {
        throw new ResultCodeException(AccResultCode.CONNECTOR_CONFIGURATION_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
    }
    // Call IC module and find schema for given connector key and
    // configuration
    IcSchema icSchema = icConfigurationFacade.getSchema(system.getConnectorInstance(), connectorConfig);
    if (icSchema == null) {
        throw new ResultCodeException(AccResultCode.CONNECTOR_SCHEMA_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
    }
    // Load existing object class from system
    SysSchemaObjectClassFilter objectClassFilter = new SysSchemaObjectClassFilter();
    objectClassFilter.setSystemId(system.getId());
    List<SysSchemaObjectClassDto> sysObjectClassesInSystem = null;
    Page<SysSchemaObjectClassDto> page = objectClassService.find(objectClassFilter, null);
    sysObjectClassesInSystem = page.getContent();
    // Convert IC schema to ACC entities
    List<SysSchemaObjectClassDto> sysObjectClasses = new ArrayList<SysSchemaObjectClassDto>();
    List<SysSchemaAttributeDto> sysAttributes = new ArrayList<SysSchemaAttributeDto>();
    for (IcObjectClassInfo objectClass : icSchema.getDeclaredObjectClasses()) {
        // __ACCOUNT__ and __GROUP__
        if (!(objectClass.getType().startsWith("__") && objectClass.getType().endsWith("__"))) {
            continue;
        }
        SysSchemaObjectClassDto sysObjectClass = null;
        // values from resource
        if (sysObjectClassesInSystem != null) {
            Optional<SysSchemaObjectClassDto> objectClassSame = sysObjectClassesInSystem.stream().filter(objectClassInSystem -> {
                // 
                return objectClassInSystem.getObjectClassName().equals(objectClass.getType());
            }).findFirst();
            if (objectClassSame.isPresent()) {
                sysObjectClass = objectClassSame.get();
            }
        }
        // Convert IC object class to ACC (if is null, then will be created
        // new instance)
        sysObjectClass = convertIcObjectClassInfo(objectClass, sysObjectClass);
        sysObjectClass.setSystem(system.getId());
        // object class may not exist
        sysObjectClass = schemaObjectClassService.save(sysObjectClass);
        sysObjectClasses.add(sysObjectClass);
        List<SysSchemaAttributeDto> attributesInSystem = null;
        // Load existing attributes for existing object class in system
        if (sysObjectClass.getId() != null) {
            SysSchemaAttributeFilter attFilter = new SysSchemaAttributeFilter();
            attFilter.setSystemId(system.getId());
            attFilter.setObjectClassId(sysObjectClass.getId());
            Page<SysSchemaAttributeDto> attributesInSystemPage = attributeService.find(attFilter, null);
            attributesInSystem = attributesInSystemPage.getContent();
        }
        for (IcAttributeInfo attribute : objectClass.getAttributeInfos()) {
            // If will be IC and ACC attribute same (same name), then we
            // will do only refresh object values from resource
            SysSchemaAttributeDto sysAttribute = null;
            if (attributesInSystem != null) {
                Optional<SysSchemaAttributeDto> sysAttributeOptional = attributesInSystem.stream().filter(a -> {
                    return a.getName().equals(attribute.getName());
                }).findFirst();
                if (sysAttributeOptional.isPresent()) {
                    sysAttribute = sysAttributeOptional.get();
                }
            }
            sysAttribute = convertIcAttributeInfo(attribute, sysAttribute);
            sysAttribute.setObjectClass(sysObjectClass.getId());
            sysAttributes.add(sysAttribute);
        }
    }
    // Persist generated schema to system
    sysObjectClasses = (List<SysSchemaObjectClassDto>) objectClassService.saveAll(sysObjectClasses);
    attributeService.saveAll(sysAttributes);
    return sysObjectClasses;
}
Also used : IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) SysSystem_(eu.bcvsolutions.idm.acc.entity.SysSystem_) FormPropertyManager(eu.bcvsolutions.idm.acc.service.api.FormPropertyManager) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) SysSyncConfigFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter) SysSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) IcConfigurationPropertiesImpl(eu.bcvsolutions.idm.ic.impl.IcConfigurationPropertiesImpl) Asserts(org.apache.http.util.Asserts) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) StringUtils(org.apache.commons.lang3.StringUtils) IcConfigurationProperties(eu.bcvsolutions.idm.ic.api.IcConfigurationProperties) SysConnectorKeyDto(eu.bcvsolutions.idm.acc.dto.SysConnectorKeyDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IcConnectorInstance(eu.bcvsolutions.idm.ic.api.IcConnectorInstance) Predicate(javax.persistence.criteria.Predicate) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Map(java.util.Map) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) IcConnectorConfigurationCzechIdMImpl(eu.bcvsolutions.idm.ic.czechidm.domain.IcConnectorConfigurationCzechIdMImpl) SysSyncConfigService(eu.bcvsolutions.idm.acc.service.api.SysSyncConfigService) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) IcConfigurationFacade(eu.bcvsolutions.idm.ic.service.api.IcConfigurationFacade) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) SysSystem(eu.bcvsolutions.idm.acc.entity.SysSystem) ImmutableMap(com.google.common.collect.ImmutableMap) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) IcConnectorKeyImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorKeyImpl) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) SysSchemaObjectClassFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaObjectClassFilter) Serializable(java.io.Serializable) List(java.util.List) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) Optional(java.util.Optional) SysSchemaObjectClassService(eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) IcConnectorFacade(eu.bcvsolutions.idm.ic.service.api.IcConnectorFacade) HashMap(java.util.HashMap) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSystemRepository(eu.bcvsolutions.idm.acc.repository.SysSystemRepository) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) IdmPasswordPolicy_(eu.bcvsolutions.idm.core.model.entity.IdmPasswordPolicy_) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) IcObjectClassInfo(eu.bcvsolutions.idm.ic.api.IcObjectClassInfo) IcUidAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl) Service(org.springframework.stereotype.Service) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) SysSystemFormValueService(eu.bcvsolutions.idm.acc.service.api.SysSystemFormValueService) IcConfigurationProperty(eu.bcvsolutions.idm.ic.api.IcConfigurationProperty) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) Root(javax.persistence.criteria.Root) IcAttributeInfo(eu.bcvsolutions.idm.ic.api.IcAttributeInfo) SysSystemMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter) IcConnectorKey(eu.bcvsolutions.idm.ic.api.IcConnectorKey) IcSchema(eu.bcvsolutions.idm.ic.api.IcSchema) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) SysSchemaAttributeService(eu.bcvsolutions.idm.acc.service.api.SysSchemaAttributeService) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) IcConnectorConfigurationImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorConfigurationImpl) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) AbstractFormableService(eu.bcvsolutions.idm.core.eav.api.service.AbstractFormableService) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) AuthorizableType(eu.bcvsolutions.idm.core.security.api.dto.AuthorizableType) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) IcAttributeInfo(eu.bcvsolutions.idm.ic.api.IcAttributeInfo) SysSchemaObjectClassFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaObjectClassFilter) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) IcConnectorKey(eu.bcvsolutions.idm.ic.api.IcConnectorKey) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) ArrayList(java.util.ArrayList) IcObjectClassInfo(eu.bcvsolutions.idm.ic.api.IcObjectClassInfo) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) IcSchema(eu.bcvsolutions.idm.ic.api.IcSchema) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)162 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)48 ApiOperation (io.swagger.annotations.ApiOperation)47 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)47 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)44 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)33 Test (org.junit.Test)31 ResponseEntity (org.springframework.http.ResponseEntity)22 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)20 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)17 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)17 Transactional (org.springframework.transaction.annotation.Transactional)17 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)15 UUID (java.util.UUID)15 ArrayList (java.util.ArrayList)14 IdmPasswordPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto)13 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)12 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)12 IOException (java.io.IOException)12 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)10