我正在尝试对 Azure Vault 进行身份验证。我不断收到此错误:
java.lang.NoClassDefFoundError:无法初始化类 reactor.netty.http.client.HttpClientSecure
这是我的天蓝色身份验证代码:
public class AzureKeyVaultAuthenticator {
/**
* Do certificate based authentication using your PFX file.
*
* @param clientId
* Also known as applicationId which is received as a part of the app creation process.
* @param tenantId
* Also known as directoryId which is received as a part of the app creation process.
* @param pathPfx
* Path to your PFX certificate.
* @param pfxPassword
* Password to your PFX certificate, this can be empty if that's the value given when it was created.
*/
public TokenCredential getTokenCredential(String clientId, String tenantId, String pathPfx, String pfxPassword) {
TokenCredential credential = new ClientCertificateCredentialBuilder()
.clientId(clientId)
.tenantId(tenantId)
.pfxCertificate(pathPfx, pfxPassword)
.build();
return credential;
}
/**
* Find the vault you want to operate on by keyVaultName.
*
* @param credential
* Credential to authenticate a {@link KeyVaultManager} with.
* @param resourceGroupName
* The name of the resource group your Key Vault is a part of.
* @param vaultBaseUrl
* The URL that identifies your Key Vault.
* @return A {@link Vault} object representing your Key Vault.
*/
public Vault getVault(TokenCredential credential, String resourceGroupName, String vaultBaseUrl) {
AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
KeyVaultManager manager = KeyVaultManager.authenticate(credential, profile);
Optional<Vault> optional = manager
.vaults()
.listByResourceGroup(resourceGroupName)
.stream()
.filter(vault -> vaultBaseUrl.equals(vault.vaultUri()))
.findFirst();
if (optional.isPresent()) {
return optional.get();
}
return null;
}
}
我认为这是由于与依赖版本的兼容性。我正在使用官方 GitHub 的 bom 文件中规定的版本,用于 azure SDK。
这是我的 pom 文件的一部分
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-security-keyvault-administration</artifactId>
<version>4.0.3</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-security-keyvault-certificates</artifactId>
<version>4.2.3</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-security-keyvault-jca</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-security-keyvault-keys</artifactId>
<version>4.3.3</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-security-keyvault-secrets</artifactId>
<version>4.3.3</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-management</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager-resources</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager-keyvault</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-security-keyvault-keys</artifactId>
<version>4.3.2</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>msal4j</artifactId>
<version>1.11.0</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-security-keyvault-administration</artifactId>
<version>4.0.3</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.3.6</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
<version>1.20.0</version>
</dependency>
<!-- Reactor -->
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<version>3.4.9</version>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<version>3.4.9</version>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-tools</artifactId>
<version>3.4.9</version>
</dependency>
<dependency>
<groupId>io.projectreactor.addons</groupId>
<artifactId>reactor-extra</artifactId>
<version>3.4.4</version>
</dependency>
<dependency>
<groupId>io.projectreactor.addons</groupId>
<artifactId>reactor-adapter</artifactId>
<version>3.4.4</version>
</dependency>
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty</artifactId>
<version>1.0.10</version>
</dependency>
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty-core</artifactId>
<version>1.0.10</version>
</dependency>
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty-http</artifactId>
<version>1.0.10</version>
</dependency>
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty-http-brave</artifactId>
<version>1.0.10</version>
</dependency>
<dependency>
<groupId>io.projectreactor.addons</groupId>
<artifactId>reactor-pool</artifactId>
<version>0.2.6</version>
</dependency>
<dependency>
<groupId>io.projectreactor.kafka</groupId>
<artifactId>reactor-kafka</artifactId>
<version>1.3.5</version>
</dependency>
<dependency>
<groupId>io.projectreactor.rabbitmq</groupId>
<artifactId>reactor-rabbitmq</artifactId>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>io.projectreactor.kotlin</groupId>
<artifactId>reactor-kotlin-extensions</artifactId>
<version>1.1.4</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
<version>4.1.67.Final</version>
</dependency>
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId>
<version>8.20</version>
</dependency>
我已将 Spring 升级到 2.4.0