Refactor hawkbit core and security (#2833)
* Refactor hawkbit core and security * improve access to the base core features - static * thus easiear access * and less boilerplate passing of instances Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com> * Refactor context classes * make JSON context serialization default * AccessContext * Split hawkbit-security-core to other modules and remove it --------- Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -106,7 +106,7 @@ public class HawkbitClient {
|
||||
template.header(AUTHORIZATION, "GatewayToken " + tenant.getGatewayToken());
|
||||
} else if (!ObjectUtils.isEmpty(controller.getSecurityToken())) {
|
||||
template.header(AUTHORIZATION, "TargetToken " + controller.getSecurityToken());
|
||||
} // else do not send authentication, no auth or certificate based
|
||||
} // else do not send auth, no auth or certificate based
|
||||
};
|
||||
// @formatter:on
|
||||
private static final ErrorDecoder DEFAULT_ERROR_DECODER_0 = new ErrorDecoder.Default();
|
||||
@@ -279,7 +279,7 @@ public class HawkbitClient {
|
||||
(controller == null ? hawkBitServer.getMgmtUrl() : hawkBitServer.getDdiUrl()) + path).openConnection();
|
||||
conn.setRequestMethod("POST");
|
||||
|
||||
// deal with authentication - only from headers1
|
||||
// deal with auth - only from headers1
|
||||
final RequestTemplate requestTemplate = new RequestTemplate();
|
||||
requestInterceptorFn.apply(tenant, controller).apply(requestTemplate);
|
||||
requestTemplate.headers().forEach((k, v) -> v.forEach(e -> conn.setRequestProperty(k, e)));
|
||||
|
||||
@@ -19,7 +19,7 @@ import org.eclipse.hawkbit.sdk.HawkbitClient;
|
||||
import org.eclipse.hawkbit.sdk.Tenant;
|
||||
|
||||
/**
|
||||
* An in-memory simulated DDI Tenant to hold the controller twins in
|
||||
* An in-memory simulated DDI AccessContext to hold the controller twins in
|
||||
* memory and be able to retrieve them again.
|
||||
*/
|
||||
public class DdiTenant {
|
||||
|
||||
@@ -32,17 +32,17 @@ import org.eclipse.hawkbit.sdk.ca.CA;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Helper for authentication setup
|
||||
* Helper for auth setup
|
||||
*/
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class AuthenticationSetupHelper {
|
||||
|
||||
private static final String AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY = "authentication.gatewaytoken.key";
|
||||
private static final String AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED = "authentication.gatewaytoken.enabled";
|
||||
private static final String AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED = "authentication.targettoken.enabled";
|
||||
private static final String AUTHENTICATION_MODE_HEADER_ENABLED = "authentication.header.enabled";
|
||||
private static final String AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME = "authentication.header.authority";
|
||||
private static final String AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY = "auth.gatewaytoken.key";
|
||||
private static final String AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED = "auth.gatewaytoken.enabled";
|
||||
private static final String AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED = "auth.targettoken.enabled";
|
||||
private static final String AUTHENTICATION_MODE_HEADER_ENABLED = "auth.header.enabled";
|
||||
private static final String AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME = "auth.header.authority";
|
||||
|
||||
private static final Random RND = new SecureRandom();
|
||||
|
||||
@@ -57,7 +57,7 @@ public class AuthenticationSetupHelper {
|
||||
return Base64.getEncoder().encodeToString(rnd);
|
||||
}
|
||||
|
||||
// sets up a certificate authentication, if DdiCA is null - generate self signed CA
|
||||
// sets up a certificate auth, if DdiCA is null - generate self signed CA
|
||||
public void setupCertificateAuthentication() throws CertificateException {
|
||||
final MgmtTenantManagementRestApi mgmtTenantManagementRestApi = hawkbitClient.mgmtService(MgmtTenantManagementRestApi.class, tenant);
|
||||
CA ddiCA = tenant.getDdiCA();
|
||||
@@ -80,7 +80,7 @@ public class AuthenticationSetupHelper {
|
||||
}
|
||||
}
|
||||
|
||||
// enables secure token authentication
|
||||
// enables secure token auth
|
||||
public void setupSecureTokenAuthentication() {
|
||||
final MgmtTenantManagementRestApi mgmtTenantManagementRestApi = hawkbitClient.mgmtService(MgmtTenantManagementRestApi.class, tenant);
|
||||
if (!(Boolean.TRUE.equals(Objects.requireNonNull(mgmtTenantManagementRestApi
|
||||
@@ -90,7 +90,7 @@ public class AuthenticationSetupHelper {
|
||||
}
|
||||
}
|
||||
|
||||
// set gateway token authentication (generate and sets gateway token to tenant, if not set up)
|
||||
// set gateway token auth (generate and sets gateway token to tenant, if not set up)
|
||||
// return the gateway token
|
||||
public void setupGatewayTokenAuthentication() {
|
||||
String gatewayToken = tenant.getGatewayToken();
|
||||
@@ -112,8 +112,8 @@ public class AuthenticationSetupHelper {
|
||||
}
|
||||
}
|
||||
|
||||
// if gateway token is configured then the gateway auth is enabled, so all devices use gateway token authentication.
|
||||
// otherwise, target token authentication is enabled - then all devices shall be registered and the target token shall be set to the one from
|
||||
// if gateway token is configured then the gateway auth is enabled, so all devices use gateway token auth.
|
||||
// otherwise, target token auth is enabled - then all devices shall be registered and the target token shall be set to the one from
|
||||
// the DDI controller instance
|
||||
public void setupTargetAuthentication() {
|
||||
final String gatewayToken = tenant.getGatewayToken();
|
||||
|
||||
Reference in New Issue
Block a user