Refine search
/** * Sets the {@link IndexWriter} this config is attached to. * * @throws AlreadySetException * if this config is already attached to a writer. */ IndexWriterConfig setIndexWriter(IndexWriter writer) { if (this.writer.get() != null) { throw new IllegalStateException("do not share IndexWriterConfig instances across IndexWriters"); } this.writer.set(writer); return this; }
private void decryptLegacyEntries() throws GeneralSecurityException, IOException { KeyStore keystore = KeyStore.getInstance("PKCS12"); Map<String, EntryType> settingTypes = new HashMap<>(); ByteArrayInputStream inputBytes = new ByteArrayInputStream(dataBytes); keystore.load(input, "".toCharArray()); Enumeration<String> aliases = keystore.aliases(); if (formatVersion == 1) { while (aliases.hasMoreElements()) { this.entries.set(new HashMap<>()); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBE"); KeyStore.PasswordProtection password = new KeyStore.PasswordProtection("".toCharArray()); entries.get().put(setting, new Entry(settingType, bytes));
/** Constructs a new keystore with the given password. */ static KeyStoreWrapper create(char[] password) throws Exception { KeyStoreWrapper wrapper = new KeyStoreWrapper(FORMAT_VERSION, password.length != 0, NEW_KEYSTORE_TYPE, NEW_KEYSTORE_STRING_KEY_ALGO, NEW_KEYSTORE_FILE_KEY_ALGO, new HashMap<>(), null); KeyStore keyStore = KeyStore.getInstance(NEW_KEYSTORE_TYPE); keyStore.load(null, null); wrapper.keystore.set(keyStore); wrapper.keystorePassword.set(new KeyStore.PasswordProtection(password)); return wrapper; }
/** Remove the given setting from the keystore. */ void remove(String setting) throws KeyStoreException { keystore.get().deleteEntry(setting); settingTypes.remove(setting); }
/** Set a file setting. */ void setFile(String setting, byte[] bytes) throws GeneralSecurityException { bytes = Base64.getEncoder().encode(bytes); char[] chars = new char[bytes.length]; for (int i = 0; i < chars.length; ++i) { chars[i] = (char)bytes[i]; // PBE only stores the lower 8 bits, so this narrowing is ok } SecretKey secretKey = stringFactory.generateSecret(new PBEKeySpec(chars)); keystore.get().setEntry(setting, new KeyStore.SecretKeyEntry(secretKey), keystorePassword.get()); settingTypes.put(setting, KeyType.FILE); }
@Override public String toString() { StringBuilder sb = new StringBuilder(super.toString()); sb.append("writer=").append(writer.get()).append("\n"); return sb.toString(); }
/** * Sets the {@link XContentType} */ final void setXContentType(XContentType xContentType) { this.xContentType.set(xContentType); }
@SuppressWarnings("unchecked") public static Suggestion<? extends Entry<? extends Option>> fromXContent(XContentParser parser) throws IOException { ensureExpectedToken(XContentParser.Token.START_ARRAY, parser.currentToken(), parser::getTokenLocation); SetOnce<Suggestion> suggestion = new SetOnce<>(); XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Suggestion.class, suggestion::set); return suggestion.get(); }
@Override protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) { if (supplier != null) { return supplier.get() == null ? this : new TermsQueryBuilder(this.fieldName, supplier.get()); } else if (this.termsLookup != null) { SetOnce<List<?>> supplier = new SetOnce<>(); queryRewriteContext.registerAsyncAction((client, listener) -> { fetch(termsLookup, client, ActionListener.wrap(list -> { supplier.set(list); listener.onResponse(null); }, listener::onFailure)); }); return new TermsQueryBuilder(this.fieldName, supplier::get); } return this; } }
executor.execute(new AbstractRunnable() { final SetOnce<Exception> failure = new SetOnce<>();
/** * Set a string setting. * * @throws IllegalArgumentException if the value is not ASCII */ void setString(String setting, char[] value) throws GeneralSecurityException { if (ASCII_ENCODER.canEncode(CharBuffer.wrap(value)) == false) { throw new IllegalArgumentException("Value must be ascii"); } SecretKey secretKey = stringFactory.generateSecret(new PBEKeySpec(value)); keystore.get().setEntry(setting, new KeyStore.SecretKeyEntry(secretKey), keystorePassword.get()); settingTypes.put(setting, KeyType.STRING); }
/** * Set the name of this node. */ static void setNodeName(String nodeName) { NODE_NAME.set(nodeName); }
public static Aggregations fromXContent(XContentParser parser) throws IOException { final List<Aggregation> aggregations = new ArrayList<>(); XContentParser.Token token; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.START_OBJECT) { SetOnce<Aggregation> typedAgg = new SetOnce<>(); String currentField = parser.currentName(); parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class, typedAgg::set); if (typedAgg.get() != null) { aggregations.add(typedAgg.get()); } else { throw new ParsingException(parser.getTokenLocation(), String.format(Locale.ROOT, "Could not parse aggregation keyed as [%s]", currentField)); } } } return new Aggregations(aggregations); } }
@Override protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) throws IOException { if (supplier != null) { return supplier.get() == null ? this : new GeoShapeQueryBuilder(this.fieldName, supplier.get()).relation(relation).strategy (strategy); } else if (this.shape == null) { SetOnce<ShapeBuilder> supplier = new SetOnce<>(); queryRewriteContext.registerAsyncAction((client, listener) -> { GetRequest getRequest = new GetRequest(indexedShapeIndex, indexedShapeType, indexedShapeId); getRequest.routing(indexedShapeRouting); fetch(client, getRequest, indexedShapePath, ActionListener.wrap(builder-> { supplier.set(builder); listener.onResponse(null); }, listener::onFailure)); }); return new GeoShapeQueryBuilder(this.fieldName, supplier::get, this.indexedShapeId, this.indexedShapeType).relation(relation) .strategy(strategy); } return this; } }
@Override public Set<String> getSettingNames() { synchronized (settingNames) { if (settingNames.get() == null) { Set<String> names = delegate.getSettingNames().stream() .filter(keyPredicate).map(removePrefix).collect(Collectors.toSet()); settingNames.set(Collections.unmodifiableSet(names)); } } return settingNames.get(); }
@Override public boolean isLoaded() { return entries.get() != null; }
/** * if this method is called the query context will throw exception if methods are accessed * that could yield different results across executions like {@link #getClient()} */ public final void freezeContext() { this.frozen.set(Boolean.TRUE); }
@SuppressWarnings("unchecked") public static Suggestion<? extends Entry<? extends Option>> fromXContent(XContentParser parser) throws IOException { ensureExpectedToken(XContentParser.Token.START_ARRAY, parser.currentToken(), parser::getTokenLocation); SetOnce<Suggestion> suggestion = new SetOnce<>(); XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Suggestion.class, suggestion::set); return suggestion.get(); }
/** Returns the fully qualified setting names contained in this settings object. */ public Set<String> keySet() { synchronized (keys) { if (keys.get() == null) { if (secureSettings == null) { keys.set(settings.keySet()); } else { Stream<String> stream = Stream.concat(settings.keySet().stream(), secureSettings.getSettingNames().stream()); // uniquify, since for legacy reasons the same setting name may exist in both keys.set(Collections.unmodifiableSet(stream.collect(Collectors.toSet()))); } } } return keys.get(); }