Search in sources :

Example 21 with StringUtils

use of org.apache.commons.lang3.StringUtils in project xwiki-platform by xwiki.

the class LiveTableResultsTest method setUp.

@Before
@SuppressWarnings("deprecation")
public void setUp() throws Exception {
    setOutputSyntax(Syntax.PLAIN_1_0);
    request.put("outputSyntax", "plain");
    request.put("xpage", "plain");
    oldcore.getXWikiContext().setAction("get");
    queryService = mock(QueryManagerScriptService.class);
    oldcore.getMocker().registerComponent(ScriptService.class, "query", queryService);
    modelService = mock(ModelScriptService.class);
    oldcore.getMocker().registerComponent(ScriptService.class, "model", modelService);
    TagPluginApi tagPluginApi = mock(TagPluginApi.class);
    doReturn(tagPluginApi).when(oldcore.getSpyXWiki()).getPluginApi(eq("tag"), any(XWikiContext.class));
    registerVelocityTool("stringtool", new StringUtils());
    registerVelocityTool("mathtool", new MathTool());
    registerVelocityTool("regextool", new RegexTool());
    registerVelocityTool("numbertool", new NumberTool());
    loadPage(new DocumentReference("xwiki", "XWiki", "LiveTableResultsMacros"));
}
Also used : NumberTool(org.apache.velocity.tools.generic.NumberTool) QueryManagerScriptService(org.xwiki.query.script.QueryManagerScriptService) StringUtils(org.apache.commons.lang3.StringUtils) XWikiContext(com.xpn.xwiki.XWikiContext) TagPluginApi(com.xpn.xwiki.plugin.tag.TagPluginApi) MathTool(org.apache.velocity.tools.generic.MathTool) ModelScriptService(org.xwiki.model.script.ModelScriptService) DocumentReference(org.xwiki.model.reference.DocumentReference) RegexTool(org.xwiki.velocity.tools.RegexTool) Before(org.junit.Before)

Example 22 with StringUtils

use of org.apache.commons.lang3.StringUtils in project cas by apereo.

the class DefaultCasCookieValueManager method obtainValueFromCompoundCookie.

@Override
protected String obtainValueFromCompoundCookie(final String value, final HttpServletRequest request) {
    val cookieParts = Splitter.on(String.valueOf(COOKIE_FIELD_SEPARATOR)).splitToList(value);
    val cookieValue = cookieParts.get(0);
    if (!cookieProperties.isPinToSession()) {
        LOGGER.trace("Cookie session-pinning is disabled. Returning cookie value as it was provided");
        return cookieValue;
    }
    if (cookieParts.size() != COOKIE_FIELDS_LENGTH) {
        throw new InvalidCookieException("Invalid cookie. Required fields are missing");
    }
    val cookieIpAddress = cookieParts.get(1);
    val cookieUserAgent = cookieParts.get(2);
    if (Stream.of(cookieValue, cookieIpAddress, cookieUserAgent).anyMatch(StringUtils::isBlank)) {
        throw new InvalidCookieException("Invalid cookie. Required fields are empty");
    }
    val clientInfo = ClientInfoHolder.getClientInfo();
    if (clientInfo == null) {
        throw new InvalidCookieException("Unable to match required remote address " + cookieIpAddress + " because client ip at time of cookie creation is unknown");
    }
    if (!cookieIpAddress.equals(clientInfo.getClientIpAddress())) {
        if (StringUtils.isBlank(cookieProperties.getAllowedIpAddressesPattern()) || !RegexUtils.find(cookieProperties.getAllowedIpAddressesPattern(), clientInfo.getClientIpAddress())) {
            throw new InvalidCookieException("Invalid cookie. Required remote address " + cookieIpAddress + " does not match " + clientInfo.getClientIpAddress());
        }
        LOGGER.debug("Required remote address [{}] does not match [{}], but it's authorized proceed", cookieIpAddress, clientInfo.getClientIpAddress());
    }
    val agent = HttpRequestUtils.getHttpServletRequestUserAgent(request);
    if (!cookieUserAgent.equals(agent)) {
        throw new InvalidCookieException("Invalid cookie. Required user-agent " + cookieUserAgent + " does not match " + agent);
    }
    return cookieValue;
}
Also used : lombok.val(lombok.val) InvalidCookieException(org.apereo.cas.web.support.InvalidCookieException) StringUtils(org.apache.commons.lang3.StringUtils)

Example 23 with StringUtils

use of org.apache.commons.lang3.StringUtils in project cas by apereo.

the class AbstractWebApplicationServiceResponseBuilder method getWebApplicationServiceResponseType.

/**
 * Determine response type response.
 *
 * @param finalService the final service
 * @return the response type
 */
protected Response.ResponseType getWebApplicationServiceResponseType(final WebApplicationService finalService) {
    val request = HttpRequestUtils.getHttpServletRequestFromRequestAttributes();
    val methodRequest = Optional.ofNullable(request).map(httpServletRequest -> httpServletRequest.getParameter(CasProtocolConstants.PARAMETER_METHOD)).orElse(null);
    final Function<String, String> func = FunctionUtils.doIf(StringUtils::isBlank, t -> {
        val registeredService = this.servicesManager.findServiceBy(finalService);
        if (registeredService != null) {
            return registeredService.getResponseType();
        }
        return null;
    }, f -> methodRequest);
    val method = func.apply(methodRequest);
    if (StringUtils.isBlank(method)) {
        return Response.ResponseType.REDIRECT;
    }
    return Response.ResponseType.valueOf(method.toUpperCase());
}
Also used : lombok.val(lombok.val) CasProtocolConstants(org.apereo.cas.CasProtocolConstants) Setter(lombok.Setter) Getter(lombok.Getter) UrlValidator(org.apereo.cas.web.UrlValidator) RequiredArgsConstructor(lombok.RequiredArgsConstructor) lombok.val(lombok.val) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) HttpRequestUtils(org.apereo.cas.util.HttpRequestUtils) FunctionUtils(org.apereo.cas.util.function.FunctionUtils) AccessLevel(lombok.AccessLevel) Map(java.util.Map) Optional(java.util.Optional) ServicesManager(org.apereo.cas.services.ServicesManager) StringUtils(org.apache.commons.lang3.StringUtils)

Example 24 with StringUtils

use of org.apache.commons.lang3.StringUtils in project metacat by Netflix.

the class MySqlTagService method buildParametrizedInClause.

private static String buildParametrizedInClause(final Set<String> tags, final List<SqlParameterValue> params, final int index) {
    final String tagList = tags.stream().filter(StringUtils::isNotBlank).map(v -> "?").collect(Collectors.joining(", "));
    params.addAll(index, tags.stream().filter(StringUtils::isNotBlank).map(p -> new SqlParameterValue(Types.VARCHAR, p)).collect(Collectors.toList()));
    return StringUtils.isBlank(tagList) ? EMPTY_CLAUSE : tagList;
}
Also used : Lookup(com.netflix.metacat.common.server.model.Lookup) UserMetadataService(com.netflix.metacat.common.server.usermetadata.UserMetadataService) TagItem(com.netflix.metacat.common.server.model.TagItem) KeyHolder(org.springframework.jdbc.support.KeyHolder) StringUtils(org.apache.commons.lang3.StringUtils) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) SQLException(java.sql.SQLException) Lists(com.google.common.collect.Lists) TagService(com.netflix.metacat.common.server.usermetadata.TagService) MetacatBadRequestException(com.netflix.metacat.common.exception.MetacatBadRequestException) Map(java.util.Map) UserMetadataServiceException(com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException) LookupService(com.netflix.metacat.common.server.usermetadata.LookupService) Config(com.netflix.metacat.common.server.properties.Config) Nullable(javax.annotation.Nullable) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) MetacatJson(com.netflix.metacat.common.json.MetacatJson) Set(java.util.Set) QualifiedName(com.netflix.metacat.common.QualifiedName) PreparedStatement(java.sql.PreparedStatement) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) SqlParameterValue(org.springframework.jdbc.core.SqlParameterValue) GeneratedKeyHolder(org.springframework.jdbc.support.GeneratedKeyHolder) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Stream(java.util.stream.Stream) Statement(java.sql.Statement) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) Transactional(org.springframework.transaction.annotation.Transactional) Types(java.sql.Types) SqlParameterValue(org.springframework.jdbc.core.SqlParameterValue) StringUtils(org.apache.commons.lang3.StringUtils)

Example 25 with StringUtils

use of org.apache.commons.lang3.StringUtils in project yorc-a4c-plugin by ystia.

the class ToscaComponentExporter method getVelocityContext.

static Map<String, Object> getVelocityContext() {
    Map<String, Object> velocityCtx = new HashMap<>();
    velocityCtx.put("vtPath", "org/ystia/yorc/alien4cloud/plugin/tosca");
    velocityCtx.put("yorcUtils", new ToscaComponentUtils());
    velocityCtx.put("stringsUtils", new StringUtils());
    return velocityCtx;
}
Also used : HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils)

Aggregations

StringUtils (org.apache.commons.lang3.StringUtils)29 HashMap (java.util.HashMap)10 List (java.util.List)10 Optional (java.util.Optional)10 Map (java.util.Map)9 Collectors (java.util.stream.Collectors)8 Set (java.util.Set)7 lombok.val (lombok.val)7 ArrayList (java.util.ArrayList)6 Arrays (java.util.Arrays)5 Stream (java.util.stream.Stream)5 ColumnSpec (com.thinkbiganalytics.util.ColumnSpec)3 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3 Slf4j (lombok.extern.slf4j.Slf4j)3 FlowFile (org.apache.nifi.flowfile.FlowFile)3 CollectionUtils (org.apereo.cas.util.CollectionUtils)3 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)2 ThriftService (com.thinkbiganalytics.nifi.v2.thrift.ThriftService)2 IOException (java.io.IOException)2