-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(SSI): implements the MIW client with Oauth2 as token provider fo…
…r using the MIW APIs (#489)
- Loading branch information
Showing
30 changed files
with
1,191 additions
and
228 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
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
76 changes: 76 additions & 0 deletions
76
...lient/src/main/java/org/eclipse/tractusx/edc/iam/ssi/miw/SsiMiwOauth2ClientExtension.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,76 @@ | ||
/* | ||
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* 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 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.tractusx.edc.iam.ssi.miw; | ||
|
||
import org.eclipse.edc.iam.oauth2.spi.client.Oauth2Client; | ||
import org.eclipse.edc.runtime.metamodel.annotation.Extension; | ||
import org.eclipse.edc.runtime.metamodel.annotation.Inject; | ||
import org.eclipse.edc.runtime.metamodel.annotation.Provider; | ||
import org.eclipse.edc.runtime.metamodel.annotation.Setting; | ||
import org.eclipse.edc.spi.security.Vault; | ||
import org.eclipse.edc.spi.system.ServiceExtension; | ||
import org.eclipse.edc.spi.system.ServiceExtensionContext; | ||
import org.eclipse.tractusx.edc.iam.ssi.miw.oauth2.MiwOauth2Client; | ||
import org.eclipse.tractusx.edc.iam.ssi.miw.oauth2.MiwOauth2ClientConfiguration; | ||
import org.eclipse.tractusx.edc.iam.ssi.miw.oauth2.MiwOauth2ClientImpl; | ||
|
||
import java.util.Objects; | ||
|
||
|
||
@Extension(SsiMiwOauth2ClientExtension.EXTENSION_NAME) | ||
public class SsiMiwOauth2ClientExtension implements ServiceExtension { | ||
|
||
public static final String EXTENSION_NAME = "SSI MIW OAuth2 Client"; | ||
|
||
@Setting(value = "OAuth2 endpoint for requesting a token") | ||
public static final String TOKEN_URL = "tx.ssi.oauth.token.url"; | ||
|
||
|
||
@Setting(value = "OAuth2 client id") | ||
public static final String CLIENT_ID = "tx.ssi.oauth.client.id"; | ||
|
||
@Setting(value = "Vault alias of OAuth2 client secret") | ||
public static final String CLIENT_SECRET_ALIAS = "tx.ssi.oauth.client.secret.alias"; | ||
|
||
@Inject | ||
private Oauth2Client oauth2Client; | ||
|
||
@Inject | ||
private Vault vault; | ||
|
||
@Override | ||
public String name() { | ||
return EXTENSION_NAME; | ||
} | ||
|
||
@Provider | ||
public MiwOauth2Client oauth2Client(ServiceExtensionContext context) { | ||
return new MiwOauth2ClientImpl(oauth2Client, createConfiguration(context)); | ||
} | ||
|
||
private MiwOauth2ClientConfiguration createConfiguration(ServiceExtensionContext context) { | ||
var tokenUrl = context.getConfig().getString(TOKEN_URL); | ||
var clientId = context.getConfig().getString(CLIENT_ID); | ||
var clientSecretAlias = context.getConfig().getString(CLIENT_SECRET_ALIAS); | ||
var clientSecret = vault.resolveSecret(clientSecretAlias); | ||
Objects.requireNonNull(clientSecret, "Client secret not found in the vault"); | ||
|
||
return MiwOauth2ClientConfiguration.Builder.newInstance() | ||
.tokenUrl(tokenUrl) | ||
.clientId(clientId) | ||
.clientSecret(clientSecret) | ||
.build(); | ||
} | ||
} |
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
Oops, something went wrong.