Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ public String getValue() {
}
}

/**
* Returns the value as stored in the database, without decrypting it.
*/
public String getRawValue() {
return value;
}

public void setValue(String value) {
if(isEncrypted()) {
this.value = DBEncryptionUtil.encrypt(value);
Expand Down
5 changes: 4 additions & 1 deletion server/src/main/java/com/cloud/api/ApiResponseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
import org.apache.cloudstack.framework.jobs.AsyncJob;
import org.apache.cloudstack.framework.jobs.AsyncJobManager;
import org.apache.cloudstack.framework.jobs.dao.AsyncJobDao;
Expand Down Expand Up @@ -686,7 +687,9 @@ public ConfigurationResponse createConfigurationResponse(Configuration cfg) {
cfgResponse.setSubGroup(configGroupAndSubGroup.second());
cfgResponse.setDescription(cfg.getDescription());
cfgResponse.setName(cfg.getName());
if (cfg.isEncrypted()) {
if (cfg instanceof ConfigurationVO && cfg.isEncrypted()) {
cfgResponse.setValue(((ConfigurationVO) cfg).getRawValue());
} else if (cfg.isEncrypted()) {
cfgResponse.setValue(DBEncryptionUtil.encrypt(cfg.getValue()));
} else {
cfgResponse.setValue(cfg.getValue());
Expand Down
18 changes: 18 additions & 0 deletions server/src/test/java/com/cloud/api/ApiResponseHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.apache.cloudstack.api.ResponseObject;
import org.apache.cloudstack.api.response.AutoScaleVmGroupResponse;
import org.apache.cloudstack.api.response.AutoScaleVmProfileResponse;
import org.apache.cloudstack.api.response.ConfigurationResponse;
import org.apache.cloudstack.api.response.ConsoleSessionResponse;
import org.apache.cloudstack.api.response.DirectDownloadCertificateResponse;
import org.apache.cloudstack.api.response.GuestOSCategoryResponse;
Expand All @@ -57,10 +58,12 @@
import org.apache.cloudstack.api.response.UsageRecordResponse;
import org.apache.cloudstack.api.response.TrafficTypeResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
import org.apache.cloudstack.usage.UsageService;
import org.apache.cloudstack.vm.UnmanagedInstanceTO;

import com.cloud.capacity.Capacity;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.configuration.Resource;
import com.cloud.domain.DomainVO;
import com.cloud.host.HostVO;
Expand Down Expand Up @@ -93,6 +96,7 @@
import com.cloud.user.UserDataVO;
import com.cloud.user.UserVO;
import com.cloud.user.dao.UserDataDao;
import com.cloud.utils.Pair;
import com.cloud.utils.net.Ip;
import com.cloud.vm.ConsoleSessionVO;
import com.cloud.vm.NicSecondaryIp;
Expand Down Expand Up @@ -137,6 +141,9 @@ public class ApiResponseHelperTest {
@Mock
ResourceIconManager resourceIconManager;

@Mock
ConfigurationManager configurationManagerMock;

@Mock
private ConsoleSessionVO consoleSessionMock;
@Mock
Expand Down Expand Up @@ -800,4 +807,15 @@ public void createConsoleSessionResponseTestShouldReturnFullResponse() {
Assert.assertEquals(expected.getVmName(), response.getVmName());
}
}

@Test
public void testCreateConfigurationResponseSecureValueIsReturnedAsStored() {
ConfigurationVO cfg = new ConfigurationVO("Secure", "DEFAULT", "test", "test.secure.setting", null, "test");
ReflectionTestUtils.setField(cfg, "value", "storedEncryptedValue");
Mockito.when(configurationManagerMock.getConfigurationGroupAndSubGroup(cfg.getName())).thenReturn(new Pair<>("Miscellaneous", "Others"));

ConfigurationResponse response = apiResponseHelper.createConfigurationResponse(cfg);

assertEquals("storedEncryptedValue", response.getValue());
}
}
Loading