Search in sources :

Example 1 with KMSClient

use of org.apache.ranger.services.kms.client.KMSClient in project ranger by apache.

the class KMSClient method testConnection.

public static Map<String, Object> testConnection(String serviceName, Map<String, String> configs) {
    List<String> strList = new ArrayList<String>();
    String errMsg = errMessage;
    boolean connectivityStatus = false;
    Map<String, Object> responseData = new HashMap<String, Object>();
    KMSClient kmsClient = getKmsClient(serviceName, configs);
    strList = getKmsKey(kmsClient, "", null);
    if (strList != null) {
        connectivityStatus = true;
    }
    if (connectivityStatus) {
        String successMsg = "TestConnection Successful";
        BaseClient.generateResponseDataMap(connectivityStatus, successMsg, successMsg, null, null, responseData);
    } else {
        String failureMsg = "Unable to retrieve any Kms Key using given URL.";
        BaseClient.generateResponseDataMap(connectivityStatus, failureMsg, failureMsg + errMsg, null, null, responseData);
    }
    return responseData;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KMSClient(org.apache.ranger.services.kms.client.KMSClient)

Example 2 with KMSClient

use of org.apache.ranger.services.kms.client.KMSClient in project ranger by apache.

the class KMSClient method getKmsClient.

public static KMSClient getKmsClient(String serviceName, Map<String, String> configs) {
    KMSClient kmsClient = null;
    if (LOG.isDebugEnabled()) {
        LOG.debug("Getting KmsClient for datasource: " + serviceName);
        LOG.debug("configMap: " + configs);
    }
    String errMsg = errMessage;
    if (configs == null || configs.isEmpty()) {
        String msgDesc = "Could not connect as Connection ConfigMap is empty.";
        LOG.error(msgDesc);
        HadoopException hdpException = new HadoopException(msgDesc);
        hdpException.generateResponseDataMap(false, msgDesc, msgDesc + errMsg, null, null);
        throw hdpException;
    } else {
        String kmsUrl = configs.get("provider");
        String kmsUserName = configs.get("username");
        String kmsPassWord = configs.get("password");
        String rangerPrincipal = configs.get("rangerprincipal");
        String rangerKeytab = configs.get("rangerkeytab");
        String nameRules = configs.get("namerules");
        String authType = configs.get("authtype");
        kmsClient = new KMSClient(kmsUrl, kmsUserName, kmsPassWord, rangerPrincipal, rangerKeytab, nameRules, authType);
    }
    return kmsClient;
}
Also used : KMSClient(org.apache.ranger.services.kms.client.KMSClient) HadoopException(org.apache.ranger.plugin.client.HadoopException)

Aggregations

KMSClient (org.apache.ranger.services.kms.client.KMSClient)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HadoopException (org.apache.ranger.plugin.client.HadoopException)1