use of org.apache.commons.lang3.StringUtils.containsIgnoreCase in project syncope by apache.
the class DefaultAccountRule method enforce.
@Transactional(readOnly = true)
@Override
public void enforce(final User user) {
this.conf.getSchemasNotPermitted().stream().map(schema -> user.getPlainAttr(schema)).filter(attr -> attr.isPresent()).map(attr -> attr.get().getValuesAsStrings()).filter(values -> (values != null && !values.isEmpty())).forEachOrdered(values -> this.conf.getWordsNotPermitted().add(values.get(0)));
if (user.getUsername() == null) {
throw new AccountPolicyException("Invalid account");
}
// check min length
if (this.conf.getMinLength() > 0 && this.conf.getMinLength() > user.getUsername().length()) {
throw new AccountPolicyException("Username too short");
}
// check max length
if (this.conf.getMaxLength() > 0 && this.conf.getMaxLength() < user.getUsername().length()) {
throw new AccountPolicyException("Username too long");
}
// check words not permitted
this.conf.getWordsNotPermitted().stream().filter(word -> StringUtils.containsIgnoreCase(user.getUsername(), word)).forEachOrdered(item -> {
throw new AccountPolicyException("Used word(s) not permitted");
});
// check case
if (this.conf.isAllUpperCase() && !user.getUsername().equals(user.getUsername().toUpperCase())) {
throw new AccountPolicyException("No lowercase characters permitted");
}
if (this.conf.isAllLowerCase() && !user.getUsername().equals(user.getUsername().toLowerCase())) {
throw new AccountPolicyException("No uppercase characters permitted");
}
// check pattern
Pattern pattern = (this.conf.getPattern() == null) ? DEFAULT_PATTERN : Pattern.compile(this.conf.getPattern());
if (!pattern.matcher(user.getUsername()).matches()) {
throw new AccountPolicyException("Username does not match pattern");
}
// check prefix
this.conf.getPrefixesNotPermitted().stream().filter(prefix -> user.getUsername().startsWith(prefix)).forEachOrdered(item -> {
throw new AccountPolicyException("Prefix not permitted");
});
// check suffix
this.conf.getSuffixesNotPermitted().stream().filter(suffix -> user.getUsername().endsWith(suffix)).forEachOrdered(item -> {
throw new AccountPolicyException("Suffix not permitted");
});
}
use of org.apache.commons.lang3.StringUtils.containsIgnoreCase in project commons-lang by apache.
the class StringUtilsContainsTest method testContainsIgnoreCase_LocaleIndependence.
@SystemDefaults(locale = "de_DE")
@Test
public void testContainsIgnoreCase_LocaleIndependence() {
final Locale[] locales = { Locale.ENGLISH, new Locale("tr"), Locale.getDefault() };
final String[][] tdata = { { "i", "I" }, { "I", "i" }, { "\u03C2", "\u03C3" }, { "\u03A3", "\u03C2" }, { "\u03A3", "\u03C3" } };
final String[][] fdata = { { "\u00DF", "SS" } };
for (final Locale testLocale : locales) {
Locale.setDefault(testLocale);
for (int j = 0; j < tdata.length; j++) {
assertTrue(Locale.getDefault() + ": " + j + " " + tdata[j][0] + " " + tdata[j][1], StringUtils.containsIgnoreCase(tdata[j][0], tdata[j][1]));
}
for (int j = 0; j < fdata.length; j++) {
assertFalse(Locale.getDefault() + ": " + j + " " + fdata[j][0] + " " + fdata[j][1], StringUtils.containsIgnoreCase(fdata[j][0], fdata[j][1]));
}
}
}
use of org.apache.commons.lang3.StringUtils.containsIgnoreCase in project hub-alert by blackducksoftware.
the class BlackDuckProviderDataAccessor method retrieveUsersForProvider.
private AlertPagedModel<ProviderUserModel> retrieveUsersForProvider(ConfigurationModel blackDuckConfigurationModel, int pageNumber, int pageSize, String searchTerm) throws IntegrationException {
BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(blackDuckConfigurationModel);
Predicate<UserView> searchFilter = userView -> StringUtils.isNotBlank(userView.getEmail());
if (StringUtils.isNotBlank(searchTerm)) {
searchFilter = searchFilter.and(userView -> StringUtils.containsIgnoreCase(userView.getEmail(), searchTerm));
}
ApiDiscovery apiDiscovery = blackDuckServicesFactory.getApiDiscovery();
BlackDuckPageResponse<UserView> pageOfUsers = retrieveBlackDuckPageResponse(blackDuckServicesFactory, apiDiscovery.metaUsersLink(), pageNumber, pageSize, searchFilter);
List<ProviderUserModel> foundUsers = pageOfUsers.getItems().stream().map(UserView::getEmail).map(email -> new ProviderUserModel(email, false)).collect(Collectors.toList());
// Due to a limitation in the blackduck-common library, the totalCount in the BlackDuckPageResponse does not represent the count the matches the searchFilter. It is the totalCount from Black Duck
int totalPageCount = computeTotalCount(pageOfUsers, pageSize);
return new AlertPagedModel<>(totalPageCount, pageNumber, pageSize, foundUsers);
}
Aggregations