use of org.eclipse.kura.configuration.Password in project kura by eclipse.
the class MqttDataTransport method updated.
public void updated(Map<String, Object> properties) {
s_logger.info("Updating {}...", properties.get(ConfigurationService.KURA_SERVICE_PID));
this.m_properties.clear();
HashMap<String, Object> decryptedPropertiesMap = new HashMap<String, Object>();
for (Map.Entry<String, Object> entry : properties.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (key.equals(MQTT_PASSWORD_PROP_NAME)) {
try {
Password decryptedPassword = new Password(this.m_cryptoService.decryptAes(((String) value).toCharArray()));
decryptedPropertiesMap.put(key, decryptedPassword);
} catch (Exception e) {
s_logger.info("Password is not encrypted");
decryptedPropertiesMap.put(key, new Password((String) value));
}
} else {
decryptedPropertiesMap.put(key, value);
}
}
this.m_properties.putAll(decryptedPropertiesMap);
update();
}
use of org.eclipse.kura.configuration.Password in project kura by eclipse.
the class XmlUtilTest method getSampleXmlComponentConfigurationsObject.
private static XmlComponentConfigurations getSampleXmlComponentConfigurationsObject() {
Map<String, Object> sampleMap = new HashMap<String, Object>();
sampleMap.put("int", 1);
sampleMap.put("long", 2L);
sampleMap.put("string", "StringValue");
sampleMap.put("boolean", true);
sampleMap.put("double", 2.2d);
sampleMap.put("float", 2.3f);
sampleMap.put("char", 'a');
sampleMap.put("short", (short) 1);
sampleMap.put("byte", (byte) 90);
Password password = new Password("password".toCharArray());
// sampleMap.put("password", password);
ComponentConfigurationImpl componentConfigurationImpl = new ComponentConfigurationImpl();
componentConfigurationImpl.setPid("8236");
componentConfigurationImpl.setDefinition(getSampleTocdObject());
componentConfigurationImpl.setProperties(sampleMap);
XmlComponentConfigurations xmlComponentConfigurations = new XmlComponentConfigurations();
xmlComponentConfigurations.setConfigurations(new ArrayList<ComponentConfigurationImpl>(Arrays.asList(componentConfigurationImpl)));
return xmlComponentConfigurations;
}
use of org.eclipse.kura.configuration.Password in project kura by eclipse.
the class ConfigurationServiceImpl method decryptPasswords.
Map<String, Object> decryptPasswords(ComponentConfiguration config) {
Map<String, Object> configProperties = config.getConfigurationProperties();
for (Entry<String, Object> property : configProperties.entrySet()) {
if (property.getValue() instanceof Password) {
try {
Password decryptedPassword = new Password(this.m_cryptoService.decryptAes(property.getValue().toString().toCharArray()));
configProperties.put(property.getKey(), decryptedPassword);
} catch (Exception e) {
}
}
}
return configProperties;
}
use of org.eclipse.kura.configuration.Password in project kura by eclipse.
the class CommandCloudApp method execute.
@Override
public KuraCommandResponsePayload execute(KuraRequestPayload reqPayload) {
KuraCommandRequestPayload commandReq = new KuraCommandRequestPayload(reqPayload);
String receivedPassword = (String) commandReq.getMetric(EDC_PASSWORD_METRIC_NAME);
Password commandPassword = (Password) this.properties.get(COMMAND_PASSWORD_ID);
KuraCommandResponsePayload commandResp = new KuraCommandResponsePayload(KuraResponsePayload.RESPONSE_CODE_OK);
boolean isExecutionAllowed = verifyPasswords(commandPassword, receivedPassword);
if (isExecutionAllowed) {
String command = commandReq.getCommand();
if (command == null || command.trim().isEmpty()) {
s_logger.error("null command");
commandResp.setResponseCode(KuraResponsePayload.RESPONSE_CODE_BAD_REQUEST);
return commandResp;
}
String[] cmdarray = prepareCommandArray(commandReq, command);
String dir = getDefaultWorkDir();
String[] envp = getEnvironment(commandReq);
byte[] zipBytes = commandReq.getZipBytes();
if (zipBytes != null) {
try {
UnZip.unZipBytes(zipBytes, dir);
} catch (IOException e) {
s_logger.error("Error unzipping command zip bytes", e);
commandResp.setResponseCode(KuraResponsePayload.RESPONSE_CODE_ERROR);
commandResp.setException(e);
return commandResp;
}
}
Process proc = null;
try {
proc = createExecutionProcess(dir, cmdarray, envp);
} catch (Throwable t) {
s_logger.error("Error executing command {}", t);
commandResp.setResponseCode(KuraResponsePayload.RESPONSE_CODE_ERROR);
commandResp.setException(t);
return commandResp;
}
boolean runAsync = commandReq.isRunAsync() != null ? commandReq.isRunAsync() : false;
int timeout = getTimeout(commandReq);
ProcessMonitorThread pmt = new ProcessMonitorThread(proc, commandReq.getStdin(), timeout);
pmt.start();
if (!runAsync) {
try {
pmt.join();
prepareResponseNoTimeout(commandResp, pmt);
} catch (InterruptedException e) {
Thread.interrupted();
pmt.interrupt();
prepareTimeoutResponse(commandResp, pmt);
}
}
} else {
s_logger.error("Password required but not correct and/or missing");
commandResp.setResponseCode(KuraResponsePayload.RESPONSE_CODE_ERROR);
commandResp.setExceptionMessage("Password missing or not correct");
}
return commandResp;
}
use of org.eclipse.kura.configuration.Password in project kura by eclipse.
the class CommandCloudApp method updated.
public void updated(Map<String, Object> properties) {
s_logger.info("updated...: " + properties);
this.properties = new HashMap<String, Object>();
for (Map.Entry<String, Object> entry : properties.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (key.equals(COMMAND_PASSWORD_ID)) {
try {
Password decryptedPassword = new Password(this.m_cryptoService.decryptAes(value.toString().toCharArray()));
this.properties.put(key, decryptedPassword);
} catch (Exception e) {
this.properties.put(key, new Password((String) value));
}
} else {
this.properties.put(key, value);
}
}
boolean newStatus = (Boolean) properties.get(COMMAND_ENABLED_ID);
boolean stateChanged = this.currentStatus != newStatus;
if (stateChanged) {
this.currentStatus = newStatus;
if (!this.currentStatus && getCloudApplicationClient() != null) {
super.deactivate(this.compCtx);
}
if (this.currentStatus) {
super.activate(this.compCtx);
}
}
}
Aggregations