Search in sources :

Example 36 with DeviceCredentials

use of org.thingsboard.server.common.data.security.DeviceCredentials in project thingsboard by thingsboard.

the class BaseDeviceControllerTest method testSaveDeviceCredentialsWithEmptyDevice.

@Test
public void testSaveDeviceCredentialsWithEmptyDevice() throws Exception {
    DeviceCredentials deviceCredentials = new DeviceCredentials();
    doPost("/api/device/credentials", deviceCredentials).andExpect(status().isBadRequest());
}
Also used : DeviceCredentials(org.thingsboard.server.common.data.security.DeviceCredentials) Test(org.junit.Test)

Example 37 with DeviceCredentials

use of org.thingsboard.server.common.data.security.DeviceCredentials in project thingsboard by thingsboard.

the class DefaultDeviceAuthService method process.

@Override
public DeviceAuthResult process(DeviceCredentialsFilter credentialsFilter) {
    log.trace("Lookup device credentials using filter {}", credentialsFilter);
    DeviceCredentials credentials = deviceCredentialsService.findDeviceCredentialsByCredentialsId(credentialsFilter.getCredentialsId());
    if (credentials != null) {
        log.trace("Credentials found {}", credentials);
        if (credentials.getCredentialsType() == credentialsFilter.getCredentialsType()) {
            switch(credentials.getCredentialsType()) {
                case ACCESS_TOKEN:
                    // primitive case;
                    return DeviceAuthResult.of(credentials.getDeviceId());
                case X509_CERTIFICATE:
                    return DeviceAuthResult.of(credentials.getDeviceId());
                default:
                    return DeviceAuthResult.of("Credentials Type is not supported yet!");
            }
        } else {
            return DeviceAuthResult.of("Credentials Type mismatch!");
        }
    } else {
        log.trace("Credentials not found!");
        return DeviceAuthResult.of("Credentials Not Found!");
    }
}
Also used : DeviceCredentials(org.thingsboard.server.common.data.security.DeviceCredentials)

Example 38 with DeviceCredentials

use of org.thingsboard.server.common.data.security.DeviceCredentials in project thingsboard by thingsboard.

the class AbstractMqttServerSideRpcIntegrationTest method testServerMqttOneWayRpcDeviceOffline.

@Test
public void testServerMqttOneWayRpcDeviceOffline() throws Exception {
    Device device = new Device();
    device.setName("Test One-Way Server-Side RPC Device Offline");
    device.setType("default");
    Device savedDevice = getSavedDevice(device);
    DeviceCredentials deviceCredentials = getDeviceCredentials(savedDevice);
    assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
    String accessToken = deviceCredentials.getCredentialsId();
    assertNotNull(accessToken);
    String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"23\",\"value\": 1}}";
    String deviceId = savedDevice.getId().getId().toString();
    doPostAsync("/api/plugins/rpc/oneway/" + deviceId, setGpioRequest, String.class, status().isRequestTimeout(), asyncContextTimeoutToUseRpcPlugin);
}
Also used : Device(org.thingsboard.server.common.data.Device) DeviceCredentials(org.thingsboard.server.common.data.security.DeviceCredentials) AbstractControllerTest(org.thingsboard.server.controller.AbstractControllerTest)

Example 39 with DeviceCredentials

use of org.thingsboard.server.common.data.security.DeviceCredentials in project thingsboard by thingsboard.

the class AbstractMqttTelemetryIntegrationTest method beforeTest.

@Before
public void beforeTest() throws Exception {
    loginTenantAdmin();
    Device device = new Device();
    device.setName("Test device");
    device.setType("default");
    savedDevice = doPost("/api/device", device, Device.class);
    DeviceCredentials deviceCredentials = doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
    assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
    accessToken = deviceCredentials.getCredentialsId();
    assertNotNull(accessToken);
}
Also used : Device(org.thingsboard.server.common.data.Device) DeviceCredentials(org.thingsboard.server.common.data.security.DeviceCredentials) Before(org.junit.Before)

Aggregations

DeviceCredentials (org.thingsboard.server.common.data.security.DeviceCredentials)39 Test (org.junit.Test)21 Device (org.thingsboard.server.common.data.Device)18 DeviceId (org.thingsboard.server.common.data.id.DeviceId)7 DeviceCredentialsId (org.thingsboard.server.common.data.id.DeviceCredentialsId)6 AbstractControllerTest (org.thingsboard.server.controller.AbstractControllerTest)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)2 Before (org.junit.Before)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 AbstractJpaDaoTest (org.thingsboard.server.dao.AbstractJpaDaoTest)2 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)2 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 UUID (java.util.UUID)1 Cache (org.springframework.cache.Cache)1 CacheEvict (org.springframework.cache.annotation.CacheEvict)1 AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)1 DeviceCredentialsService (org.thingsboard.server.dao.device.DeviceCredentialsService)1