Search in sources :

Example 1 with SQLServerKeyVaultAuthenticationCallback

use of com.microsoft.sqlserver.jdbc.SQLServerKeyVaultAuthenticationCallback in project mssql-jdbc by microsoft.

the class FedauthWithAE method setupKeyStoreProvider_AKVOld.

private SQLServerColumnEncryptionKeyStoreProvider setupKeyStoreProvider_AKVOld() throws SQLServerException {
    ExecutorService service = Executors.newFixedThreadPool(2);
    SQLServerKeyVaultAuthenticationCallback authenticationCallback = new SQLServerKeyVaultAuthenticationCallback() {

        @Override
        public String getAccessToken(String authority, String resource, String scope) {
            AuthenticationResult result = null;
            try {
                AuthenticationContext context = new AuthenticationContext(authority, false, service);
                ClientCredential cred = new ClientCredential(applicationClientID, applicationKey);
                Future<AuthenticationResult> future = context.acquireToken(resource, cred, null);
                result = future.get();
                return result.getAccessToken();
            } catch (Exception e) {
                fail(e.getMessage());
                return null;
            }
        }
    };
    return new SQLServerColumnEncryptionAzureKeyVaultProvider(authenticationCallback);
}
Also used : ClientCredential(com.microsoft.aad.adal4j.ClientCredential) AuthenticationContext(com.microsoft.aad.adal4j.AuthenticationContext) ExecutorService(java.util.concurrent.ExecutorService) SQLServerKeyVaultAuthenticationCallback(com.microsoft.sqlserver.jdbc.SQLServerKeyVaultAuthenticationCallback) SQLException(java.sql.SQLException) SQLServerException(com.microsoft.sqlserver.jdbc.SQLServerException) SQLServerColumnEncryptionAzureKeyVaultProvider(com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider) AuthenticationResult(com.microsoft.aad.adal4j.AuthenticationResult)

Example 2 with SQLServerKeyVaultAuthenticationCallback

use of com.microsoft.sqlserver.jdbc.SQLServerKeyVaultAuthenticationCallback in project mssql-jdbc by Microsoft.

the class FedauthWithAE method setupKeyStoreProvider_AKVOld.

private SQLServerColumnEncryptionKeyStoreProvider setupKeyStoreProvider_AKVOld() throws SQLServerException {
    ExecutorService service = Executors.newFixedThreadPool(2);
    SQLServerKeyVaultAuthenticationCallback authenticationCallback = new SQLServerKeyVaultAuthenticationCallback() {

        @Override
        public String getAccessToken(String authority, String resource, String scope) {
            AuthenticationResult result = null;
            try {
                AuthenticationContext context = new AuthenticationContext(authority, false, service);
                ClientCredential cred = new ClientCredential(applicationClientID, applicationKey);
                Future<AuthenticationResult> future = context.acquireToken(resource, cred, null);
                result = future.get();
                return result.getAccessToken();
            } catch (Exception e) {
                fail(e.getMessage());
                return null;
            }
        }
    };
    return new SQLServerColumnEncryptionAzureKeyVaultProvider(authenticationCallback);
}
Also used : ClientCredential(com.microsoft.aad.adal4j.ClientCredential) AuthenticationContext(com.microsoft.aad.adal4j.AuthenticationContext) ExecutorService(java.util.concurrent.ExecutorService) SQLServerKeyVaultAuthenticationCallback(com.microsoft.sqlserver.jdbc.SQLServerKeyVaultAuthenticationCallback) SQLException(java.sql.SQLException) SQLServerException(com.microsoft.sqlserver.jdbc.SQLServerException) SQLServerColumnEncryptionAzureKeyVaultProvider(com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider) AuthenticationResult(com.microsoft.aad.adal4j.AuthenticationResult)

Aggregations

AuthenticationContext (com.microsoft.aad.adal4j.AuthenticationContext)2 AuthenticationResult (com.microsoft.aad.adal4j.AuthenticationResult)2 ClientCredential (com.microsoft.aad.adal4j.ClientCredential)2 SQLServerColumnEncryptionAzureKeyVaultProvider (com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider)2 SQLServerException (com.microsoft.sqlserver.jdbc.SQLServerException)2 SQLServerKeyVaultAuthenticationCallback (com.microsoft.sqlserver.jdbc.SQLServerKeyVaultAuthenticationCallback)2 SQLException (java.sql.SQLException)2 ExecutorService (java.util.concurrent.ExecutorService)2