Search in sources :

Example 1 with SessionMsgType

use of org.thingsboard.server.common.msg.session.SessionMsgType in project thingsboard by thingsboard.

the class CoapTransportResource method processAccessTokenRequest.

private void processAccessTokenRequest(CoapExchange exchange, SessionMsgType type, Request request) {
    Optional<DeviceTokenCredentials> credentials = decodeCredentials(request);
    if (credentials.isEmpty()) {
        exchange.respond(CoAP.ResponseCode.UNAUTHORIZED);
        return;
    }
    transportService.process(DeviceTransportType.COAP, TransportProtos.ValidateDeviceTokenRequestMsg.newBuilder().setToken(credentials.get().getCredentialsId()).build(), new CoapDeviceAuthCallback(exchange, (deviceCredentials, deviceProfile) -> processRequest(exchange, type, request, deviceCredentials, deviceProfile)));
}
Also used : JsonParseException(com.google.gson.JsonParseException) CoapExchange(org.eclipse.californium.core.server.resources.CoapExchange) Response(org.eclipse.californium.core.coap.Response) FeatureType(org.thingsboard.server.common.msg.session.FeatureType) TbCoapDtlsSessionInfo(org.thingsboard.server.coapserver.TbCoapDtlsSessionInfo) Exchange(org.eclipse.californium.core.network.Exchange) TransportServiceCallback(org.thingsboard.server.common.transport.TransportServiceCallback) CoapDeviceAuthCallback(org.thingsboard.server.transport.coap.callback.CoapDeviceAuthCallback) TransportPayloadType(org.thingsboard.server.common.data.TransportPayloadType) CoapNoOpCallback(org.thingsboard.server.transport.coap.callback.CoapNoOpCallback) Random(java.util.Random) ConcurrentMap(java.util.concurrent.ConcurrentMap) SessionMsgType(org.thingsboard.server.common.msg.session.SessionMsgType) ObserveRelation(org.eclipse.californium.core.observe.ObserveRelation) Resource(org.eclipse.californium.core.server.resources.Resource) DeviceTokenCredentials(org.thingsboard.server.common.data.security.DeviceTokenCredentials) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DeviceTransportType(org.thingsboard.server.common.data.DeviceTransportType) JsonConverter(org.thingsboard.server.common.transport.adaptor.JsonConverter) GetAttributesSyncSessionCallback(org.thingsboard.server.transport.coap.callback.GetAttributesSyncSessionCallback) CoapServerService(org.thingsboard.server.coapserver.CoapServerService) ToServerRpcSyncSessionCallback(org.thingsboard.server.transport.coap.callback.ToServerRpcSyncSessionCallback) CoapClientContext(org.thingsboard.server.transport.coap.client.CoapClientContext) TbCoapClientState(org.thingsboard.server.transport.coap.client.TbCoapClientState) CoapOkCallback(org.thingsboard.server.transport.coap.callback.CoapOkCallback) DataConstants(org.thingsboard.server.common.data.DataConstants) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) ResourceObserver(org.eclipse.californium.core.server.resources.ResourceObserver) UUID(java.util.UUID) InetSocketAddress(java.net.InetSocketAddress) TimeUnit(java.util.concurrent.TimeUnit) Slf4j(lombok.extern.slf4j.Slf4j) AdaptorException(org.thingsboard.server.common.transport.adaptor.AdaptorException) List(java.util.List) Request(org.eclipse.californium.core.coap.Request) CoAP(org.eclipse.californium.core.coap.CoAP) KEY_SESSION_ID(org.eclipse.californium.elements.DtlsEndpointContext.KEY_SESSION_ID) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos) Optional(java.util.Optional) ValidateDeviceCredentialsResponse(org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse) DeviceTokenCredentials(org.thingsboard.server.common.data.security.DeviceTokenCredentials) CoapDeviceAuthCallback(org.thingsboard.server.transport.coap.callback.CoapDeviceAuthCallback)

Example 2 with SessionMsgType

use of org.thingsboard.server.common.msg.session.SessionMsgType in project thingsboard by thingsboard.

the class CoapTransportResource method processExchangeGetRequest.

private void processExchangeGetRequest(CoapExchange exchange, FeatureType featureType) {
    boolean unsubscribe = exchange.getRequestOptions().getObserve() == 1;
    SessionMsgType sessionMsgType;
    if (featureType == FeatureType.RPC) {
        sessionMsgType = unsubscribe ? SessionMsgType.UNSUBSCRIBE_RPC_COMMANDS_REQUEST : SessionMsgType.SUBSCRIBE_RPC_COMMANDS_REQUEST;
    } else {
        sessionMsgType = unsubscribe ? SessionMsgType.UNSUBSCRIBE_ATTRIBUTES_REQUEST : SessionMsgType.SUBSCRIBE_ATTRIBUTES_REQUEST;
    }
    processRequest(exchange, sessionMsgType);
}
Also used : SessionMsgType(org.thingsboard.server.common.msg.session.SessionMsgType)

Aggregations

SessionMsgType (org.thingsboard.server.common.msg.session.SessionMsgType)2 JsonParseException (com.google.gson.JsonParseException)1 InetSocketAddress (java.net.InetSocketAddress)1 List (java.util.List)1 Optional (java.util.Optional)1 Random (java.util.Random)1 UUID (java.util.UUID)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Slf4j (lombok.extern.slf4j.Slf4j)1 CoAP (org.eclipse.californium.core.coap.CoAP)1 Request (org.eclipse.californium.core.coap.Request)1 Response (org.eclipse.californium.core.coap.Response)1 Exchange (org.eclipse.californium.core.network.Exchange)1 ObserveRelation (org.eclipse.californium.core.observe.ObserveRelation)1 CoapExchange (org.eclipse.californium.core.server.resources.CoapExchange)1 Resource (org.eclipse.californium.core.server.resources.Resource)1 ResourceObserver (org.eclipse.californium.core.server.resources.ResourceObserver)1 KEY_SESSION_ID (org.eclipse.californium.elements.DtlsEndpointContext.KEY_SESSION_ID)1