Search in sources :

Example 1 with RestClientAuthenticator

use of org.janusgraph.diskstorage.es.rest.util.RestClientAuthenticator in project janusgraph by JanusGraph.

the class RestClientSetup method getCustomAuthenticator.

protected RestClientAuthenticator getCustomAuthenticator(String authClassName, String[] authClassConstructorArgList) {
    Preconditions.checkArgument(StringUtils.isNotEmpty(authClassName), "Custom authenticator class name cannot be empty");
    Preconditions.checkNotNull(authClassConstructorArgList, "Custom authenticator class constructor argument list cannot be null");
    final RestClientAuthenticator authenticator;
    try {
        final Class<?> c = Class.forName(authClassName);
        Preconditions.checkArgument(RestClientAuthenticator.class.isAssignableFrom(c), "Authenticator class " + authClassName + " must be a subclass of " + RestClientAuthenticator.class.getName());
        @SuppressWarnings("unchecked") final Constructor<RestClientAuthenticator> ctr = ((Class<RestClientAuthenticator>) c).getConstructor(String[].class);
        authenticator = ctr.newInstance((Object) authClassConstructorArgList);
    } catch (Exception e) {
        log.error("Unable to instantiate the custom authenticator {} with constructor arguments \"{}\"", authClassName, authClassConstructorArgList, e);
        throw new RuntimeException("Unable to instantiate the custom authenticator", e);
    }
    try {
        authenticator.init();
    } catch (IOException e) {
        log.error("Unable to initialize the custom authenticator {} with constructor arguments \"{}\"", authClassName, authClassConstructorArgList, e);
        throw new RuntimeException("Unable to initialize the custom authenticator", e);
    }
    return authenticator;
}
Also used : RestClientAuthenticator(org.janusgraph.diskstorage.es.rest.util.RestClientAuthenticator) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 RestClientAuthenticator (org.janusgraph.diskstorage.es.rest.util.RestClientAuthenticator)1