/** * 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 boolean isAllowedProxyCallbackUrl(final URL pgtUrl) { return RegexUtils.find(this.pattern, pgtUrl.toExternalForm()); } }
/** * Init the policy with the pgt url regex pattern that * will determine the urls allowed to receive the pgt. * The matching by default is done in a case insensitive manner. * * @param pgtUrlPattern the pgt url pattern */ @JsonCreator public RegexMatchingRegisteredServiceProxyPolicy(@JsonProperty("pattern") final String pgtUrlPattern) { if (RegexUtils.isValidRegex(pgtUrlPattern)) { this.pattern = pgtUrlPattern; } else { LOGGER.warn("Pattern specified [{}] is not a valid regular expression", pgtUrlPattern); this.pattern = RegexUtils.MATCH_NOTHING_PATTERN.pattern(); } }
/** * 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<>(); } }
/** * Filter attribute values by pattern and return the list. * * @param attributeValues the attribute values * @param pattern the pattern * @return the list */ protected List<Object> filterAttributeValuesByPattern(final Set<Object> attributeValues, final Pattern pattern) { return attributeValues.stream().filter(v -> RegexUtils.matches(pattern, v.toString(), completeMatch)).collect(Collectors.toList()); }
private boolean requiredAttributeFound(final String attributeName, final Map<String, Object> principalAttributes, final Map<String, Set<String>> requiredAttributes) { val values = requiredAttributes.get(attributeName); val availableValues = CollectionUtils.toCollection(principalAttributes.get(attributeName)); val pattern = RegexUtils.concatenate(values, this.caseInsensitive); LOGGER.debug("Checking [{}] against [{}] with pattern [{}] for attribute [{}]", values, availableValues, pattern, attributeName); if (pattern != RegexUtils.MATCH_NOTHING_PATTERN) { return availableValues.stream().map(Object::toString).anyMatch(pattern.asPredicate()); } return availableValues.stream().anyMatch(values::contains); } }
if (!RegexUtils.matches(this.serviceFileNamePattern, fileName)) { LOGGER.warn("[{}] does not match the recommended pattern [{}]. " + "While CAS tries to be forgiving as much as possible, it's recommended "
@Override public Pattern convert(final String source) { if (StringUtils.isBlank(source)) { return null; } return RegexUtils.createPattern(source); } }
@Override public boolean isValid(final UsernamePasswordCredential c, final PasswordChangeBean bean) { if (StringUtils.isEmpty(bean.getPassword())) { LOGGER.error("Provided password is blank"); return false; } if (!bean.getPassword().equals(bean.getConfirmedPassword())) { LOGGER.error("Provided password does not match the confirmed password"); return false; } if (!RegexUtils.find(policyPattern, bean.getPassword())) { LOGGER.error("Provided password does not match the pattern required for password policy [{}}", policyPattern); return false; } return true; } }
private static void buildPredicateFilterIfNeeded(final SamlRegisteredService service, final List<MetadataFilter> metadataFilterList) { if (StringUtils.isNotBlank(service.getMetadataCriteriaDirection()) && StringUtils.isNotBlank(service.getMetadataCriteriaPattern()) && RegexUtils.isValidRegex(service.getMetadataCriteriaPattern())) { val dir = PredicateFilter.Direction.valueOf(service.getMetadataCriteriaDirection()); LOGGER.debug("Metadata predicate filter configuring with direction [{}] and pattern [{}]", service.getMetadataCriteriaDirection(), service.getMetadataCriteriaPattern()); val filter = new PredicateFilter(dir, entityDescriptor -> StringUtils.isNotBlank(entityDescriptor.getEntityID()) && entityDescriptor.getEntityID().matches(service.getMetadataCriteriaPattern())); metadataFilterList.add(filter); LOGGER.debug("Added metadata predicate filter with direction [{}] and pattern [{}]", service.getMetadataCriteriaDirection(), service.getMetadataCriteriaPattern()); } }
/** * 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(); }
val name = entry.getName(); LOGGER.trace("Comparing [{}] against [{}] and pattern [{}]", name, resource.getFilename(), containsName); if (name.contains(resource.getFilename()) && RegexUtils.find(containsName, name)) { try (val stream = jFile.getInputStream(entry)) { var copyDestination = destination;
@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(); } }