Search in sources :

Example 6 with Password

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();
}
Also used : HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) KuraNotConnectedException(org.eclipse.kura.KuraNotConnectedException) KuraTimeoutException(org.eclipse.kura.KuraTimeoutException) KuraException(org.eclipse.kura.KuraException) KuraTooManyInflightMessagesException(org.eclipse.kura.KuraTooManyInflightMessagesException) KuraConnectException(org.eclipse.kura.KuraConnectException) MqttException(org.eclipse.paho.client.mqttv3.MqttException) MqttPersistenceException(org.eclipse.paho.client.mqttv3.MqttPersistenceException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Password(org.eclipse.kura.configuration.Password)

Example 7 with Password

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;
}
Also used : ComponentConfigurationImpl(org.eclipse.kura.core.configuration.ComponentConfigurationImpl) XmlComponentConfigurations(org.eclipse.kura.core.configuration.XmlComponentConfigurations) HashMap(java.util.HashMap) Password(org.eclipse.kura.configuration.Password)

Example 8 with Password

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;
}
Also used : KuraException(org.eclipse.kura.KuraException) XMLStreamException(javax.xml.stream.XMLStreamException) KuraPartialSuccessException(org.eclipse.kura.KuraPartialSuccessException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ComponentException(org.osgi.service.component.ComponentException) IOException(java.io.IOException) Password(org.eclipse.kura.configuration.Password)

Example 9 with Password

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;
}
Also used : IOException(java.io.IOException) Password(org.eclipse.kura.configuration.Password)

Example 10 with Password

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);
        }
    }
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) IOException(java.io.IOException) KuraException(org.eclipse.kura.KuraException) Password(org.eclipse.kura.configuration.Password)

Aggregations

Password (org.eclipse.kura.configuration.Password)20 KuraException (org.eclipse.kura.KuraException)12 HashMap (java.util.HashMap)9 IOException (java.io.IOException)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 KuraConnectException (org.eclipse.kura.KuraConnectException)3 KuraNotConnectedException (org.eclipse.kura.KuraNotConnectedException)3 KuraTimeoutException (org.eclipse.kura.KuraTimeoutException)3 KuraTooManyInflightMessagesException (org.eclipse.kura.KuraTooManyInflightMessagesException)3 CryptoService (org.eclipse.kura.crypto.CryptoService)3 FileNotFoundException (java.io.FileNotFoundException)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 ConfigurationService (org.eclipse.kura.configuration.ConfigurationService)2 WifiMode (org.eclipse.kura.net.wifi.WifiMode)2 GwtKuraException (org.eclipse.kura.web.shared.GwtKuraException)2 GwtConfigParameterType (org.eclipse.kura.web.shared.model.GwtConfigParameter.GwtConfigParameterType)2 MqttException (org.eclipse.paho.client.mqttv3.MqttException)2 MqttPersistenceException (org.eclipse.paho.client.mqttv3.MqttPersistenceException)2