if (!Strings.isNullOrEmpty(principal)) {
@Override public AuthCredentials extractCredentials(final RestRequest request, ThreadContext context) { if(context.getTransient(ConfigConstants.SG_XFF_DONE) != Boolean.TRUE) { throw new ElasticsearchSecurityException("xff not done"); } final String userHeader = settings.get("user_header"); final String rolesHeader = settings.get("roles_header"); final String rolesSeparator = settings.get("roles_separator", ","); if(log.isDebugEnabled()) { log.debug("headers {}", request.getHeaders()); log.debug("userHeader {}, value {}", userHeader, userHeader == null?null:request.header(userHeader)); log.debug("rolesHeader {}, value {}", rolesHeader, rolesHeader == null?null:request.header(rolesHeader)); } if (!Strings.isNullOrEmpty(userHeader) && !Strings.isNullOrEmpty((String) request.header(userHeader))) { String[] backendRoles = null; if (!Strings.isNullOrEmpty(rolesHeader) && !Strings.isNullOrEmpty((String) request.header(rolesHeader))) { backendRoles = ((String) request.header(rolesHeader)).split(rolesSeparator); } return new AuthCredentials((String) request.header(userHeader), backendRoles).markComplete(); } else { if(log.isTraceEnabled()) { log.trace("No '{}' header, send 401", userHeader); } return null; } }
private static String valueOrDefault(String value, String globalDefault) { if (Strings.isNullOrEmpty(value) && !Strings.isNullOrEmpty(globalDefault)) { return globalDefault; } return value; } }
private String sharedExistingSyncId(Map<String, PreSyncedFlushResponse> preSyncedFlushResponses) { String existingSyncId = null; for (PreSyncedFlushResponse resp : preSyncedFlushResponses.values()) { if (Strings.isNullOrEmpty(resp.existingSyncId)) { return null; } if (existingSyncId == null) { existingSyncId = resp.existingSyncId; } if (existingSyncId.equals(resp.existingSyncId) == false) { return null; } } return existingSyncId; }
/** * Return the CORS setting as an array of origins. * * @param corsSetting the CORS allow origin setting as configured by the user; * should never pass null, but we check for it anyway. * @return an array of origins if set, otherwise {@code null}. */ public static String[] corsSettingAsArray(String corsSetting) { if (Strings.isNullOrEmpty(corsSetting)) { return new String[0]; } return Arrays.asList(corsSetting.split(",")) .stream() .map(String::trim) .toArray(size -> new String[size]); } }
/** * Sets the format to use on the output of this aggregation. */ public MovFnPipelineAggregationBuilder format(String format) { if (Strings.isNullOrEmpty(format)) { throw new IllegalArgumentException("[" + FORMAT.getPreferredName() + "] must not be null or an empty string."); } this.format = format; return this; }
public MultiValuesSourceFieldConfig build() { if (Strings.isNullOrEmpty(fieldName) && script == null) { throw new IllegalArgumentException("[" + ParseField.CommonFields.FIELD.getPreferredName() + "] and [" + Script.SCRIPT_PARSE_FIELD.getPreferredName() + "] cannot both be null. " + "Please specify one or the other."); } if (Strings.isNullOrEmpty(fieldName) == false && script != null) { throw new IllegalArgumentException("[" + ParseField.CommonFields.FIELD.getPreferredName() + "] and [" + Script.SCRIPT_PARSE_FIELD.getPreferredName() + "] cannot both be configured. " + "Please specify one or the other."); } return new MultiValuesSourceFieldConfig(fieldName, missing, script, timeZone); } }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); builder.field("text", text); if (Strings.isNullOrEmpty(analyzer) == false) { builder.field("analyzer", analyzer); } if (tokenizer != null) { tokenizer.toXContent(builder, params); } if (tokenFilters.size() > 0) { builder.field("filter", tokenFilters); } if (charFilters.size() > 0) { builder.field("char_filter", charFilters); } if (Strings.isNullOrEmpty(field) == false) { builder.field("field", field); } if (explain) { builder.field("explain", true); } if (attributes.length > 0) { builder.field("attributes", attributes); } if (Strings.isNullOrEmpty(normalizer) == false) { builder.field("normalizer", normalizer); } return builder.endObject(); }
public UpdatedRepresentation(String id, String updatedDocumentPart) { Preconditions.checkArgument(!Strings.isNullOrEmpty(id), "Updated id must be specified " + id); Preconditions.checkArgument(!Strings.isNullOrEmpty(updatedDocumentPart), "Updated document must be specified"); this.id = id; this.updatedDocumentPart = updatedDocumentPart; }
public GetRollupCapsRequest(final String indexPattern) { if (Strings.isNullOrEmpty(indexPattern) || indexPattern.equals("*")) { this.indexPattern = MetaData.ALL; } else { this.indexPattern = indexPattern; } }
public DeleteLifecyclePolicyRequest(String lifecyclePolicy) { if (Strings.isNullOrEmpty(lifecyclePolicy)) { throw new IllegalArgumentException("lifecycle name must be present"); } this.lifecyclePolicy = lifecyclePolicy; }
private static boolean isSameOrigin(final String origin, final String host) { if (Strings.isNullOrEmpty(host) == false) { // strip protocol from origin final String originDomain = SCHEME_PATTERN.matcher(origin).replaceFirst(""); if (host.equals(originDomain)) { return true; } } return false; }
private static boolean isSameOrigin(final String origin, final String host) { if (Strings.isNullOrEmpty(host) == false) { // strip protocol from origin final String originDomain = SCHEME_PATTERN.matcher(origin).replaceFirst(""); if (host.equals(originDomain)) { return true; } } return false; }
public PutLifecyclePolicyRequest(LifecyclePolicy policy) { if (policy == null) { throw new IllegalArgumentException("policy definition cannot be null"); } if (Strings.isNullOrEmpty(policy.getName())) { throw new IllegalArgumentException("policy name must be present"); } this.policy = policy; }
public static InvalidateTokenRequest accessToken(String accessToken) { if (Strings.isNullOrEmpty(accessToken)) { throw new IllegalArgumentException("token is required"); } return new InvalidateTokenRequest(accessToken, null); }
public static CreateTokenRequest refreshTokenGrant(String refreshToken) { if (Strings.isNullOrEmpty(refreshToken)) { throw new IllegalArgumentException("refresh_token is required"); } return new CreateTokenRequest("refresh_token", null, null, null, refreshToken); }
public static InvalidateTokenRequest refreshToken(String refreshToken) { if (Strings.isNullOrEmpty(refreshToken)) { throw new IllegalArgumentException("refresh_token is required"); } return new InvalidateTokenRequest(null, refreshToken); }
public static InvalidateTokenRequest realmTokens(String realmName) { if (Strings.isNullOrEmpty(realmName)) { throw new IllegalArgumentException("realm name is required"); } return new InvalidateTokenRequest(null, null, realmName, null); }
/** * Checks for a removed setting and logs the correct alternative */ protected void logRemovedSetting(String settingName, String alternativeName) { if (!Strings.isNullOrEmpty(settings.get(settingName))) { deprecationLogger.deprecated("Setting [{}] has been removed, use [{}] instead", settingName, alternativeName); } }
public GetPrivilegesRequest(@Nullable final String applicationName, @Nullable final String... privilegeNames) { if ((CollectionUtils.isEmpty(privilegeNames) == false) && Strings.isNullOrEmpty(applicationName)) { throw new IllegalArgumentException("privilege cannot be specified when application is missing"); } this.applicationName = applicationName; this.privilegeNames = privilegeNames; }