Search in sources :

Example 1 with ModuleDescriptorDto

use of eu.bcvsolutions.idm.core.api.dto.ModuleDescriptorDto in project CzechIdMng by bcvsolutions.

the class DefaultModuleService method setEnabled.

@Override
public void setEnabled(String moduleId, boolean enabled) {
    ModuleDescriptor moduleDescriptor = moduleDescriptorRegistry.getPluginFor(moduleId);
    ModuleDescriptorDto moduleDescriptorDto = null;
    if (moduleDescriptor == null) {
        LOG.info("Frontend module [{}] will be enabled [{}].", moduleId, enabled);
        // FE module - create basic descriptor
        moduleDescriptorDto = new ModuleDescriptorDto(moduleId);
        moduleDescriptorDto.setDisableable(true);
        moduleDescriptorDto.setDisabled(!configurationService.getBooleanValue(getModuleConfigurationProperty(moduleId, ConfigurationService.PROPERTY_ENABLED), false));
    } else {
        LOG.info("Backend module [{}] will be enabled [{}].", moduleId, enabled);
        // 
        moduleDescriptorDto = toDto(moduleDescriptor);
    }
    // 
    ModuleDescriptorEvent event = new ModuleDescriptorEvent(enabled ? ModuleDescriptorEventType.ENABLE : ModuleDescriptorEventType.DISABLE, moduleDescriptorDto);
    entityEventManager.process(event);
}
Also used : ModuleDescriptor(eu.bcvsolutions.idm.core.api.domain.ModuleDescriptor) ModuleDescriptorEvent(eu.bcvsolutions.idm.core.api.event.ModuleDescriptorEvent) ModuleDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ModuleDescriptorDto)

Example 2 with ModuleDescriptorDto

use of eu.bcvsolutions.idm.core.api.dto.ModuleDescriptorDto in project CzechIdMng by bcvsolutions.

the class DefaultModuleService method toDto.

/**
 * FIXME: DRY ModuleController#toResource => redesign to work with dto?
 */
private ModuleDescriptorDto toDto(ModuleDescriptor moduleDescriptor) {
    ModuleDescriptorDto dto = mapper.map(moduleDescriptor, ModuleDescriptorDto.class);
    // 
    dto.setId(moduleDescriptor.getId());
    dto.setDisabled(!isEnabled(moduleDescriptor));
    return dto;
}
Also used : ModuleDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ModuleDescriptorDto)

Example 3 with ModuleDescriptorDto

use of eu.bcvsolutions.idm.core.api.dto.ModuleDescriptorDto in project CzechIdMng by bcvsolutions.

the class ModuleController method toResource.

/**
 * TODO: resource support + self link
 *
 * @param moduleDescriptor
 * @return
 */
protected ModuleDescriptorDto toResource(ModuleDescriptor moduleDescriptor) {
    ModuleDescriptorDto dto = mapper.map(moduleDescriptor, ModuleDescriptorDto.class);
    // 
    dto.setId(moduleDescriptor.getId());
    dto.setDisabled(!moduleService.isEnabled(moduleDescriptor));
    return dto;
}
Also used : ModuleDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ModuleDescriptorDto)

Example 4 with ModuleDescriptorDto

use of eu.bcvsolutions.idm.core.api.dto.ModuleDescriptorDto in project CzechIdMng by bcvsolutions.

the class DefaultModuleServiceUnitTest method testIsDisableable.

@Test(expected = ModuleNotDisableableException.class)
public void testIsDisableable() {
    ModuleDisableProcessor disableProcessor = new ModuleDisableProcessor();
    ModuleDescriptorDto moduleDescriptor = new ModuleDescriptorDto(ModuleDescriptorOne.MODULE_ID);
    moduleDescriptor.setDisableable(false);
    // 
    disableProcessor.process(new ModuleDescriptorEvent(ModuleDescriptorEventType.DISABLE, moduleDescriptor));
}
Also used : ModuleDisableProcessor(eu.bcvsolutions.idm.core.model.event.processor.module.ModuleDisableProcessor) ModuleDescriptorEvent(eu.bcvsolutions.idm.core.api.event.ModuleDescriptorEvent) ModuleDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ModuleDescriptorDto) AbstractVerifiableUnitTest(eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest) Test(org.junit.Test)

Example 5 with ModuleDescriptorDto

use of eu.bcvsolutions.idm.core.api.dto.ModuleDescriptorDto in project CzechIdMng by bcvsolutions.

the class AccInitRemoteServerProcessor method process.

@Override
public EventResult<ModuleDescriptorDto> process(EntityEvent<ModuleDescriptorDto> event) {
    // all remote systems => will be two at max
    List<SysConnectorServerDto> remoteServers = Lists.newArrayList(remoteServerService.find(null).getContent());
    // fill password
    remoteServers.forEach(remoteServer -> {
        remoteServer.setPassword(confidentialStorage.getGuardedString(remoteServer.getId(), SysRemoteServer.class, SysSystemService.REMOTE_SERVER_PASSWORD));
    });
    // 
    // find all systems with remote flag and empty related remoteServer
    SysSystemFilter systemFilter = new SysSystemFilter();
    systemFilter.setRemote(Boolean.TRUE);
    systemService.find(systemFilter, null).stream().filter(// remote server is not referenced => old definition with remote flag
    system -> Objects.isNull(system.getRemoteServer())).filter(system -> {
        // remote server is properly filled
        // cannot be filled from frontend, but just for sure
        SysConnectorServerDto connectorServer = system.getConnectorServer();
        if (connectorServer == null) {
            return false;
        }
        return StringUtils.isNotBlank(connectorServer.getHost());
    }).forEach(system -> {
        SysConnectorServerDto systemConnector = system.getConnectorServer();
        try {
            systemConnector.setPassword(confidentialStorage.getGuardedString(system.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD));
        } catch (SerializationException ex) {
            LOG.error("Password for configured system [{}] is broken, will be ignored.", system.getCode());
        }
        // try to find remote system by all fields
        SysConnectorServerDto remoteServer = remoteServers.stream().filter(r -> {
            return StringUtils.equals(r.getHost(), systemConnector.getHost()) && Integer.compare(r.getPort(), systemConnector.getPort()) == 0 && BooleanUtils.compare(r.isUseSsl(), systemConnector.isUseSsl()) == 0 && Integer.compare(r.getTimeout(), systemConnector.getTimeout()) == 0 && (// password is broken, e.g. when confidential storage was dropped
            systemConnector.getPassword() == null || StringUtils.equals(r.getPassword().asString(), systemConnector.getPassword().asString()));
        }).findFirst().orElse(null);
        // 
        if (remoteServer != null) {
            LOG.info("Remote server [{}] will be used for configured system [{}].", remoteServer.getFullServerName(), system.getCode());
            system.setRemoteServer(remoteServer.getId());
            systemService.save(system);
        } else {
            String systemCode = system.getCode();
            systemConnector.setDescription(String.format("Created automatically by upgrade to CzechIdM version 10.8.0 by target system [%s].", systemCode));
            GuardedString password = systemConnector.getPassword();
            remoteServer = remoteServerService.save(systemConnector);
            // preserve password
            remoteServer.setPassword(password);
            remoteServers.add(remoteServer);
            system.setRemoteServer(remoteServer.getId());
            systemService.save(system);
            LOG.info("New remote server [{}] was created and used for configured system [{}].", remoteServer.getFullServerName(), systemCode);
        }
    });
    // 
    // Turn off for next start => already processed
    getConfigurationService().setBooleanValue(getConfigurationPropertyName(ConfigurationService.PROPERTY_ENABLED), false);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : Description(org.springframework.context.annotation.Description) SysSystem(eu.bcvsolutions.idm.acc.entity.SysSystem) AbstractInitApplicationProcessor(eu.bcvsolutions.idm.core.api.event.processor.AbstractInitApplicationProcessor) SysSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) Autowired(org.springframework.beans.factory.annotation.Autowired) BooleanUtils(org.apache.commons.lang3.BooleanUtils) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) StringUtils(org.apache.commons.lang3.StringUtils) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto) SysRemoteServer(eu.bcvsolutions.idm.acc.entity.SysRemoteServer) Objects(java.util.Objects) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) List(java.util.List) Component(org.springframework.stereotype.Component) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) Lists(com.google.common.collect.Lists) SerializationException(org.apache.commons.lang3.SerializationException) SysRemoteServerService(eu.bcvsolutions.idm.acc.service.api.SysRemoteServerService) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) ModuleDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ModuleDescriptorDto) SysSystem(eu.bcvsolutions.idm.acc.entity.SysSystem) SerializationException(org.apache.commons.lang3.SerializationException) SysSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto) SysRemoteServer(eu.bcvsolutions.idm.acc.entity.SysRemoteServer)

Aggregations

ModuleDescriptorDto (eu.bcvsolutions.idm.core.api.dto.ModuleDescriptorDto)11 ModuleDescriptorEvent (eu.bcvsolutions.idm.core.api.event.ModuleDescriptorEvent)4 ModuleDescriptor (eu.bcvsolutions.idm.core.api.domain.ModuleDescriptor)3 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)3 SysConnectorServerDto (eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto)2 SysSystemFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter)2 SysSystem (eu.bcvsolutions.idm.acc.entity.SysSystem)2 SysRemoteServerService (eu.bcvsolutions.idm.acc.service.api.SysRemoteServerService)2 SysSystemService (eu.bcvsolutions.idm.acc.service.api.SysSystemService)2 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)2 ConfidentialStorage (eu.bcvsolutions.idm.core.api.service.ConfidentialStorage)2 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)2 ApiOperation (io.swagger.annotations.ApiOperation)2 List (java.util.List)2 Test (org.junit.Test)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 Lists (com.google.common.collect.Lists)1