Netty httpclientsecure class cannot be found

787 Views Asked by At

I am trying to authenticate to Azure Vault. I keep getting this error:

java.lang.NoClassDefFoundError: Could not initialize class reactor.netty.http.client.HttpClientSecure

Here is my code for azure Authentication:

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;
    }
}

I think it is due to a compatibility with dependency versions. I am using the versions as prescribed in the bom file of the official GitHub for azure SDK.

This is a part of my pom file

<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>

I have upgraded Spring to 2.4.0

0

There are 0 best solutions below