Example usage for org.apache.solr.security Sha256AuthenticationProvider sha256

List of usage examples for org.apache.solr.security Sha256AuthenticationProvider sha256

Introduction

In this page you can find the example usage for org.apache.solr.security Sha256AuthenticationProvider sha256.

Prototype

public static String sha256(String password, String saltKey) 

Source Link

Usage

From source file:org.apache.beam.sdk.io.solr.SolrIOTest.java

License:Apache License

@BeforeClass
public static void beforeClass() throws Exception {
    // setup credential for solr user,
    // See https://cwiki.apache.org/confluence/display/solr/Basic+Authentication+Plugin
    String password = "SolrRocks";
    // salt's size can be arbitrary
    byte[] salt = new byte[random().nextInt(30) + 1];
    random().nextBytes(salt);/*from   www  .  j  av  a2 s.c om*/
    String base64Salt = BaseEncoding.base64().encode(salt);
    String sha56 = Sha256AuthenticationProvider.sha256(password, base64Salt);
    String credential = sha56 + " " + base64Salt;
    String securityJson = "{" + "'authentication':{" + "  'blockUnknown': true,"
            + "  'class':'solr.BasicAuthPlugin'," + "  'credentials':{'solr':'" + credential + "'}}" + "}";

    configureCluster(3).addConfig("conf", getFile("cloud-minimal/conf").toPath()).configure();
    ZkStateReader zkStateReader = cluster.getSolrClient().getZkStateReader();
    zkStateReader.getZkClient().setData("/security.json", securityJson.getBytes(Charset.defaultCharset()),
            true);
    String zkAddress = cluster.getZkServer().getZkAddress();
    connectionConfiguration = SolrIO.ConnectionConfiguration.create(zkAddress).withBasicCredentials("solr",
            password);
    solrClient = connectionConfiguration.createClient();
    SolrIOTestUtils.createCollection(SOLR_COLLECTION, NUM_SHARDS, 1, solrClient);
}