Search in sources :

Example 1 with IdmConfigurationDto

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

the class DefaultConfigurationService method getAllPublicConfigurations.

/**
 * Returns all public configuration properties
 *
 * @return
 */
@Override
@Transactional(readOnly = true)
public List<IdmConfigurationDto> getAllPublicConfigurations() {
    Map<String, Object> configurations = new HashMap<>();
    // defaults from property file
    Map<String, Object> map = getAllProperties(env);
    for (Entry<String, Object> entry : map.entrySet()) {
        String key = entry.getKey();
        if (key.startsWith(IDM_PUBLIC_PROPERTY_PREFIX)) {
            configurations.put(key, entry.getValue());
        }
    }
    // override from database
    repository.findAllBySecuredIsFalse().forEach(idmConfiguration -> {
        configurations.put(idmConfiguration.getName(), idmConfiguration.getValue());
    });
    List<IdmConfigurationDto> results = new ArrayList<>();
    configurations.forEach((k, v) -> {
        results.add(toConfigurationDto(k, v));
    });
    return results;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IdmConfigurationDto(eu.bcvsolutions.idm.core.api.dto.IdmConfigurationDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with IdmConfigurationDto

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

the class DefaultConfigurationService method deleteValue.

@Override
@Transactional
public String deleteValue(String key) {
    IdmConfigurationDto dto = getByCode(key);
    if (dto == null) {
        return null;
    }
    delete(dto);
    return dto.getValue();
}
Also used : IdmConfigurationDto(eu.bcvsolutions.idm.core.api.dto.IdmConfigurationDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with IdmConfigurationDto

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

the class DefaultConfigurationService method saveConfiguration.

@Override
@Transactional
public void saveConfiguration(IdmConfigurationDto configuration) {
    Assert.notNull(configuration);
    Assert.hasText(configuration.getName());
    // only maps dto to entity
    IdmConfigurationDto configurationEntity = getByCode(configuration.getName());
    if (configurationEntity == null) {
        configurationEntity = new IdmConfigurationDto(configuration.getName(), configuration.getValue(), configuration.isSecured(), configuration.isConfidential());
    } else {
        configurationEntity.setValue(configuration.getValue());
        configurationEntity.setSecured(configuration.isSecured());
        configurationEntity.setConfidential(configuration.isConfidential());
    }
    save(configurationEntity);
}
Also used : IdmConfigurationDto(eu.bcvsolutions.idm.core.api.dto.IdmConfigurationDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with IdmConfigurationDto

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

the class DefaultConfigurationService method getValue.

@Override
@Transactional(readOnly = true)
public String getValue(String key, String defaultValue) {
    ValueWrapper cachedValue = getCachedValue(key);
    if (cachedValue != null) {
        String value = (String) cachedValue.get();
        return value != null ? value : defaultValue;
    }
    // 
    LOG.debug("Reading configuration for key [{}]", key);
    String value = null;
    boolean confidential = true;
    // idm configuration has higher priority than property file
    IdmConfigurationDto config = getByCode(key);
    if (config != null) {
        if (config.isConfidential()) {
            value = confidentialStorage.get(config.getId(), getEntityClass(), CONFIDENTIAL_PROPERTY_VALUE, String.class);
            LOG.debug("Configuration value for key [{}] was found in confidential storage", config.getName());
        } else {
            value = config.getValue();
            confidential = false;
            LOG.trace("Configuration value for key [{}] was found in database.", key);
        }
    } else if (env != null) {
        // try to find value in property configuration
        value = env.getProperty(key);
        confidential = shouldBeConfidential(key);
    }
    // fill default value
    if (value == null) {
        value = defaultValue;
    }
    LOG.debug("Resolved configuration value for key [{}] is [{}].", key, confidential ? GuardedString.SECRED_PROXY_STRING : value);
    setCachedValue(key, value);
    return value;
}
Also used : ValueWrapper(org.springframework.cache.Cache.ValueWrapper) IdmConfigurationDto(eu.bcvsolutions.idm.core.api.dto.IdmConfigurationDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with IdmConfigurationDto

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

the class PreserveUuidIntegrationTest method testIsNewWithoutId.

@Test
public void testIsNewWithoutId() {
    IdmConfigurationDto configuration = new IdmConfigurationDto();
    configuration.setName("test-property-one");
    configuration.setValue("one");
    // 
    assertTrue(configurationService.isNew(configuration));
}
Also used : IdmConfigurationDto(eu.bcvsolutions.idm.core.api.dto.IdmConfigurationDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmConfigurationDto (eu.bcvsolutions.idm.core.api.dto.IdmConfigurationDto)16 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)9 Test (org.junit.Test)9 Transactional (org.springframework.transaction.annotation.Transactional)8 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)5 IdmAuthorizationPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto)2 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)2 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)2 IdmConfiguration (eu.bcvsolutions.idm.core.model.entity.IdmConfiguration)2 LoginDto (eu.bcvsolutions.idm.core.security.api.dto.LoginDto)2 UUID (java.util.UUID)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ValueWrapper (org.springframework.cache.Cache.ValueWrapper)1