Java Code Examples for org.apache.logging.log4j.util.Strings#isNotBlank()

The following examples show how to use org.apache.logging.log4j.util.Strings#isNotBlank() . 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: ThrowablePatternConverter.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
private void formatOption(final Throwable throwable, final String suffix, final StringBuilder buffer) {
    final int len = buffer.length();
    if (len > 0 && !Character.isWhitespace(buffer.charAt(len - 1))) {
        buffer.append(' ');
    }
    if (!options.allLines() || nonStandardLineSeparator || Strings.isNotBlank(suffix)) {
        final StringWriter w = new StringWriter();
        throwable.printStackTrace(new PrintWriter(w));

        final String[] array = w.toString().split(Strings.LINE_SEPARATOR);
        final int limit = options.minLines(array.length) - 1;
        final boolean suffixNotBlank = Strings.isNotBlank(suffix);
        for (int i = 0; i <= limit; ++i) {
            buffer.append(array[i]);
            if (suffixNotBlank) {
                buffer.append(' ');
                buffer.append(suffix);
            }
            if (i < limit) {
                buffer.append(options.getSeparator());
            }
        }
    } else {
        throwable.printStackTrace(new PrintWriter(new StringBuilderWriter(buffer)));
    }
}
 
Example 2
Source File: CIBAAuthorizeParamsValidatorService.java    From oxAuth with MIT License 5 votes vote down vote up
private boolean validateOneParamNotBlank(String... params) {
    List<String> notBlankParams = new ArrayList<>();

    for (String param : params) {
        if (Strings.isNotBlank(param)) {
            notBlankParams.add(param);
        }
    }

    return notBlankParams.size() == 1;
}
 
Example 3
Source File: K8SController.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
private Pod getCurrentPod(KubernetesClient kubernetesClient) {
    String hostName = System.getenv(HOSTNAME);
    try {
        if (isServiceAccount() && Strings.isNotBlank(hostName)) {
            return kubernetesClient.pods().withName(hostName).get();
        }
    } catch (Throwable t) {
        LOGGER.debug("Unable to locate pod with name {}.", hostName);
    }
    return null;
}
 
Example 4
Source File: PluginManager.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a list of package names to be scanned for plugins. Convenience method for {@link #addPackage(String)}.
 *
 * @param packages collection of package names to add. Empty and null package names are ignored.
 */
public static void addPackages(final Collection<String> packages) {
    for (final String pkg : packages) {
        if (Strings.isNotBlank(pkg)) {
            PACKAGES.addIfAbsent(pkg);
        }
    }
}
 
Example 5
Source File: KubernetesLookup.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
private Pod getCurrentPod(String hostName, KubernetesClient kubernetesClient) {
    try {
        if (isServiceAccount() && Strings.isNotBlank(hostName)) {
            return kubernetesClient.pods().withName(hostName).get();
        }
    } catch (Throwable t) {
        LOGGER.debug("Unable to locate pod with name {}.", hostName);
    }
    return null;
}
 
Example 6
Source File: KerberosConfigToCreateKerberosConfigRequestConverter.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private String getFakeSecretIfNotNull(String value, String postfix) {
    if (Strings.isNotBlank(value)) {
        String postString = postfix != null ? postfix : "secret";
        return "fake-" + postString;
    }
    return value;
}
 
Example 7
Source File: AuthorizeAction.java    From oxAuth with MIT License 5 votes vote down vote up
public String getBindingMessage() {
    String bindingMessage = null;

    if (Strings.isNotBlank(getAuthReqId())) {
        final CibaRequestCacheControl cibaRequestCacheControl = cibaRequestService.getCibaRequest(authReqId);

        if (cibaRequestCacheControl != null) {
            bindingMessage = cibaRequestCacheControl.getBindingMessage();
        }
    }

    return bindingMessage;
}
 
Example 8
Source File: UsedAuthenticationFlowWorkaroundFactory.java    From keycloak-config-cli with Apache License 2.0 5 votes vote down vote up
private boolean hasToResetFlows() {
    return Strings.isNotBlank(browserFlow) ||
            Strings.isNotBlank(directGrantFlow) ||
            Strings.isNotBlank(clientAuthenticationFlow) ||
            Strings.isNotBlank(dockerAuthenticationFlow) ||
            Strings.isNotBlank(registrationFlow) ||
            Strings.isNotBlank(resetCredentialsFlow);
}
 
Example 9
Source File: UsedAuthenticationFlowWorkaroundFactory.java    From keycloak-config-cli with Apache License 2.0 5 votes vote down vote up
private void resetCredentialsFlowIfNeeded(RealmRepresentation existingRealm) {
    if (Strings.isNotBlank(resetCredentialsFlow)) {
        logger.debug("Reset reset-credentials-flow in realm '{}' to '{}'", realmImport.getRealm(), resetCredentialsFlow);

        existingRealm.setResetCredentialsFlow(resetCredentialsFlow);
    }
}
 
Example 10
Source File: UsedAuthenticationFlowWorkaroundFactory.java    From keycloak-config-cli with Apache License 2.0 5 votes vote down vote up
private void resetRegistrationFlowIfNeeded(RealmRepresentation existingRealm) {
    if (Strings.isNotBlank(registrationFlow)) {
        logger.debug("Reset registration-flow in realm '{}' to '{}'", realmImport.getRealm(), registrationFlow);

        existingRealm.setRegistrationFlow(registrationFlow);
    }
}
 
Example 11
Source File: UsedAuthenticationFlowWorkaroundFactory.java    From keycloak-config-cli with Apache License 2.0 5 votes vote down vote up
private void resetDockerAuthenticationFlowIfNeeded(RealmRepresentation existingRealm) {
    if (Strings.isNotBlank(dockerAuthenticationFlow)) {
        logger.debug("Reset docker-authentication-flow in realm '{}' to '{}'", realmImport.getRealm(), dockerAuthenticationFlow);

        existingRealm.setDockerAuthenticationFlow(dockerAuthenticationFlow);
    }
}
 
Example 12
Source File: UsedAuthenticationFlowWorkaroundFactory.java    From keycloak-config-cli with Apache License 2.0 5 votes vote down vote up
private void resetClientAuthenticationFlowIfNeeded(RealmRepresentation existingRealm) {
    if (Strings.isNotBlank(clientAuthenticationFlow)) {
        logger.debug("Reset client-authentication-flow in realm '{}' to '{}'", realmImport.getRealm(), clientAuthenticationFlow);

        existingRealm.setClientAuthenticationFlow(clientAuthenticationFlow);
    }
}
 
Example 13
Source File: UsedAuthenticationFlowWorkaroundFactory.java    From keycloak-config-cli with Apache License 2.0 5 votes vote down vote up
private void resetDirectGrantFlowIfNeeded(RealmRepresentation existingRealm) {
    if (Strings.isNotBlank(directGrantFlow)) {
        logger.debug("Reset direct-grant-flow in realm '{}' to '{}'", realmImport.getRealm(), directGrantFlow);

        existingRealm.setDirectGrantFlow(directGrantFlow);
    }
}
 
Example 14
Source File: UsedAuthenticationFlowWorkaroundFactory.java    From keycloak-config-cli with Apache License 2.0 5 votes vote down vote up
private void resetBrowserFlowIfNeeded(RealmRepresentation existingRealm) {
    if (Strings.isNotBlank(browserFlow)) {
        logger.debug("Reset browser-flow in realm '{}' to '{}'", realmImport.getRealm(), browserFlow);

        existingRealm.setBrowserFlow(browserFlow);
    }
}
 
Example 15
Source File: CIBARegisterParamsValidatorService.java    From oxAuth with MIT License 4 votes vote down vote up
public boolean validateParams(
        BackchannelTokenDeliveryMode backchannelTokenDeliveryMode, String backchannelClientNotificationEndpoint,
        AsymmetricSignatureAlgorithm backchannelAuthenticationRequestSigningAlg, Boolean backchannelUserCodeParameter,
        List<GrantType> grantTypes, SubjectType subjectType, String sectorIdentifierUri, String jwks, String jwksUri) {
    try {
        // Not CIBA Registration
        if (backchannelTokenDeliveryMode == null && Strings.isBlank(backchannelClientNotificationEndpoint) && backchannelAuthenticationRequestSigningAlg == null) {
            return true;
        }

        // Required parameter.
        if (backchannelTokenDeliveryMode == null
                || !appConfiguration.getBackchannelTokenDeliveryModesSupported().contains(backchannelTokenDeliveryMode.getValue())) {
            return false;
        }

        // Required if the token delivery mode is set to ping or push.
        if ((backchannelTokenDeliveryMode == PING || backchannelTokenDeliveryMode == PUSH)
                && Strings.isBlank(backchannelClientNotificationEndpoint)) {
            return false;
        }

        // Grant type urn:openid:params:grant-type:ciba is required if the token delivery mode is set to ping or poll.
        if (backchannelTokenDeliveryMode == PING || backchannelTokenDeliveryMode == POLL) {
            if (!appConfiguration.getGrantTypesSupported().contains(CIBA) || !grantTypes.contains(CIBA)) {
                return false;
            }
        }

        // If the server does not support backchannel_user_code_parameter_supported, the default value is false.
        if (appConfiguration.getBackchannelUserCodeParameterSupported() == null || appConfiguration.getBackchannelUserCodeParameterSupported() == false) {
            backchannelUserCodeParameter = false;
        }

        if (subjectType != null && subjectType == SubjectType.PAIRWISE) {

            if (backchannelTokenDeliveryMode == PING || backchannelTokenDeliveryMode == POLL) {
                if (Strings.isBlank(jwks) && Strings.isBlank(jwksUri)) {
                    return false;
                }
            }

            if (Strings.isNotBlank(sectorIdentifierUri)) {
                ClientRequest clientRequest = new ClientRequest(sectorIdentifierUri);
                clientRequest.setHttpMethod(HttpMethod.GET);

                ClientResponse<String> clientResponse = clientRequest.get(String.class);
                int status = clientResponse.getStatus();

                if (status != 200) {
                    return false;
                }

                String entity = clientResponse.getEntity(String.class);
                JSONArray sectorIdentifierJsonArray = new JSONArray(entity);

                if (backchannelTokenDeliveryMode == PING || backchannelTokenDeliveryMode == POLL) {
                    // If a sector_identifier_uri is explicitly provided, then the jwks_uri must be included in the list of
                    // URIs pointed to by the sector_identifier_uri.
                    if (!Strings.isBlank(jwksUri) && !Util.asList(sectorIdentifierJsonArray).contains(jwksUri)) {
                        return false;
                    }
                } else if (backchannelTokenDeliveryMode == PUSH) {
                    // In case a sector_identifier_uri is explicitly provided, then the backchannel_client_notification_endpoint
                    // must be included in the list of URIs pointed to by the sector_identifier_uri.
                    if (!Util.asList(sectorIdentifierJsonArray).contains(backchannelClientNotificationEndpoint)) {
                        return false;
                    }
                }
            }
        }
    } catch (Exception e) {
        log.trace(e.getMessage(), e);
        return false;
    }

    return true;
}
 
Example 16
Source File: Poem.java    From tutorials with MIT License 4 votes vote down vote up
public static boolean isValidPoem(Poem poem) {
    return poem != null && Strings.isNotBlank(poem.getAuthor()) && Strings.isNotBlank(poem.getBody())
      && Strings.isNotBlank(poem.getTitle());
}
 
Example 17
Source File: ThrowablePatternConverter.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
private void formatSubShortOption(final Throwable t, final String suffix, final StringBuilder buffer) {
    StackTraceElement[] trace;
    StackTraceElement throwingMethod = null;
    int len;

    if (t != null) {
        trace = t.getStackTrace();
        if (trace !=null && trace.length > 0) {
            throwingMethod = trace[0];
        }
    }

    if (t != null && throwingMethod != null) {
        String toAppend = Strings.EMPTY;

        if (ThrowableFormatOptions.CLASS_NAME.equalsIgnoreCase(rawOption)) {
            toAppend = throwingMethod.getClassName();
        }
        else if (ThrowableFormatOptions.METHOD_NAME.equalsIgnoreCase(rawOption)) {
            toAppend = throwingMethod.getMethodName();
        }
        else if (ThrowableFormatOptions.LINE_NUMBER.equalsIgnoreCase(rawOption)) {
            toAppend = String.valueOf(throwingMethod.getLineNumber());
        }
        else if (ThrowableFormatOptions.MESSAGE.equalsIgnoreCase(rawOption)) {
            toAppend = t.getMessage();
        }
        else if (ThrowableFormatOptions.LOCALIZED_MESSAGE.equalsIgnoreCase(rawOption)) {
            toAppend = t.getLocalizedMessage();
        }
        else if (ThrowableFormatOptions.FILE_NAME.equalsIgnoreCase(rawOption)) {
            toAppend = throwingMethod.getFileName();
        }

        len = buffer.length();
        if (len > 0 && !Character.isWhitespace(buffer.charAt(len - 1))) {
            buffer.append(' ');
        }
        buffer.append(toAppend);

        if (Strings.isNotBlank(suffix)) {
            buffer.append(' ');
            buffer.append(suffix);
        }
    }
}