Search in sources :

Example 6 with ModuleDescriptorDto

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

the class InitApplicationData method init.

protected void init() {
    securityService.setSystemAuthentication();
    // 
    LOG.info("Init application - start ...");
    try {
        // 
        // Cancels all previously ran events (before server is restarted).
        // Init is called before new event is published => defined here (cannot be done in processor).
        entityEventManager.init();
        // start application by event
        ModuleDescriptorEvent event = new ModuleDescriptorEvent(ModuleDescriptorEventType.INIT, new ModuleDescriptorDto(AppModule.MODULE_ID));
        // publish event => all registered processors will be notified
        entityEventManager.publishEvent(event);
        // 
        LOG.info("Init application - complete.");
    } finally {
        securityService.logout();
    }
}
Also used : ModuleDescriptorEvent(eu.bcvsolutions.idm.core.api.event.ModuleDescriptorEvent) ModuleDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ModuleDescriptorDto)

Example 7 with ModuleDescriptorDto

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

the class ModuleController method put.

/**
 * Supports enable / disable only
 *
 * @param moduleId
 * @param nativeRequest
 * @return
 */
@ResponseBody
@RequestMapping(value = "/{moduleId}", method = RequestMethod.PUT)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.MODULE_UPDATE + "')")
@ApiOperation(value = "Update module properties", nickname = "putModule", tags = { ModuleController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.MODULE_UPDATE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.MODULE_UPDATE, description = "") }) }, notes = "Supports enable / disable only")
public ModuleDescriptorDto put(@ApiParam(value = "Module's identifier.", required = true) @PathVariable @NotNull String moduleId, HttpServletRequest nativeRequest) {
    ModuleDescriptor updatedModuleDescriptor = moduleService.getModule(moduleId);
    if (updatedModuleDescriptor == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", moduleId));
    }
    ModuleDescriptorDto md = (ModuleDescriptorDto) requestResourceResolver.resolve(nativeRequest, ModuleDescriptorDto.class, null);
    moduleService.setEnabled(moduleId, !md.isDisabled());
    return get(moduleId);
}
Also used : ModuleDescriptor(eu.bcvsolutions.idm.core.api.domain.ModuleDescriptor) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) ModuleDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ModuleDescriptorDto) 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 8 with ModuleDescriptorDto

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

the class AccInitRemoteServerProcessorIntegrationTest method testInit.

@Test
public void testInit() {
    String host = getHelper().createName();
    String password = getHelper().createName();
    String description = getHelper().createName();
    // 
    SysConnectorServerDto remoteServer = new SysConnectorServerDto();
    remoteServer.setHost(host);
    remoteServer.setPassword(new GuardedString(password));
    remoteServer.setPort(2);
    remoteServer.setTimeout(2);
    remoteServer.setUseSsl(true);
    remoteServerService.save(remoteServer);
    // 
    SysRemoteServerFilter filter = new SysRemoteServerFilter();
    filter.setText(host);
    List<SysConnectorServerDto> results = remoteServerService.find(filter, null).getContent();
    Assert.assertEquals(1, results.size());
    SysConnectorServerDto existRemoteServer = results.get(0);
    // 
    // wee need to save system old way => repository is used
    SysSystem system = new SysSystem();
    system.setRemote(true);
    system.setName(getHelper().createName());
    system.setDescription(description);
    system.setConnectorServer(new SysConnectorServer());
    system.getConnectorServer().setHost(host);
    system.getConnectorServer().setPassword(new GuardedString(password));
    system.getConnectorServer().setPort(1);
    system.getConnectorServer().setTimeout(2);
    system.getConnectorServer().setUseSsl(true);
    system.setBlockedOperation(new SysBlockedOperation());
    SysSystemDto systemOne = systemService.get(systemRepository.save(system).getId());
    confidentialStorage.saveGuardedString(systemOne.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD, new GuardedString(password));
    // 
    system = new SysSystem();
    system.setRemote(true);
    system.setName(getHelper().createName());
    system.setDescription(description);
    system.setConnectorServer(new SysConnectorServer());
    system.getConnectorServer().setHost(host);
    system.getConnectorServer().setPassword(new GuardedString(password));
    system.getConnectorServer().setPort(1);
    system.getConnectorServer().setTimeout(2);
    system.getConnectorServer().setUseSsl(true);
    system.setBlockedOperation(new SysBlockedOperation());
    SysSystemDto systemTwo = systemService.get(systemRepository.save(system).getId());
    confidentialStorage.saveGuardedString(systemTwo.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD, new GuardedString(password));
    // 
    system = new SysSystem();
    system.setRemote(true);
    system.setName(getHelper().createName());
    system.setDescription(description);
    system.setConnectorServer(new SysConnectorServer());
    system.getConnectorServer().setHost(host);
    String differentPassword = getHelper().createName();
    // different password
    system.getConnectorServer().setPassword(new GuardedString(differentPassword));
    system.getConnectorServer().setPort(1);
    system.getConnectorServer().setTimeout(2);
    system.getConnectorServer().setUseSsl(true);
    system.setBlockedOperation(new SysBlockedOperation());
    SysSystemDto systemThree = systemService.get(systemRepository.save(system).getId());
    confidentialStorage.saveGuardedString(systemThree.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD, new GuardedString(differentPassword));
    // 
    system = new SysSystem();
    system.setRemote(true);
    system.setName(getHelper().createName());
    system.setDescription(description);
    system.setConnectorServer(new SysConnectorServer());
    system.getConnectorServer().setHost(host);
    system.getConnectorServer().setPassword(new GuardedString(password));
    system.getConnectorServer().setPort(1);
    system.getConnectorServer().setTimeout(2);
    // useSsl - different
    system.getConnectorServer().setUseSsl(false);
    system.setBlockedOperation(new SysBlockedOperation());
    SysSystemDto systemFour = systemService.get(systemRepository.save(system).getId());
    confidentialStorage.saveGuardedString(systemFour.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD, new GuardedString(password));
    // 
    system = new SysSystem();
    system.setRemote(true);
    system.setName(getHelper().createName());
    system.setDescription(description);
    system.setConnectorServer(new SysConnectorServer());
    system.getConnectorServer().setHost(host);
    system.getConnectorServer().setPassword(new GuardedString(password));
    system.getConnectorServer().setPort(2);
    system.getConnectorServer().setTimeout(2);
    // useSsl - different
    system.getConnectorServer().setUseSsl(true);
    system.setBlockedOperation(new SysBlockedOperation());
    SysSystemDto systemFive = systemService.get(systemRepository.save(system).getId());
    confidentialStorage.saveGuardedString(systemFive.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD, new GuardedString(password));
    // 
    SysSystemFilter systemFilter = new SysSystemFilter();
    systemFilter.setText(description);
    List<SysSystemDto> systems = systemService.find(systemFilter, null).getContent();
    Assert.assertEquals(5, systems.size());
    Assert.assertTrue(systems.stream().allMatch(s -> s.isRemote()));
    Assert.assertTrue(systems.stream().allMatch(s -> s.getRemoteServer() == null));
    // 
    // process migration
    initProcessor.process(new ModuleDescriptorEvent(ModuleDescriptorEventType.INIT, new ModuleDescriptorDto(AccModuleDescriptor.MODULE_ID)));
    // 
    systems = systemService.find(systemFilter, null).getContent();
    Assert.assertTrue(systems.stream().allMatch(s -> s.isRemote()));
    Assert.assertTrue(systems.stream().allMatch(s -> s.getRemoteServer() != null));
    results = remoteServerService.find(filter, null).getContent();
    Assert.assertEquals(4, results.size());
    // 
    // one - two => same
    systemOne = systemService.get(systemOne);
    systemTwo = systemService.get(systemTwo);
    Assert.assertEquals(systemOne.getRemoteServer(), systemTwo.getRemoteServer());
    Assert.assertEquals(password, confidentialStorage.getGuardedString(systemOne.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD).asString());
    Assert.assertEquals(password, confidentialStorage.getGuardedString(systemTwo.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD).asString());
    Assert.assertEquals(password, remoteServerService.getPassword(systemTwo.getRemoteServer()).asString());
    // 
    // three - different password
    systemThree = systemService.get(systemThree);
    Assert.assertEquals(differentPassword, confidentialStorage.getGuardedString(systemThree.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD).asString());
    Assert.assertEquals(differentPassword, remoteServerService.getPassword(systemThree.getRemoteServer()).asString());
    Assert.assertNotEquals(systemOne.getRemoteServer(), systemThree.getRemoteServer());
    // 
    // four - different ssl
    systemFour = systemService.get(systemFour);
    Assert.assertEquals(password, confidentialStorage.getGuardedString(systemOne.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD).asString());
    Assert.assertEquals(password, remoteServerService.getPassword(systemFour.getRemoteServer()).asString());
    Assert.assertNotEquals(systemOne.getRemoteServer(), systemFour.getRemoteServer());
    Assert.assertNotEquals(systemThree.getRemoteServer(), systemFour.getRemoteServer());
    // 
    // five - exists
    systemFive = systemService.get(systemFive);
    Assert.assertEquals(existRemoteServer.getId(), systemFive.getRemoteServer());
}
Also used : AccModuleDescriptor(eu.bcvsolutions.idm.acc.AccModuleDescriptor) SysSystem(eu.bcvsolutions.idm.acc.entity.SysSystem) SysConnectorServer(eu.bcvsolutions.idm.acc.entity.SysConnectorServer) SysSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSystemRepository(eu.bcvsolutions.idm.acc.repository.SysSystemRepository) ModuleDescriptorEvent(eu.bcvsolutions.idm.core.api.event.ModuleDescriptorEvent) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto) ModuleDescriptorEventType(eu.bcvsolutions.idm.core.api.event.ModuleDescriptorEvent.ModuleDescriptorEventType) List(java.util.List) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) SysRemoteServerFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRemoteServerFilter) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) SysRemoteServerService(eu.bcvsolutions.idm.acc.service.api.SysRemoteServerService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) SysBlockedOperation(eu.bcvsolutions.idm.acc.entity.SysBlockedOperation) ModuleDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ModuleDescriptorDto) SysSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter) SysRemoteServerFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRemoteServerFilter) SysConnectorServer(eu.bcvsolutions.idm.acc.entity.SysConnectorServer) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) ModuleDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ModuleDescriptorDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSystem(eu.bcvsolutions.idm.acc.entity.SysSystem) SysBlockedOperation(eu.bcvsolutions.idm.acc.entity.SysBlockedOperation) ModuleDescriptorEvent(eu.bcvsolutions.idm.core.api.event.ModuleDescriptorEvent) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 9 with ModuleDescriptorDto

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

the class ModuleEnableProcessor method process.

@Override
public EventResult<ModuleDescriptorDto> process(EntityEvent<ModuleDescriptorDto> event) {
    ModuleDescriptorDto moduleDescriptor = event.getContent();
    // enable module
    String propertyName = moduleService.getModuleConfigurationProperty(moduleDescriptor.getId(), ConfigurationService.PROPERTY_ENABLED);
    configurationService.setBooleanValue(propertyName, true);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) ModuleDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ModuleDescriptorDto)

Example 10 with ModuleDescriptorDto

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

the class ModuleDisableProcessor method process.

@Override
public EventResult<ModuleDescriptorDto> process(EntityEvent<ModuleDescriptorDto> event) {
    ModuleDescriptorDto moduleDescriptor = event.getContent();
    String moduleId = moduleDescriptor.getId();
    // validation
    if (!moduleDescriptor.isDisableable()) {
        throw new ModuleNotDisableableException(moduleId);
    }
    // disable module
    String propertyName = moduleService.getModuleConfigurationProperty(moduleId, ConfigurationService.PROPERTY_ENABLED);
    configurationService.setBooleanValue(propertyName, false);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : ModuleNotDisableableException(eu.bcvsolutions.idm.core.exception.ModuleNotDisableableException) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) ModuleDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ModuleDescriptorDto)

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