Java Code Examples for org.apache.solr.common.util.Base64#base64ToByteArray()
The following examples show how to use
org.apache.solr.common.util.Base64#base64ToByteArray() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JWTAuthPluginIntegrationTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void infoRequestValidateXSolrAuthHeadersBlockUnknownFalse() throws Exception { // Re-configure cluster with other security.json, see https://issues.apache.org/jira/browse/SOLR-14196 shutdownCluster(); configureCluster(NUM_SERVERS)// nodes .withSecurityJson(TEST_PATH().resolve("security").resolve("jwt_plugin_jwk_security_blockUnknownFalse.json")) .addConfig("conf1", TEST_PATH().resolve("configsets").resolve("cloud-minimal").resolve("conf")) .withDefaultClusterProperty("useLegacyReplicaAssignment", "false") .configure(); baseUrl = cluster.getRandomJetty(random()).getBaseUrl().toString(); Map<String, String> headers = getHeaders(baseUrl + "/admin/info/system", null); assertEquals("Should have received 401 code", "401", headers.get("code")); assertEquals("Bearer realm=\"my-solr-jwt-blockunknown-false\"", headers.get("WWW-Authenticate")); String authData = new String(Base64.base64ToByteArray(headers.get("X-Solr-AuthData")), UTF_8); assertEquals("{\n" + " \"scope\":\"solr:admin\",\n" + " \"redirect_uris\":[],\n" + " \"authorizationEndpoint\":\"http://acmepaymentscorp/oauth/auz/authorize\",\n" + " \"client_id\":\"solr-cluster\"}", authData); }
Example 2
Source File: CryptoKeys.java From lucene-solr with Apache License 2.0 | 5 votes |
public static PublicKey deserializeX509PublicKey(String pubKey) { try { KeyFactory keyFactory = KeyFactory.getInstance("RSA"); X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(Base64.base64ToByteArray(pubKey)); return keyFactory.generatePublic(publicKeySpec); } catch (Exception e) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,e); } }
Example 3
Source File: FieldType.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Unmarshals a binary field value. */ protected static Object unmarshalBase64SortValue(Object value) { if (null == value) { return null; } final String val = (String)value; final byte[] bytes = Base64.base64ToByteArray(val); return new BytesRef(bytes); }
Example 4
Source File: BinaryField.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public IndexableField createField(SchemaField field, Object val) { if (val == null) return null; if (!field.stored()) { log.trace("Ignoring unstored binary field: {}", field); return null; } byte[] buf = null; int offset = 0, len = 0; if (val instanceof byte[]) { buf = (byte[]) val; len = buf.length; } else if (val instanceof ByteBuffer && ((ByteBuffer)val).hasArray()) { ByteBuffer byteBuf = (ByteBuffer) val; buf = byteBuf.array(); offset = byteBuf.position(); len = byteBuf.limit() - byteBuf.position(); } else { String strVal = val.toString(); //the string has to be a base64 encoded string buf = Base64.base64ToByteArray(strVal); offset = 0; len = buf.length; } return new org.apache.lucene.document.StoredField(field.getName(), buf, offset, len); }
Example 5
Source File: JWTAuthPluginIntegrationTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void infoRequestValidateXSolrAuthHeaders() throws IOException { Map<String, String> headers = getHeaders(baseUrl + "/admin/info/system", null); assertEquals("Should have received 401 code", "401", headers.get("code")); assertEquals("Bearer realm=\"my-solr-jwt\"", headers.get("WWW-Authenticate")); String authData = new String(Base64.base64ToByteArray(headers.get("X-Solr-AuthData")), UTF_8); assertEquals("{\n" + " \"scope\":\"solr:admin\",\n" + " \"redirect_uris\":[],\n" + " \"authorizationEndpoint\":\"http://acmepaymentscorp/oauth/auz/authorize\",\n" + " \"client_id\":\"solr-cluster\"}", authData); }
Example 6
Source File: JWTAuthPluginTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void xSolrAuthDataHeader() { testConfig.put("adminUiScope", "solr:admin"); testConfig.put("authorizationEndpoint", "http://acmepaymentscorp/oauth/auz/authorize"); testConfig.put("clientId", "solr-cluster"); plugin.init(testConfig); String headerBase64 = plugin.generateAuthDataHeader(); String headerJson = new String(Base64.base64ToByteArray(headerBase64), StandardCharsets.UTF_8); Map<String,String> parsed = (Map<String, String>) Utils.fromJSONString(headerJson); assertEquals("solr:admin", parsed.get("scope")); assertEquals("http://acmepaymentscorp/oauth/auz/authorize", parsed.get("authorizationEndpoint")); assertEquals("solr-cluster", parsed.get("client_id")); }
Example 7
Source File: BinaryDocValuesField.java From liresolr with GNU General Public License v2.0 | 5 votes |
@Override public IndexableField createField(SchemaField field, Object val /*, float boost*/) { if (val == null) return null; if (!field.stored()) { return null; } byte[] buf = null; int offset = 0, len = 0; if (val instanceof byte[]) { buf = (byte[]) val; len = buf.length; } else if (val instanceof ByteBuffer && ((ByteBuffer)val).hasArray()) { ByteBuffer byteBuf = (ByteBuffer) val; buf = byteBuf.array(); offset = byteBuf.position(); len = byteBuf.limit() - byteBuf.position(); } else { String strVal = val.toString(); //the string has to be a base64 encoded string buf = Base64.base64ToByteArray(strVal); offset = 0; len = buf.length; } Field f = new org.apache.lucene.document.BinaryDocValuesField(field.getName(), new BytesRef(buf, offset, len)); // Field f = new org.apache.lucene.document.StoredField(field.getName(), buf, offset, len); //f.setBoost(boost); return f; }