看來我靠近有一些工作定義這個類:
class WindowsStoreCertificateCredentials(clientId: String, certificate: X509Certificate, privateKey: PrivateKey) extends KeyVaultCredentials {
def getAuthResult(authority: String, resource: String): AuthenticationResult = {
val service = Executors.newFixedThreadPool(1)
val context = new AuthenticationContext(authority, false, service)
val certificateCredentials = AsymmetricKeyCredential.create(clientId, privateKey, certificate)
val authResultFuture = context.acquireToken(resource, certificateCredentials, null)
authResultFuture.get
}
override def doAuthenticate (authority: String, resource: String, scope: String): String = {
getAuthResult(authority, resource).getAccessToken
}
}
,並試圖用它獲得使用java.security.KeyStore中的證書X509Certificate對象和私鑰後:
val client = new KeyVaultClient(new WindowsStoreCertificateCredentials(
id, privateKey, certificate,))
val test = client.getSecret("https:/...")
不幸的是,引發一個異常:
sun.security.mscapi.RSAPrivateKey cannot be cast to java.security.interfaces.RSAPrivateKey java.lang.ClassCastException: sun.security.mscapi.RSAPrivateKey cannot be cast to java.security.interfaces.RSAPrivateKey
我在GitHub上AzureAD打開一個問題/蔚的ActiveDirectory庫換java和建議pull請求解決它,未完待續......
編輯:這是現在固定在AzureAD的版本1.2.0/azure-activedirectory-library-for-java。
它看起來像我不能使用這個構造函數,因爲我沒有後面的Azure應用程序。要特別指向Azure文檔:我正在嘗試執行與https://docs.microsoft.com/zh-CN/azure/key-vault/key-vault-use-from-web-application中的相同的第「使用證書進行身份驗證而不是客戶端祕密「。 – CanardMoussant