-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#1582] initial draft of CoAP support in Ditto gateway:
* provides (unsecure, plain UDP) CoAP endpoint * providing equivalent CoAP resources as the HTTP resources: * /things, /policies, /whoami * supporting verbs: GET, PUT, POST, DELETE, PATCH, IPATCH * providing "observe" functionality for watching changes of resources Signed-off-by: Thomas Jaeckle <ditto@jaeckles.de>
- Loading branch information
Showing
20 changed files
with
869 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...ice/src/main/java/org/eclipse/ditto/gateway/service/coap/DittoCoapDeviceInfoSupplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* tetms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.gateway.service.coap; | ||
|
||
import java.security.Principal; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.eclipse.californium.elements.auth.AdditionalInfo; | ||
import org.eclipse.californium.scandium.auth.ApplicationLevelInfoSupplier; | ||
import org.eclipse.ditto.base.model.auth.AuthorizationContext; | ||
import org.eclipse.ditto.base.model.headers.DittoHeaderDefinition; | ||
import org.eclipse.ditto.internal.utils.akka.logging.DittoLoggerFactory; | ||
import org.eclipse.ditto.internal.utils.akka.logging.ThreadSafeDittoLogger; | ||
|
||
/** | ||
* TODO TJ doc | ||
* TODO TJ use in scope of authenticating with PSK / Certificate | ||
*/ | ||
final class DittoCoapDeviceInfoSupplier implements ApplicationLevelInfoSupplier { | ||
|
||
private static final ThreadSafeDittoLogger LOGGER = | ||
DittoLoggerFactory.getThreadSafeLogger(DittoCoapDeviceInfoSupplier.class); | ||
|
||
/** | ||
* Creates additional information for authenticated devices. | ||
* | ||
* @param context the {@link AuthorizationContext} of the authenticated device. | ||
* @return additional device information. | ||
*/ | ||
public static AdditionalInfo createDeviceInfo(final AuthorizationContext context) { | ||
final Map<String, Object> result = new HashMap<>(); | ||
result.put(DittoHeaderDefinition.AUTHORIZATION_CONTEXT.getKey(), context); | ||
return AdditionalInfo.from(result); | ||
} | ||
|
||
@Override | ||
public AdditionalInfo getInfo(final Principal principal, final Object customArgument) { | ||
if (customArgument instanceof AdditionalInfo additionalInfo) { | ||
final AuthorizationContext authorizationContext = | ||
additionalInfo.get(DittoHeaderDefinition.AUTHORIZATION_CONTEXT.getKey(), AuthorizationContext.class); | ||
LOGGER.info("get AdditionalInfo auth context: {} - for principal: {}", authorizationContext, principal); | ||
return additionalInfo; | ||
} | ||
LOGGER.debug("did not get additional info"); | ||
return AdditionalInfo.empty(); | ||
} | ||
} |
Oops, something went wrong.