Search in sources :

Example 1 with StringUtils.containsIgnoreCase

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");
    });
}
Also used : AccountRuleConf(org.apache.syncope.common.lib.policy.AccountRuleConf) AccountRule(org.apache.syncope.core.persistence.api.dao.AccountRule) AccountRuleConfClass(org.apache.syncope.core.persistence.api.dao.AccountRuleConfClass) User(org.apache.syncope.core.persistence.api.entity.user.User) Pattern(java.util.regex.Pattern) AccountPolicyException(org.apache.syncope.core.provisioning.api.utils.policy.AccountPolicyException) DefaultAccountRuleConf(org.apache.syncope.common.lib.policy.DefaultAccountRuleConf) StringUtils(org.apache.commons.lang3.StringUtils) Transactional(org.springframework.transaction.annotation.Transactional) Pattern(java.util.regex.Pattern) AccountPolicyException(org.apache.syncope.core.provisioning.api.utils.policy.AccountPolicyException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with StringUtils.containsIgnoreCase

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]));
        }
    }
}
Also used : Locale(java.util.Locale) SystemDefaults(org.apache.commons.lang3.test.SystemDefaults) Test(org.junit.Test)

Example 3 with StringUtils.containsIgnoreCase

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);
}
Also used : ProviderDataAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor) IntegrationException(com.synopsys.integration.exception.IntegrationException) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) BlackDuckResponse(com.synopsys.integration.blackduck.api.core.BlackDuckResponse) BlackDuckPageDefinition(com.synopsys.integration.blackduck.http.BlackDuckPageDefinition) LoggerFactory(org.slf4j.LoggerFactory) ProviderUserModel(com.synopsys.integration.alert.common.persistence.model.ProviderUserModel) Autowired(org.springframework.beans.factory.annotation.Autowired) ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) StringUtils(org.apache.commons.lang3.StringUtils) BlackDuckMultipleRequest(com.synopsys.integration.blackduck.service.request.BlackDuckMultipleRequest) IntLogger(com.synopsys.integration.log.IntLogger) HttpUrl(com.synopsys.integration.rest.HttpUrl) ArrayList(java.util.ArrayList) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) Map(java.util.Map) UrlMultipleResponses(com.synopsys.integration.blackduck.api.core.response.UrlMultipleResponses) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) BlackDuckPageResponse(com.synopsys.integration.blackduck.http.BlackDuckPageResponse) BlackDuckPropertiesFactory(com.synopsys.integration.alert.provider.blackduck.factory.BlackDuckPropertiesFactory) BlackDuckQuery(com.synopsys.integration.blackduck.http.BlackDuckQuery) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) Collectors(java.util.stream.Collectors) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) BlackDuckResponsesTransformer(com.synopsys.integration.blackduck.http.transform.BlackDuckResponsesTransformer) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) Nullable(org.jetbrains.annotations.Nullable) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) List(java.util.List) Component(org.springframework.stereotype.Component) ProjectUsersService(com.synopsys.integration.blackduck.service.dataservice.ProjectUsersService) ThrowingSupplier(com.synopsys.integration.function.ThrowingSupplier) Optional(java.util.Optional) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) UserService(com.synopsys.integration.blackduck.service.dataservice.UserService) ProviderUserModel(com.synopsys.integration.alert.common.persistence.model.ProviderUserModel) ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)

Aggregations

AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)1 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)1 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)1 ProviderDataAccessor (com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor)1 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)1 ProviderProject (com.synopsys.integration.alert.common.persistence.model.ProviderProject)1 ProviderUserModel (com.synopsys.integration.alert.common.persistence.model.ProviderUserModel)1 AlertPagedModel (com.synopsys.integration.alert.common.rest.model.AlertPagedModel)1 BlackDuckPropertiesFactory (com.synopsys.integration.alert.provider.blackduck.factory.BlackDuckPropertiesFactory)1 BlackDuckResponse (com.synopsys.integration.blackduck.api.core.BlackDuckResponse)1 UrlMultipleResponses (com.synopsys.integration.blackduck.api.core.response.UrlMultipleResponses)1 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)1 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)1 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)1 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)1 BlackDuckPageDefinition (com.synopsys.integration.blackduck.http.BlackDuckPageDefinition)1 BlackDuckPageResponse (com.synopsys.integration.blackduck.http.BlackDuckPageResponse)1 BlackDuckQuery (com.synopsys.integration.blackduck.http.BlackDuckQuery)1 BlackDuckRequestBuilder (com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder)1 BlackDuckHttpClient (com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient)1