Example usage for org.springframework.util StringUtils commaDelimitedListToSet

List of usage examples for org.springframework.util StringUtils commaDelimitedListToSet

Introduction

In this page you can find the example usage for org.springframework.util StringUtils commaDelimitedListToSet.

Prototype

public static Set<String> commaDelimitedListToSet(@Nullable String str) 

Source Link

Document

Convert a comma delimited list (e.g., a row from a CSV file) into a set.

Usage

From source file:cec.easyshop.storefront.util.CSRFHandlerInterceptor.java

protected boolean isCSRFExemptUrl(final String servletPath) {
    if (servletPath != null) {
        final String allowedUrlPatterns = Config.getParameter(CSRF_ALLOWED_URLS);
        final Set<String> allowedUrls = StringUtils.commaDelimitedListToSet(allowedUrlPatterns);
        if (CollectionUtils.isNotEmpty(csrfAllowedUrlPatterns)) {
            allowedUrls.addAll(csrfAllowedUrlPatterns);
        }/*from w  ww  .  j  a  v  a2s .  c om*/
        for (final String pattern : allowedUrls) {
            if (servletPath.matches(pattern)) {
                return true;
            }
        }
    }
    return false;
}

From source file:eu.trentorise.smartcampus.permissionprovider.controller.ResourceAccessController.java

/**
 * Check the access to the specified resource using the client app token header
 * @param token//from w  ww.j  a va  2s  . co m
 * @param resourceUri
 * @param request
 * @return
 */
@RequestMapping("/resources/access")
public @ResponseBody Boolean canAccessResource(@RequestHeader("Authorization") String token,
        @RequestParam String scope, HttpServletRequest request) {
    try {
        String parsedToken = resourceFilterHelper.parseTokenFromRequest(request);
        OAuth2Authentication auth = resourceServerTokenServices.loadAuthentication(parsedToken);
        Collection<String> actualScope = auth.getAuthorizationRequest().getScope();
        Collection<String> scopeSet = StringUtils.commaDelimitedListToSet(scope);
        if (actualScope != null && !actualScope.isEmpty() && actualScope.containsAll(scopeSet)) {
            return true;
        }
    } catch (AuthenticationException e) {
        logger.error("Error validating token: " + e.getMessage());
    }
    return false;
}

From source file:com.consol.citrus.admin.service.TestCaseService.java

/**
 * Lists all available Citrus test cases grouped in test packages.
 * @param project/* ww  w .ja v a2  s  . c  o m*/
 * @return
 */
public List<TestGroup> getTestPackages(Project project) {
    Map<String, TestGroup> testPackages = new LinkedHashMap<>();

    List<File> sourceFiles = FileUtils.findFiles(project.getJavaDirectory(),
            StringUtils.commaDelimitedListToSet(project.getSettings().getJavaFilePattern()));
    List<Test> tests = findTests(project, sourceFiles);

    for (Test test : tests) {
        if (!testPackages.containsKey(test.getPackageName())) {
            TestGroup testPackage = new TestGroup();
            testPackage.setName(test.getPackageName());
            testPackages.put(test.getPackageName(), testPackage);
        }

        testPackages.get(test.getPackageName()).getTests().add(test);
    }

    return Arrays.asList(testPackages.values().toArray(new TestGroup[testPackages.size()]));
}

From source file:com.devnexus.ting.model.support.PresentationSearchQuery.java

public static PresentationSearchQuery create(Event event, Long trackId, String trackName,
        String presentationTypeName, String skillLevelName, String presentationTagsAsString) {

    if (trackId == null && trackName == null && presentationTypeName == null && skillLevelName == null
            && presentationTagsAsString == null) {
        return null;
    }/*from  ww w  . j a v a2 s  .  c o m*/

    final PresentationSearchQuery presentationSearchQuery = new PresentationSearchQuery();
    presentationSearchQuery.setEvent(event);

    if (trackId != null) {
        final Track track = new Track();
        track.setId(trackId);
        presentationSearchQuery.setTrack(track);
    } else if (StringUtils.hasText(trackName)) {
        final Track track = new Track();
        track.setName(StringUtils.trimWhitespace(trackName).toLowerCase(Locale.ENGLISH));
        presentationSearchQuery.setTrack(track);
    }

    if (StringUtils.hasText(presentationTypeName)) {
        final PresentationType presentationType = PresentationType
                .valueOf(StringUtils.trimWhitespace(presentationTypeName).toUpperCase(Locale.ENGLISH));
        presentationSearchQuery.setPresentationType(presentationType);
    }

    if (StringUtils.hasText(skillLevelName)) {
        final SkillLevel skillLevel = SkillLevel
                .valueOf(StringUtils.trimWhitespace(skillLevelName).toUpperCase(Locale.ENGLISH));
        presentationSearchQuery.setSkillLevel(skillLevel);
    }

    if (StringUtils.hasText(presentationTagsAsString)) {

        final Set<String> tagNames = StringUtils.commaDelimitedListToSet(presentationTagsAsString);

        for (String tagName : tagNames) {
            PresentationTag presentationTag = new PresentationTag();
            presentationTag.setName(tagName);
            presentationSearchQuery.getPresentationTags().add(presentationTag);
        }
    }

    return presentationSearchQuery;
}

From source file:net.prasenjit.auth.domain.Client.java

/** {@inheritDoc} */
@Override
public Set<String> getRegisteredRedirectUri() {
    return StringUtils.commaDelimitedListToSet(redirectUri);
}

From source file:org.cloudfoundry.identity.uaa.oauth.UaaAuthorizationRequestManagerTests.java

@Test
public void testScopeDefaultsToAuthoritiesForClientCredentials() {
    client.setAuthorities(AuthorityUtils.commaSeparatedStringToAuthorityList("foo.bar,spam.baz"));
    parameters.put("grant_type", "client_credentials");
    AuthorizationRequest request = factory.createAuthorizationRequest(parameters);
    assertEquals(StringUtils.commaDelimitedListToSet("foo.bar,spam.baz"), request.getScope());
}

From source file:org.elasticsoftware.elasticactors.configuration.BackplaneConfiguration.java

@PostConstruct
public void initialize() {
    String cassandraHosts = env.getProperty("ea.cassandra.hosts", "localhost:9042");
    String cassandraClusterName = env.getProperty("ea.cassandra.cluster", "ElasticActorsCluster");
    String cassandraKeyspaceName = env.getProperty("ea.cassandra.keyspace", "\"ElasticActors\"");
    Integer cassandraPort = env.getProperty("ea.cassandra.port", Integer.class, 9042);

    Set<String> hostSet = StringUtils.commaDelimitedListToSet(cassandraHosts);

    String[] contactPoints = new String[hostSet.size()];
    int i = 0;//from   w  w  w. jav a  2 s  .co  m
    for (String host : hostSet) {
        if (host.contains(":")) {
            contactPoints[i] = host.substring(0, host.indexOf(":"));
        } else {
            contactPoints[i] = host;
        }
        i += 1;
    }

    PoolingOptions poolingOptions = new PoolingOptions();
    poolingOptions.setHeartbeatIntervalSeconds(60);
    poolingOptions.setConnectionsPerHost(HostDistance.LOCAL, 2, env.getProperty("ea.cassandra.maxActive",
            Integer.class, Runtime.getRuntime().availableProcessors() * 3));
    poolingOptions.setPoolTimeoutMillis(2000);

    Cluster cassandraCluster = Cluster.builder().withClusterName(cassandraClusterName)
            .addContactPoints(contactPoints).withPort(cassandraPort)
            .withLoadBalancingPolicy(new RoundRobinPolicy())
            .withRetryPolicy(new LoggingRetryPolicy(DefaultRetryPolicy.INSTANCE))
            .withPoolingOptions(poolingOptions)
            .withReconnectionPolicy(new ConstantReconnectionPolicy(
                    env.getProperty("ea.cassandra.retryDownedHostsDelayInSeconds", Integer.class, 1) * 1000))
            .withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.QUORUM)).build();

    this.cassandraSession = cassandraCluster.connect(cassandraKeyspaceName);

}

From source file:com.consol.citrus.admin.service.TestCaseService.java

/**
 * List test names of latest, meaning newest or last modified tests in project.
 *
 * @param project/*from   ww w. j av a  2 s  . c  o m*/
 * @return
 */
public List<TestGroup> getLatest(Project project, int limit) {
    Map<String, TestGroup> grouped = new LinkedHashMap<>();

    List<File> sourceFiles = FileUtils.findFiles(project.getJavaDirectory(),
            StringUtils.commaDelimitedListToSet(project.getSettings().getJavaFilePattern()));
    sourceFiles = sourceFiles.stream().sorted((f1, f2) -> f1.lastModified() >= f2.lastModified() ? -1 : 1)
            .limit(limit).collect(Collectors.toList());

    List<Test> tests = findTests(project, sourceFiles);
    for (Test test : tests) {
        if (!grouped.containsKey(test.getClassName())) {
            TestGroup testGroup = new TestGroup();
            testGroup.setName(test.getClassName());
            grouped.put(test.getClassName(), testGroup);
        }

        grouped.get(test.getClassName()).getTests().add(test);
    }

    return Arrays.asList(grouped.values().toArray(new TestGroup[grouped.size()]));
}

From source file:org.apigw.monitoring.web.controller.ActionsController.java

@RequestMapping("/resource")
@ResponseStatus(HttpStatus.OK)//w  w  w .j  a va  2 s  .  c o m
public Actions getResourceEvents(@RequestParam(value = "user", required = false) String user) {
    log.debug("Listing resource events for user: {}", user);
    List<Action> actions = new ArrayList<>();
    final List<ResourceEvent> resourceEvents = resourceEventRepository.findByUser(user);
    for (ResourceEvent resourceEvent : resourceEvents) {
        Action action = new Action();
        action.setClient(resourceEvent.getClient());
        action.setUser(resourceEvent.getUser());
        action.setId(resourceEvent.getId().toString());
        action.setMessage(resourceEvent.getMessage());
        action.setScope(StringUtils.commaDelimitedListToSet(resourceEvent.getScopes()));
        action.setService(resourceEvent.getEventType().name());
        if (resourceEvent.getRequestState() != null) {
            action.setState(resourceEvent.getRequestState().toString());
        } else {
            action.setState("");
        }
        action.setTimestamp(resourceEvent.getTimestamp());
        actions.add(action);
    }
    return new Actions(actions);
}

From source file:com.davidak.bet.XmppAppender.java

private static Set<String> parseContacts(String contacts) {
    return StringUtils.commaDelimitedListToSet(contacts);
}