/** * Creates the pattern. Matching is by default * case insensitive. * * @param pattern the pattern, may not be null. * @return the pattern or or {@link RegexUtils#MATCH_NOTHING_PATTERN} * if pattern is null or invalid. */ public static Pattern createPattern(final String pattern) { return createPattern(pattern, Pattern.CASE_INSENSITIVE); }
@Override public Pattern convert(final String source) { if (StringUtils.isBlank(source)) { return null; } return RegexUtils.createPattern(source); } }
/** * Attempts to find the next sub-sequence of the input sequence that matches the pattern. * * @param pattern the pattern * @param string the string * @return the boolean */ public static boolean find(final String pattern, final String string) { return createPattern(pattern, Pattern.CASE_INSENSITIVE).matcher(string).find(); }
@Override public boolean matches(final String serviceId) { if (this.servicePattern == null) { this.servicePattern = RegexUtils.createPattern(this.serviceId); } return StringUtils.isBlank(serviceId) ? false : this.servicePattern.matcher(serviceId).matches(); }
/** * Concatenate all elements in the given collection to form a regex pattern. * * @param requiredValues the required values * @param caseInsensitive the case insensitive * @return the pattern */ public static Pattern concatenate(final Collection<?> requiredValues, final boolean caseInsensitive) { val pattern = requiredValues .stream() .map(Object::toString) .collect(Collectors.joining("|", "(", ")")); return createPattern(pattern, caseInsensitive ? Pattern.CASE_INSENSITIVE : 0); }
public RegexPrincipalNameTransformer(final String pattern) { setPattern(RegexUtils.createPattern(pattern)); }
/** * Create pattern for mapped attribute pattern. * * @param attributeName the attribute name * @return the pattern */ protected Collection<Pattern> createPatternForMappedAttribute(final String attributeName) { val matchingPattern = patterns.get(attributeName).toString(); val pattern = RegexUtils.createPattern(matchingPattern, this.caseInsensitive ? Pattern.CASE_INSENSITIVE : 0); LOGGER.debug("Created pattern for mapped attribute filter [{}]", pattern.pattern()); return CollectionUtils.wrap(pattern); }
private Pair<Pattern, String> mapPattern(final Object p) { val patternValue = p.toString(); val index = patternValue.indexOf("->"); if (index != -1) { val patternStr = patternValue.substring(0, index).trim(); val pattern = RegexUtils.createPattern(patternStr, isCaseInsensitive() ? Pattern.CASE_INSENSITIVE : 0); val returnValue = patternValue.substring(index + 2).trim(); LOGGER.debug("Created attribute filter pattern [{}] with the mapped return value template [{}]", patternStr, returnValue); return Pair.of(pattern, returnValue); } val pattern = RegexUtils.createPattern(patternValue.trim(), isCaseInsensitive() ? Pattern.CASE_INSENSITIVE : 0); LOGGER.debug("Created attribute filter pattern [{}] without a mapped return value template", pattern.pattern()); return Pair.of(pattern, StringUtils.EMPTY); } }
@Override protected Map<String, Object> getAttributesForSamlRegisteredService(final Map<String, Object> attributes, final SamlRegisteredService service, final ApplicationContext applicationContext, final SamlRegisteredServiceCachingMetadataResolver resolver, final SamlRegisteredServiceServiceProviderMetadataFacade facade, final EntityDescriptor entityDescriptor) { val pattern = RegexUtils.createPattern(this.entityIds); val entityID = entityDescriptor.getEntityID(); val matcher = pattern.matcher(entityID); val matched = fullMatch ? matcher.matches() : matcher.find(); LOGGER.debug("Pattern [{}] matched against [{}]? [{}]", pattern.pattern(), entityID, BooleanUtils.toStringYesNo(matched)); if (matched) { return authorizeReleaseOfAllowedAttributes(attributes); } return new HashMap<>(0); } }
public DefaultMultifactorAuthenticationProviderBypass(final MultifactorAuthenticationProviderBypassProperties bypassProperties) { this.bypassProperties = bypassProperties; if (StringUtils.isNotBlank(bypassProperties.getHttpRequestRemoteAddress())) { this.httpRequestRemoteAddressPattern = RegexUtils.createPattern(bypassProperties.getHttpRequestRemoteAddress()); } else { this.httpRequestRemoteAddressPattern = RegexUtils.MATCH_NOTHING_PATTERN; } val values = org.springframework.util.StringUtils.commaDelimitedListToSet(bypassProperties.getHttpRequestHeaders()); this.httpRequestHeaderPatterns = values.stream().map(RegexUtils::createPattern).collect(Collectors.toSet()); }
private void initializeRegistry(final Path configDirectory, final Collection<StringSerializer<RegisteredService>> serializers, final boolean enableWatcher, final RegisteredServiceReplicationStrategy registeredServiceReplicationStrategy, final RegisteredServiceResourceNamingStrategy resourceNamingStrategy) { this.registeredServiceReplicationStrategy = ObjectUtils.defaultIfNull(registeredServiceReplicationStrategy, new NoOpRegisteredServiceReplicationStrategy()); this.resourceNamingStrategy = ObjectUtils.defaultIfNull(resourceNamingStrategy, new DefaultRegisteredServiceResourceNamingStrategy()); this.registeredServiceSerializers = serializers; val pattern = String.join("|", getExtensions()); this.serviceFileNamePattern = RegexUtils.createPattern(PATTERN_REGISTERED_SERVICE_FILE_NAME.concat(pattern)); LOGGER.trace("Constructed service name file pattern [{}]", serviceFileNamePattern.pattern()); this.serviceRegistryDirectory = configDirectory; val file = this.serviceRegistryDirectory.toFile(); Assert.isTrue(file.exists(), this.serviceRegistryDirectory + " does not exist"); Assert.isTrue(file.isDirectory(), this.serviceRegistryDirectory + " is not a directory"); LOGGER.trace("Service registry directory is specified at [{}]", file); if (enableWatcher) { enableServicesDirectoryPathWatcher(); } }
/** * Search for property. * * @param name the name * @return the response entity */ @ReadOperation public List<ConfigurationMetadataSearchResult> search(@Selector final String name) { val allProps = repository.getRepository().getAllProperties(); if (StringUtils.isNotBlank(name) && RegexUtils.isValidRegex(name)) { val names = StreamSupport.stream(RelaxedPropertyNames.forCamelCase(name).spliterator(), false) .map(Object::toString) .collect(Collectors.joining("|")); val pattern = RegexUtils.createPattern(names); return allProps.entrySet() .stream() .filter(propEntry -> RegexUtils.find(pattern, propEntry.getKey())) .map(propEntry -> new ConfigurationMetadataSearchResult(propEntry.getValue(), repository)) .sorted() .collect(Collectors.toList()); } return new ArrayList<>(); } }
@Bean @RefreshScope @ConditionalOnMissingBean(name = "x509CredentialsAuthenticationHandler") public AuthenticationHandler x509CredentialsAuthenticationHandler() { val x509 = casProperties.getAuthn().getX509(); val revChecker = getRevocationCheckerFrom(x509); val subjectDnPattern = StringUtils.isNotBlank(x509.getRegExSubjectDnPattern()) ? RegexUtils.createPattern(x509.getRegExSubjectDnPattern()) : null; val trustedIssuerDnPattern = StringUtils.isNotBlank(x509.getRegExTrustedIssuerDnPattern()) ? RegexUtils.createPattern(x509.getRegExTrustedIssuerDnPattern()) : null; return new X509CredentialsAuthenticationHandler( x509.getName(), servicesManager.getIfAvailable(), x509PrincipalFactory(), trustedIssuerDnPattern, x509.getMaxPathLength(), x509.isMaxPathLengthAllowUnspecified(), x509.isCheckKeyUsage(), x509.isRequireKeyUsage(), subjectDnPattern, revChecker, x509.getOrder()); }