Skip to content

Commit

Permalink
temporarily made DIM and TokenRefresh config optional
Browse files Browse the repository at this point in the history
  • Loading branch information
paullatzelsperger committed Mar 20, 2024
1 parent 7bae34b commit 864859c
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 8 deletions.
1 change: 1 addition & 0 deletions core/core-utils/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ plugins {
}

dependencies {
implementation(libs.edc.spi.core)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft
*
* 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
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

package org.eclipse.tractusx.edc.core.utils;

import org.eclipse.edc.spi.monitor.Monitor;

public class RequiredConfigWarnings {

public static void warningNotPresent(Monitor monitor, String missingConfig) {
monitor.severe("Mandatory config value missing: '%s'. This runtime will not be fully operational! Starting with v0.7.x this will be a runtime error.".formatted(missingConfig));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.spi.types.TypeManager;
import org.eclipse.tractusx.edc.core.utils.PathUtils;
import org.eclipse.tractusx.edc.iam.iatp.sts.dim.oauth.DimOauth2Client;

import static org.eclipse.tractusx.edc.core.utils.PathUtils.removeTrailingSlash;
import static java.util.Optional.ofNullable;
import static org.eclipse.tractusx.edc.core.utils.RequiredConfigWarnings.warningNotPresent;

@Extension(DimSecureTokenServiceExtension.NAME)
public class DimSecureTokenServiceExtension implements ServiceExtension {
Expand All @@ -55,14 +57,22 @@ public class DimSecureTokenServiceExtension implements ServiceExtension {
@Inject
private TypeManager typeManager;


@Override
public String name() {
return NAME;
}

@Provider
public SecureTokenService secureTokenService(ServiceExtensionContext context) {
return new DimSecureTokenService(httpClient, removeTrailingSlash(context.getConfig().getString(DIM_URL)), dimOauth2Client, typeManager.getMapper(), monitor);
}
var dimUrl = ofNullable(context.getConfig().getString(DIM_URL, null))
.map(PathUtils::removeTrailingSlash)
.orElse(null);

if (dimUrl == null) {
warningNotPresent(context.getMonitor().withPrefix("STS Client for DIM"), DIM_URL);
}

return new DimSecureTokenService(httpClient, dimUrl, dimOauth2Client, typeManager.getMapper(), monitor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import org.eclipse.edc.runtime.metamodel.annotation.Setting;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.tractusx.edc.core.utils.PathUtils;

import static org.eclipse.tractusx.edc.core.utils.PathUtils.removeTrailingSlash;
import static java.util.Optional.ofNullable;
import static org.eclipse.tractusx.edc.core.utils.RequiredConfigWarnings.warningNotPresent;

/**
* Configuration Extension for the STS OAuth2 client
Expand All @@ -44,6 +46,7 @@ public class DimStsConfigurationExtension implements ServiceExtension {

protected static final String NAME = "DIM STS client configuration extension";


@Override
public String name() {
return NAME;
Expand All @@ -52,9 +55,21 @@ public String name() {
@Provider
public StsRemoteClientConfiguration clientConfiguration(ServiceExtensionContext context) {

var tokenUrl = removeTrailingSlash(context.getConfig().getString(TOKEN_URL));
var clientId = context.getConfig().getString(CLIENT_ID);
var clientSecretAlias = context.getConfig().getString(CLIENT_SECRET_ALIAS);
var tokenUrl = ofNullable(context.getConfig().getString(TOKEN_URL, null))
.map(PathUtils::removeTrailingSlash).orElse(null);
var clientId = context.getConfig().getString(CLIENT_ID, null);
var clientSecretAlias = context.getConfig().getString(CLIENT_SECRET_ALIAS, null);

var monitor = context.getMonitor().withPrefix("STS Client for DIM");
if (tokenUrl == null) {
warningNotPresent(monitor, TOKEN_URL);
}
if (clientId == null) {
warningNotPresent(monitor, CLIENT_ID);
}
if (clientSecretAlias == null) {
warningNotPresent(monitor, CLIENT_SECRET_ALIAS);
}

return new StsRemoteClientConfiguration(tokenUrl, clientId, clientSecretAlias);
}
Expand Down
1 change: 1 addition & 0 deletions edc-extensions/tokenrefresh-handler/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ plugins {
}

dependencies {
implementation(project(":core:core-utils"))
implementation(project(":spi:core-spi"))
implementation(project(":spi:tokenrefresh-spi"))
implementation(libs.edc.spi.core)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.spi.types.TypeManager;
import org.eclipse.tractusx.edc.core.utils.RequiredConfigWarnings;
import org.eclipse.tractusx.edc.spi.tokenrefresh.common.TokenRefreshHandler;

import static org.eclipse.tractusx.edc.common.tokenrefresh.TokenRefreshHandlerExtension.NAME;
Expand Down Expand Up @@ -58,6 +59,10 @@ public TokenRefreshHandler createTokenRefreshHander(ServiceExtensionContext cont
}

private String getOwnDid(ServiceExtensionContext context) {
return context.getConfig().getString(PARTICIPANT_DID_PROPERTY);
var did = context.getConfig().getString(PARTICIPANT_DID_PROPERTY, null);
if (did == null) {
RequiredConfigWarnings.warningNotPresent(context.getMonitor().withPrefix("Token Refresh Handler"), PARTICIPANT_DID_PROPERTY);
}
return did;
}
}

0 comments on commit 864859c

Please sign in to comment.