List of usage examples for org.springframework.util StringUtils split
@Nullable public static String[] split(@Nullable String toSplit, @Nullable String delimiter)
From source file:com.mycompany.apps.oauth2.authentication.security.LogoutImpl.java
/** * ????<br>//from w ww. j a v a 2 s . co m * ????? * * @param paramHttpServletRequest * @param paramHttpServletResponse * @param paramAuthentication * @throws IOException * @throws ServletException */ @Override public void onLogoutSuccess(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse, Authentication paramAuthentication) throws IOException, ServletException { String tokens = paramHttpServletRequest.getHeader("Authorization"); String values[] = StringUtils.split(tokens, " "); LOG.debug("\n\ttoken type: " + values[0]); LOG.debug("\n\ttoken: " + values[1]); String accessTokenId = null; String refreshTokenId = null; if (values.length != 2) { return; } if (values[1] != null) { accessTokenId = values[1]; } else { return; } // ? OAuth2AccessToken accessToken = tokenstore.readAccessToken(accessTokenId); if (accessToken != null) { // ??? OAuth2RefreshToken rt = accessToken.getRefreshToken(); refreshTokenId = rt.getValue(); // ? tokenstore.removeAccessToken(values[1]); LOG.info("\n\tAccess Token Removed Successfully!"); } else { LOG.info("\n\tAccess Token Not Exist(Not Removed)!"); } // ? OAuth2RefreshToken refreshToken = tokenstore.readRefreshToken(refreshTokenId); if (refreshToken != null) { // ? tokenstore.removeRefreshToken(refreshTokenId); LOG.info("\n\tRefresh Token Removed Successfully!"); } else { LOG.info("\n\tRefresh Token Not Exist(Not Removed)!"); } paramHttpServletResponse.getOutputStream().write("\n\tYou Have Logged Out successfully.".getBytes()); }
From source file:com.codeabovelab.dm.common.security.token.SignedTokenServiceBackend.java
static String[] unpack(String strs) { return StringUtils.split(strs, ","); }
From source file:com.codeabovelab.dm.cluman.configs.container.PropertiesParser.java
public void parse(Map<String, Object> map, ContainerSource arg) { for (Map.Entry<String, Object> el : map.entrySet()) { String propKey = el.getKey(); Object elValue = el.getValue(); if (elValue instanceof String) { String val = (String) elValue; String[] split = StringUtils.split(propKey, "."); if (split != null && StringUtils.hasText(val)) { String key = split[1]; switch (split[0]) { case ENV: arg.getEnvironment().add(key + "=" + val); break; case LABELS: arg.getLabels().put(key, val); break; }// w w w . ja v a 2 s.com } else { try { Object value; if (val.contains(":")) { value = parseMap(val); } else if (val.contains(",")) { value = parseList(val); } else { value = el.getValue(); } BeanUtils.setProperty(arg, propKey, value); } catch (Exception e) { LOG.error("can't set value {} to property {}", propKey, el.getValue()); } } } } LOG.info("Result of parsing {}", arg); }
From source file:org.agatom.springatom.data.xml.OXMLConfiguration.java
/** * <p>getJaxbMarshaller.</p> * * @return a {@link org.springframework.oxm.jaxb.Jaxb2Marshaller} object. *//*from w w w .ja v a 2s .c o m*/ @Bean(name = "jaxbMarshaller") @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON) public Jaxb2Marshaller getJaxbMarshaller() { final Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller(); jaxb2Marshaller.setLazyInit(this.environment.getProperty("springatom.oxm.lazyInit", Boolean.class)); jaxb2Marshaller.setPackagesToScan( StringUtils.split(this.environment.getProperty("springatom.oxm.packagesToScan"), ",")); jaxb2Marshaller.setCheckForXmlRootElement(true); jaxb2Marshaller.setProcessExternalEntities(true); return jaxb2Marshaller; }
From source file:your.microservice.core.util.YourServletUriComponentsBuilder.java
/** * Prepare a builder by copying the scheme, host, port, path, and * query string of an HttpServletRequest. * @param request to build path from/*from w w w .j av a 2s. c o m*/ * @return a URI component builder */ public static YourServletUriComponentsBuilder fromRequest(HttpServletRequest request) { String scheme = request.getScheme(); String host = request.getServerName(); int port = request.getServerPort(); String hostHeader = request.getHeader("X-Forwarded-Host"); if (StringUtils.hasText(hostHeader)) { String[] hosts = StringUtils.commaDelimitedListToStringArray(hostHeader); String hostToUse = hosts[0]; if (hostToUse.contains(":")) { String[] hostAndPort = StringUtils.split(hostToUse, ":"); host = hostAndPort[0]; port = Integer.parseInt(hostAndPort[1]); } else { host = hostToUse; port = -1; } } String portHeader = request.getHeader("X-Forwarded-Port"); if (StringUtils.hasText(portHeader)) { port = Integer.parseInt(portHeader); } String protocolHeader = request.getHeader("X-Forwarded-Proto"); if (StringUtils.hasText(protocolHeader)) { scheme = protocolHeader; } YourServletUriComponentsBuilder builder = new YourServletUriComponentsBuilder(); builder.scheme(scheme); builder.host(host); if (scheme.equals("http") && port != 80 || scheme.equals("https") && port != 443) { builder.port(port); } builder.pathFromRequest(request); builder.query(request.getQueryString()); return builder; }
From source file:net.opentsdb.contrib.tsquare.ExtendedTsdbMetricParser.java
private Metric parseSingleMetricWithoutTags(final String metricString) { Metric metric = null;// w ww . j a v a 2 s.c o m if (metricString.indexOf(':') < 0) { // EXTENSION: This is a metric only expression. We auto-detect the aggregator // based on the metric name, or use the default. Aggregator agg = aggregatorFactory.getAggregatorForMetric(metricString); metric = new Metric(metricString, metricString, (agg == null ? defaultAggregator : agg)); } else { // Otherwise, this might be a standard expression with some extra sauce... final String[] parts = StringUtils.delimitedListToStringArray(metricString, ":"); Preconditions.checkState(parts.length > 1, "Invalid metric: %s", metricString); // Metric name is always the last element, regardless of format. ASSUMING we've stripped // tag expressions off the end. final String metricName = parts[parts.length - 1]; // EXTENSION: Logic in determineAggregator() allows for empty or auto-detect // aggregators. See the doc on that method for details. metric = new Metric(metricString, metricName, determineAggregator(metricName, parts[0])); // Handle parsing of rate and downsampler. if (parts.length > 2 && parts.length <= 4) { for (int i = 1; i < parts.length - 1; i++) { final String p = parts[i]; if ("rate".equals(p)) { metric.setRate(true); } else if (Character.isDefined(p.charAt(0)) && p.indexOf('-') > 0) { // 1h-sum final String[] downsampleParts = StringUtils.split(p, "-"); long downsampleMillis = new DateTimeExpressionParser().setBaseTimeMillis(0) // ... parse a relative duration .setPositiveOffset(true).parseRequired(downsampleParts[0]); // Convert to epoch SECONDS. metric.setDownsampleIntervalSeconds( (int) TimeUnit.MILLISECONDS.toSeconds(downsampleMillis)); // EXTENSION: Again, determineAggregator() allows for empty or auto-detected // downsamplers. metric.setDownsampler(determineAggregator(metricName, downsampleParts[1])); } else { throw new IllegalStateException("Invalid characters in metric: " + p); } } } else if (parts.length != 2) { throw new IllegalStateException("Metric has invalid parsed length: " + parts.length); } } return metric; }
From source file:org.bitsofinfo.util.address.usps.ais.DefaultIdGenerator.java
@Override public Class<? extends USPSRecord> getRecordType(String identifier) { String prefix = StringUtils.split(identifier, "-")[0]; Class clazz = prefixCache.get(prefix); return clazz; }
From source file:tv.arte.resteventapi.core.presentation.decoration.RestEventApiControllerLinkBuilder.java
/** * Returns a {@link UriComponentsBuilder} obtained from the current servlet mapping with the host tweaked in case the * request contains an {@code X-Forwarded-Host} header and the scheme tweaked in case the request contains an * {@code X-Forwarded-Ssl} header/* www.jav a2 s. c o m*/ * * @return */ static UriComponentsBuilder getBuilder() { HttpServletRequest request = getCurrentRequest(); ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromServletMapping(request); String forwardedSsl = request.getHeader("X-Forwarded-Ssl"); if (StringUtils.hasText(forwardedSsl) && forwardedSsl.equalsIgnoreCase("on")) { builder.scheme("https"); } String host = request.getHeader("X-Forwarded-Host"); if (!StringUtils.hasText(host)) { return builder; } String[] hosts = StringUtils.commaDelimitedListToStringArray(host); String hostToUse = hosts[0]; if (hostToUse.contains(":")) { String[] hostAndPort = StringUtils.split(hostToUse, ":"); builder.host(hostAndPort[0]); builder.port(Integer.parseInt(hostAndPort[1])); } else { builder.host(hostToUse); builder.port(-1); // reset port if it was forwarded from default port } String port = request.getHeader("X-Forwarded-Port"); if (StringUtils.hasText(port)) { builder.port(Integer.parseInt(port)); } return builder; }
From source file:org.ihtsdo.otf.refset.security.RefsetIdentityService.java
/** * Gets a minimal {@link Authentication} object from {@link Token}. * It is only possible if that Token exist. At the moment ROLE_USER is defaulted * @return/*from w ww . ja v a2 s. c o m*/ */ protected Authentication getPrincipal(Token token) { String info = token.getExtendedInformation(); String[] details = StringUtils.split(info, ":"); User user = new User(); user.setPassword(details[1]); user.setUsername(details[0]); user.setAuthenticated(true); user.setEnabled(true); Collection<RefsetRole> roles = new ArrayList<RefsetRole>(); RefsetRole role = new RefsetRole(); role.setAuthority(ROLE_USER); roles.add(role); user.setAuthorities(roles); Authentication auth = new UsernamePasswordAuthenticationToken(user, details[1], roles); return auth; }
From source file:com.ephesoft.dcma.core.hibernate.EphesoftCriteria.java
private String[] split(String associationPath) { String[] involvedEntitiyVars = StringUtils.split(associationPath, CoreConstants.DOT); if (involvedEntitiyVars == null) { involvedEntitiyVars = new String[1]; involvedEntitiyVars[0] = associationPath; }/*from ww w . j a v a 2 s . c o m*/ return involvedEntitiyVars; }