Search in sources :

Example 1 with StringUtils.isNoneBlank

use of org.apache.commons.lang3.StringUtils.isNoneBlank in project cas by apereo.

the class LdapUtils method newLdaptivePooledConnectionFactory.

/**
 * New pooled connection factory pooled connection factory.
 *
 * @param l the ldap properties
 * @return the pooled connection factory
 */
public static PooledConnectionFactory newLdaptivePooledConnectionFactory(final AbstractLdapProperties l) {
    val cc = newLdaptiveConnectionConfig(l);
    LOGGER.debug("Creating LDAP connection pool configuration for [{}]", l.getLdapUrl());
    val pooledCf = new PooledConnectionFactory(cc);
    pooledCf.setMinPoolSize(l.getMinPoolSize());
    pooledCf.setMaxPoolSize(l.getMaxPoolSize());
    pooledCf.setValidateOnCheckOut(l.isValidateOnCheckout());
    pooledCf.setValidatePeriodically(l.isValidatePeriodically());
    pooledCf.setBlockWaitTime(Beans.newDuration(l.getBlockWaitTime()));
    val strategy = new IdlePruneStrategy();
    strategy.setIdleTime(Beans.newDuration(l.getIdleTime()));
    strategy.setPrunePeriod(Beans.newDuration(l.getPrunePeriod()));
    pooledCf.setPruneStrategy(strategy);
    val validator = l.getValidator();
    switch(validator.getType().trim().toLowerCase()) {
        case "compare":
            val compareRequest = new CompareRequest(validator.getDn(), validator.getAttributeName(), validator.getAttributeValue());
            val compareValidator = new CompareConnectionValidator(compareRequest);
            compareValidator.setValidatePeriod(Beans.newDuration(l.getValidatePeriod()));
            compareValidator.setValidateTimeout(Beans.newDuration(l.getValidateTimeout()));
            pooledCf.setValidator(compareValidator);
            break;
        case "none":
            LOGGER.debug("No validator is configured for the LDAP connection pool of [{}]", l.getLdapUrl());
            break;
        case "search":
        default:
            val searchRequest = new SearchRequest();
            searchRequest.setBaseDn(validator.getBaseDn());
            searchRequest.setFilter(validator.getSearchFilter());
            searchRequest.setReturnAttributes(ReturnAttributes.NONE.value());
            searchRequest.setSearchScope(SearchScope.valueOf(validator.getScope()));
            searchRequest.setSizeLimit(1);
            val searchValidator = new SearchConnectionValidator(searchRequest);
            searchValidator.setValidatePeriod(Beans.newDuration(l.getValidatePeriod()));
            searchValidator.setValidateTimeout(Beans.newDuration(l.getValidateTimeout()));
            pooledCf.setValidator(searchValidator);
            break;
    }
    pooledCf.setFailFastInitialize(l.isFailFast());
    if (StringUtils.isNotBlank(l.getPoolPassivator())) {
        val pass = AbstractLdapProperties.LdapConnectionPoolPassivator.valueOf(l.getPoolPassivator().toUpperCase());
        switch(pass) {
            case BIND:
                if (StringUtils.isNotBlank(l.getBindDn()) && StringUtils.isNoneBlank(l.getBindCredential())) {
                    val bindRequest = new SimpleBindRequest(l.getBindDn(), l.getBindCredential());
                    pooledCf.setPassivator(new BindConnectionPassivator(bindRequest));
                    LOGGER.debug("Created [{}] passivator for [{}]", l.getPoolPassivator(), l.getLdapUrl());
                } else {
                    val values = Arrays.stream(AbstractLdapProperties.LdapConnectionPoolPassivator.values()).filter(v -> v != AbstractLdapProperties.LdapConnectionPoolPassivator.BIND).collect(Collectors.toList());
                    LOGGER.warn("[{}] pool passivator could not be created for [{}] given bind credentials are not specified. " + "If you are dealing with LDAP in such a way that does not require bind credentials, you may need to " + "set the pool passivator setting to one of [{}]", l.getPoolPassivator(), l.getLdapUrl(), values);
                }
                break;
            default:
                break;
        }
    }
    LOGGER.debug("Initializing ldap connection pool for [{}] and bindDn [{}]", l.getLdapUrl(), l.getBindDn());
    pooledCf.initialize();
    return pooledCf;
}
Also used : lombok.val(lombok.val) Arrays(java.util.Arrays) ConnectionFactory(org.ldaptive.ConnectionFactory) AllowAnyTrustManager(org.ldaptive.ssl.AllowAnyTrustManager) SearchOperation(org.ldaptive.SearchOperation) SearchResponse(org.ldaptive.SearchResponse) GroovyPasswordPolicyHandlingStrategy(org.apereo.cas.authentication.support.password.GroovyPasswordPolicyHandlingStrategy) AddRequest(org.ldaptive.AddRequest) AuthenticationPasswordPolicyHandlingStrategy(org.apereo.cas.authentication.AuthenticationPasswordPolicyHandlingStrategy) DnResolver(org.ldaptive.auth.DnResolver) StringUtils(org.apache.commons.lang3.StringUtils) DefaultLdapAccountStateHandler(org.apereo.cas.authentication.support.DefaultLdapAccountStateHandler) ActivePassiveConnectionStrategy(org.ldaptive.ActivePassiveConnectionStrategy) AllowAnyHostnameVerifier(org.ldaptive.ssl.AllowAnyHostnameVerifier) FormatDnResolver(org.ldaptive.auth.FormatDnResolver) CompareConnectionValidator(org.ldaptive.CompareConnectionValidator) Map(java.util.Map) AbstractLdapAuthenticationProperties(org.apereo.cas.configuration.model.support.ldap.AbstractLdapAuthenticationProperties) FreeIPAAuthenticationResponseHandler(org.ldaptive.auth.ext.FreeIPAAuthenticationResponseHandler) ApplicationContextProvider(org.apereo.cas.util.spring.ApplicationContextProvider) SimpleBindAuthenticationHandler(org.ldaptive.auth.SimpleBindAuthenticationHandler) CompareAuthenticationHandler(org.ldaptive.auth.CompareAuthenticationHandler) ConnectionConfig(org.ldaptive.ConnectionConfig) Unchecked(org.jooq.lambda.Unchecked) SaslConfig(org.ldaptive.sasl.SaslConfig) BindConnectionInitializer(org.ldaptive.BindConnectionInitializer) ModifyRequest(org.ldaptive.ModifyRequest) PagedResultsClient(org.ldaptive.control.util.PagedResultsClient) Set(java.util.Set) DnsSrvConnectionStrategy(org.ldaptive.DnsSrvConnectionStrategy) SearchScope(org.ldaptive.SearchScope) StandardCharsets(java.nio.charset.StandardCharsets) Slf4j(lombok.extern.slf4j.Slf4j) AccountNotFoundException(javax.security.auth.login.AccountNotFoundException) FilterTemplate(org.ldaptive.FilterTemplate) AddOperation(org.ldaptive.AddOperation) LdapAttribute(org.ldaptive.LdapAttribute) DisposableBean(org.springframework.beans.factory.DisposableBean) LdapEntry(org.ldaptive.LdapEntry) ObjectGuidHandler(org.ldaptive.ad.handler.ObjectGuidHandler) RangeEntryHandler(org.ldaptive.ad.handler.RangeEntryHandler) User(org.ldaptive.auth.User) ActiveDirectoryLdapEntryHandler(org.apereo.services.persondir.support.ldap.ActiveDirectoryLdapEntryHandler) SearchEntryResolver(org.ldaptive.auth.SearchEntryResolver) ArrayList(java.util.ArrayList) UtilityClass(lombok.experimental.UtilityClass) LinkedHashMap(java.util.LinkedHashMap) SearchDnResolver(org.ldaptive.auth.SearchDnResolver) IdlePruneStrategy(org.ldaptive.pool.IdlePruneStrategy) ModifyOperation(org.ldaptive.ModifyOperation) ActiveDirectoryAuthenticationResponseHandler(org.ldaptive.auth.ext.ActiveDirectoryAuthenticationResponseHandler) FollowSearchReferralHandler(org.ldaptive.referral.FollowSearchReferralHandler) CompareRequest(org.ldaptive.CompareRequest) ServicesManager(org.apereo.cas.services.ServicesManager) MergeResultHandler(org.ldaptive.handler.MergeResultHandler) lombok.val(lombok.val) AttributeModification(org.ldaptive.AttributeModification) SearchRequest(org.ldaptive.SearchRequest) DefaultConnectionFactory(org.ldaptive.DefaultConnectionFactory) RoundRobinConnectionStrategy(org.ldaptive.RoundRobinConnectionStrategy) Mechanism(org.ldaptive.sasl.Mechanism) CaseChangeEntryHandler(org.ldaptive.handler.CaseChangeEntryHandler) PasswordExpirationAuthenticationResponseHandler(org.ldaptive.auth.ext.PasswordExpirationAuthenticationResponseHandler) AuthenticationHandlerResponse(org.ldaptive.auth.AuthenticationHandlerResponse) FastBindConnectionInitializer(org.ldaptive.ad.extended.FastBindConnectionInitializer) KeyStoreCredentialConfig(org.ldaptive.ssl.KeyStoreCredentialConfig) LdapException(org.ldaptive.LdapException) PooledConnectionFactory(org.ldaptive.PooledConnectionFactory) LdapAuthenticationHandler(org.apereo.cas.authentication.LdapAuthenticationHandler) SimpleBindRequest(org.ldaptive.SimpleBindRequest) SetFactoryBean(org.springframework.beans.factory.config.SetFactoryBean) SneakyThrows(lombok.SneakyThrows) UnicodePwdAttribute(org.ldaptive.ad.UnicodePwdAttribute) URL(java.net.URL) RequiredArgsConstructor(lombok.RequiredArgsConstructor) PasswordPolicyContext(org.apereo.cas.authentication.support.password.PasswordPolicyContext) PasswordPolicyAuthenticationRequestHandler(org.ldaptive.auth.ext.PasswordPolicyAuthenticationRequestHandler) Beans(org.apereo.cas.configuration.support.Beans) DerefAliases(org.ldaptive.DerefAliases) FunctionUtils(org.apereo.cas.util.function.FunctionUtils) PrincipalFactory(org.apereo.cas.authentication.principal.PrincipalFactory) ScriptResourceCacheManager(org.apereo.cas.util.scripting.ScriptResourceCacheManager) PasswordModifyRequest(org.ldaptive.extended.PasswordModifyRequest) URI(java.net.URI) DeleteRequest(org.ldaptive.DeleteRequest) SslConfig(org.ldaptive.ssl.SslConfig) PrimaryGroupIdHandler(org.ldaptive.ad.handler.PrimaryGroupIdHandler) X509CredentialConfig(org.ldaptive.ssl.X509CredentialConfig) AbstractLdapProperties(org.apereo.cas.configuration.model.support.ldap.AbstractLdapProperties) DefaultHostnameVerifier(org.ldaptive.ssl.DefaultHostnameVerifier) Collectors(java.util.stream.Collectors) LdapAuthenticationProperties(org.apereo.cas.configuration.model.support.ldap.LdapAuthenticationProperties) Objects(java.util.Objects) DnAttributeEntryHandler(org.ldaptive.handler.DnAttributeEntryHandler) List(java.util.List) DeleteOperation(org.ldaptive.DeleteOperation) SearchResultHandler(org.ldaptive.handler.SearchResultHandler) LdapPasswordPolicyProperties(org.apereo.cas.configuration.model.support.ldap.LdapPasswordPolicyProperties) AuthenticationRequestHandler(org.ldaptive.auth.AuthenticationRequestHandler) CoreAuthenticationUtils(org.apereo.cas.authentication.CoreAuthenticationUtils) EDirectoryAuthenticationResponseHandler(org.ldaptive.auth.ext.EDirectoryAuthenticationResponseHandler) IntStream(java.util.stream.IntStream) PasswordEncoderUtils(org.apereo.cas.authentication.support.password.PasswordEncoderUtils) ReturnAttributes(org.ldaptive.ReturnAttributes) AuthenticationResponse(org.ldaptive.auth.AuthenticationResponse) BindConnectionPassivator(org.ldaptive.pool.BindConnectionPassivator) AuthenticationCriteria(org.ldaptive.auth.AuthenticationCriteria) OptionalWarningLdapAccountStateHandler(org.apereo.cas.authentication.support.OptionalWarningLdapAccountStateHandler) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Multimap(com.google.common.collect.Multimap) AuthenticationHandler(org.ldaptive.auth.AuthenticationHandler) HashSet(java.util.HashSet) EntryResolver(org.ldaptive.auth.EntryResolver) QualityOfProtection(org.ldaptive.sasl.QualityOfProtection) AuthenticationResponseHandler(org.ldaptive.auth.AuthenticationResponseHandler) Period(java.time.Period) PasswordPolicyAuthenticationResponseHandler(org.ldaptive.auth.ext.PasswordPolicyAuthenticationResponseHandler) RandomConnectionStrategy(org.ldaptive.RandomConnectionStrategy) ObjectSidHandler(org.ldaptive.ad.handler.ObjectSidHandler) RejectResultCodeLdapPasswordPolicyHandlingStrategy(org.apereo.cas.authentication.support.RejectResultCodeLdapPasswordPolicyHandlingStrategy) ResultCode(org.ldaptive.ResultCode) WatchableGroovyScriptResource(org.apereo.cas.util.scripting.WatchableGroovyScriptResource) SearchConnectionValidator(org.ldaptive.SearchConnectionValidator) ApplicationContext(org.springframework.context.ApplicationContext) DefaultTrustManager(org.ldaptive.ssl.DefaultTrustManager) Authenticator(org.ldaptive.auth.Authenticator) Credential(org.ldaptive.Credential) MergeAttributeEntryHandler(org.ldaptive.handler.MergeAttributeEntryHandler) LdapSearchEntryHandlersProperties(org.apereo.cas.configuration.model.support.ldap.LdapSearchEntryHandlersProperties) SecurityStrength(org.ldaptive.sasl.SecurityStrength) PrincipalNameTransformerUtils(org.apereo.cas.authentication.principal.PrincipalNameTransformerUtils) DefaultPasswordPolicyHandlingStrategy(org.apereo.cas.authentication.support.password.DefaultPasswordPolicyHandlingStrategy) RecursiveResultHandler(org.ldaptive.handler.RecursiveResultHandler) ExtendedOperation(org.ldaptive.extended.ExtendedOperation) LdapEntryHandler(org.ldaptive.handler.LdapEntryHandler) ExecutableCompiledGroovyScript(org.apereo.cas.util.scripting.ExecutableCompiledGroovyScript) IdlePruneStrategy(org.ldaptive.pool.IdlePruneStrategy) SearchRequest(org.ldaptive.SearchRequest) SearchConnectionValidator(org.ldaptive.SearchConnectionValidator) CompareRequest(org.ldaptive.CompareRequest) SimpleBindRequest(org.ldaptive.SimpleBindRequest) CompareConnectionValidator(org.ldaptive.CompareConnectionValidator) BindConnectionPassivator(org.ldaptive.pool.BindConnectionPassivator) PooledConnectionFactory(org.ldaptive.PooledConnectionFactory)

Example 2 with StringUtils.isNoneBlank

use of org.apache.commons.lang3.StringUtils.isNoneBlank in project cas by apereo.

the class LdapUtils method newLdaptiveBlockingConnectionPool.

/**
 * New blocking connection pool connection pool.
 *
 * @param l the l
 * @return the connection pool
 */
public static ConnectionPool newLdaptiveBlockingConnectionPool(final AbstractLdapProperties l) {
    final DefaultConnectionFactory bindCf = newLdaptiveConnectionFactory(l);
    final PoolConfig pc = newLdaptivePoolConfig(l);
    final BlockingConnectionPool cp = new BlockingConnectionPool(pc, bindCf);
    cp.setBlockWaitTime(Beans.newDuration(l.getBlockWaitTime()));
    cp.setPoolConfig(pc);
    final IdlePruneStrategy strategy = new IdlePruneStrategy();
    strategy.setIdleTime(Beans.newDuration(l.getIdleTime()));
    strategy.setPrunePeriod(Beans.newDuration(l.getPrunePeriod()));
    cp.setPruneStrategy(strategy);
    switch(l.getValidator().getType().trim().toLowerCase()) {
        case "compare":
            final CompareRequest compareRequest = new CompareRequest();
            compareRequest.setDn(l.getValidator().getDn());
            compareRequest.setAttribute(new LdapAttribute(l.getValidator().getAttributeName(), l.getValidator().getAttributeValues().toArray(new String[] {})));
            compareRequest.setReferralHandler(new SearchReferralHandler());
            cp.setValidator(new CompareValidator(compareRequest));
            break;
        case "none":
            LOGGER.debug("No validator is configured for the LDAP connection pool of [{}]", l.getLdapUrl());
            break;
        case "search":
        default:
            final SearchRequest searchRequest = new SearchRequest();
            searchRequest.setBaseDn(l.getValidator().getBaseDn());
            searchRequest.setSearchFilter(new SearchFilter(l.getValidator().getSearchFilter()));
            searchRequest.setReturnAttributes(ReturnAttributes.NONE.value());
            searchRequest.setSearchScope(SearchScope.valueOf(l.getValidator().getScope()));
            searchRequest.setSizeLimit(1L);
            searchRequest.setReferralHandler(new SearchReferralHandler());
            cp.setValidator(new SearchValidator(searchRequest));
            break;
    }
    cp.setFailFastInitialize(l.isFailFast());
    if (StringUtils.isNotBlank(l.getPoolPassivator())) {
        final AbstractLdapProperties.LdapConnectionPoolPassivator pass = AbstractLdapProperties.LdapConnectionPoolPassivator.valueOf(l.getPoolPassivator().toUpperCase());
        switch(pass) {
            case CLOSE:
                cp.setPassivator(new ClosePassivator());
                LOGGER.debug("Created [{}] passivator for [{}]", l.getPoolPassivator(), l.getLdapUrl());
                break;
            case BIND:
                if (StringUtils.isNotBlank(l.getBindDn()) && StringUtils.isNoneBlank(l.getBindCredential())) {
                    final BindRequest bindRequest = new BindRequest();
                    bindRequest.setDn(l.getBindDn());
                    bindRequest.setCredential(new Credential(l.getBindCredential()));
                    cp.setPassivator(new BindPassivator(bindRequest));
                    LOGGER.debug("Created [{}] passivator for [{}]", l.getPoolPassivator(), l.getLdapUrl());
                } else {
                    final List values = Arrays.stream(AbstractLdapProperties.LdapConnectionPoolPassivator.values()).filter(v -> v != AbstractLdapProperties.LdapConnectionPoolPassivator.BIND).collect(Collectors.toList());
                    LOGGER.warn("[{}] pool passivator could not be created for [{}] given bind credentials are not specified. " + "If you are dealing with LDAP in such a way that does not require bind credentials, you may need to " + "set the pool passivator setting to one of [{}]", l.getPoolPassivator(), l.getLdapUrl(), values);
                }
                break;
            default:
                break;
        }
    }
    LOGGER.debug("Initializing ldap connection pool for [{}] and bindDn [{}]", l.getLdapUrl(), l.getBindDn());
    cp.initialize();
    return cp;
}
Also used : Arrays(java.util.Arrays) ConnectionFactory(org.ldaptive.ConnectionFactory) SearchOperation(org.ldaptive.SearchOperation) AddRequest(org.ldaptive.AddRequest) ExternalConfig(org.ldaptive.sasl.ExternalConfig) StringUtils(org.apache.commons.lang3.StringUtils) SearchEntryHandler(org.ldaptive.handler.SearchEntryHandler) ClassUtils(org.apache.commons.lang3.ClassUtils) ActivePassiveConnectionStrategy(org.ldaptive.ActivePassiveConnectionStrategy) FormatDnResolver(org.ldaptive.auth.FormatDnResolver) Map(java.util.Map) AbstractLdapAuthenticationProperties(org.apereo.cas.configuration.model.support.ldap.AbstractLdapAuthenticationProperties) PasswordPolicyControl(org.ldaptive.control.PasswordPolicyControl) ConnectionConfig(org.ldaptive.ConnectionConfig) BindPassivator(org.ldaptive.pool.BindPassivator) SaslConfig(org.ldaptive.sasl.SaslConfig) BindConnectionInitializer(org.ldaptive.BindConnectionInitializer) ModifyRequest(org.ldaptive.ModifyRequest) BlockingConnectionPool(org.ldaptive.pool.BlockingConnectionPool) Set(java.util.Set) PasswordModifyOperation(org.ldaptive.extended.PasswordModifyOperation) DnsSrvConnectionStrategy(org.ldaptive.DnsSrvConnectionStrategy) SearchScope(org.ldaptive.SearchScope) Response(org.ldaptive.Response) StandardCharsets(java.nio.charset.StandardCharsets) Slf4j(lombok.extern.slf4j.Slf4j) AddOperation(org.ldaptive.AddOperation) LdapAttribute(org.ldaptive.LdapAttribute) LdapEntry(org.ldaptive.LdapEntry) CramMd5Config(org.ldaptive.sasl.CramMd5Config) ObjectGuidHandler(org.ldaptive.ad.handler.ObjectGuidHandler) SearchFilter(org.ldaptive.SearchFilter) RangeEntryHandler(org.ldaptive.ad.handler.RangeEntryHandler) ArrayList(java.util.ArrayList) UtilityClass(lombok.experimental.UtilityClass) IdlePruneStrategy(org.ldaptive.pool.IdlePruneStrategy) ModifyOperation(org.ldaptive.ModifyOperation) SearchResult(org.ldaptive.SearchResult) SearchValidator(org.ldaptive.pool.SearchValidator) CompareRequest(org.ldaptive.CompareRequest) AttributeModification(org.ldaptive.AttributeModification) SearchRequest(org.ldaptive.SearchRequest) DefaultConnectionFactory(org.ldaptive.DefaultConnectionFactory) RoundRobinConnectionStrategy(org.ldaptive.RoundRobinConnectionStrategy) Mechanism(org.ldaptive.sasl.Mechanism) CaseChangeEntryHandler(org.ldaptive.handler.CaseChangeEntryHandler) KeyStoreCredentialConfig(org.ldaptive.ssl.KeyStoreCredentialConfig) LdapException(org.ldaptive.LdapException) SearchExecutor(org.ldaptive.SearchExecutor) ClosePassivator(org.ldaptive.pool.ClosePassivator) PooledSearchDnResolver(org.ldaptive.auth.PooledSearchDnResolver) UnicodePwdAttribute(org.ldaptive.ad.UnicodePwdAttribute) URL(java.net.URL) AttributeModificationType(org.ldaptive.AttributeModificationType) Beans(org.apereo.cas.configuration.support.Beans) PooledBindAuthenticationHandler(org.ldaptive.auth.PooledBindAuthenticationHandler) ConnectionPool(org.ldaptive.pool.ConnectionPool) DerefAliases(org.ldaptive.DerefAliases) SearchReferralHandler(org.ldaptive.referral.SearchReferralHandler) PasswordModifyRequest(org.ldaptive.extended.PasswordModifyRequest) DigestMd5Config(org.ldaptive.sasl.DigestMd5Config) URI(java.net.URI) DeleteRequest(org.ldaptive.DeleteRequest) PooledCompareAuthenticationHandler(org.ldaptive.auth.PooledCompareAuthenticationHandler) SslConfig(org.ldaptive.ssl.SslConfig) PoolConfig(org.ldaptive.pool.PoolConfig) PrimaryGroupIdHandler(org.ldaptive.ad.handler.PrimaryGroupIdHandler) X509CredentialConfig(org.ldaptive.ssl.X509CredentialConfig) AbstractLdapProperties(org.apereo.cas.configuration.model.support.ldap.AbstractLdapProperties) Collectors(java.util.stream.Collectors) DnAttributeEntryHandler(org.ldaptive.handler.DnAttributeEntryHandler) List(java.util.List) DeleteOperation(org.ldaptive.DeleteOperation) CompareValidator(org.ldaptive.pool.CompareValidator) BindRequest(org.ldaptive.BindRequest) IntStream(java.util.stream.IntStream) Provider(org.ldaptive.provider.Provider) ReturnAttributes(org.ldaptive.ReturnAttributes) DefaultConnectionStrategy(org.ldaptive.DefaultConnectionStrategy) HashSet(java.util.HashSet) EntryResolver(org.ldaptive.auth.EntryResolver) QualityOfProtection(org.ldaptive.sasl.QualityOfProtection) ModifyReferralHandler(org.ldaptive.referral.ModifyReferralHandler) RecursiveEntryHandler(org.ldaptive.handler.RecursiveEntryHandler) PooledSearchEntryResolver(org.ldaptive.auth.PooledSearchEntryResolver) RandomConnectionStrategy(org.ldaptive.RandomConnectionStrategy) ObjectSidHandler(org.ldaptive.ad.handler.ObjectSidHandler) ResultCode(org.ldaptive.ResultCode) FastBindOperation(org.ldaptive.ad.extended.FastBindOperation) GssApiConfig(org.ldaptive.sasl.GssApiConfig) Connection(org.ldaptive.Connection) Authenticator(org.ldaptive.auth.Authenticator) DeleteReferralHandler(org.ldaptive.referral.DeleteReferralHandler) Credential(org.ldaptive.Credential) MergeAttributeEntryHandler(org.ldaptive.handler.MergeAttributeEntryHandler) NumberUtils(org.apache.commons.lang3.math.NumberUtils) PooledConnectionFactory(org.ldaptive.pool.PooledConnectionFactory) SecurityStrength(org.ldaptive.sasl.SecurityStrength) DefaultConnectionFactory(org.ldaptive.DefaultConnectionFactory) IdlePruneStrategy(org.ldaptive.pool.IdlePruneStrategy) SearchRequest(org.ldaptive.SearchRequest) Credential(org.ldaptive.Credential) ClosePassivator(org.ldaptive.pool.ClosePassivator) BindRequest(org.ldaptive.BindRequest) BlockingConnectionPool(org.ldaptive.pool.BlockingConnectionPool) SearchFilter(org.ldaptive.SearchFilter) AbstractLdapProperties(org.apereo.cas.configuration.model.support.ldap.AbstractLdapProperties) CompareRequest(org.ldaptive.CompareRequest) SearchValidator(org.ldaptive.pool.SearchValidator) CompareValidator(org.ldaptive.pool.CompareValidator) BindPassivator(org.ldaptive.pool.BindPassivator) LdapAttribute(org.ldaptive.LdapAttribute) PoolConfig(org.ldaptive.pool.PoolConfig) ArrayList(java.util.ArrayList) List(java.util.List) SearchReferralHandler(org.ldaptive.referral.SearchReferralHandler)

Example 3 with StringUtils.isNoneBlank

use of org.apache.commons.lang3.StringUtils.isNoneBlank in project eol-globi-data by jhpoelen.

the class DOIResolverCache method init.

void init(final Reader reader) throws PropertyEnricherException, IOException {
    DB db = initDb("doiCache");
    StopWatch watch = new StopWatch();
    watch.start();
    final CSVParser parser = CSVTSVUtil.createTSVParser(reader);
    LOG.info("doi cache building...");
    doiCitationMap = db.createTreeMap("doiCache").pumpPresort(300000).pumpIgnoreDuplicates().pumpSource(new Iterator<Fun.Tuple2<String, String>>() {

        private String[] line;

        String getCitation(String[] line) {
            return line[1];
        }

        String getDOI(String[] line) {
            return line[0];
        }

        @Override
        public boolean hasNext() {
            try {
                do {
                    line = parser.getLine();
                } while (line != null && line.length > 1 && !StringUtils.isNoneBlank(getCitation(line), getDOI(line)));
                boolean hasNext = line != null && line.length > 1 && StringUtils.isNoneBlank(getCitation(line), getDOI(line));
                if (!hasNext) {
                    System.out.println("[no more]");
                }
                return hasNext;
            } catch (IOException e) {
                LOG.error("problem reading", e);
                return false;
            }
        }

        @Override
        public Fun.Tuple2<String, String> next() {
            String citationString = StringUtils.defaultString(line[1], "");
            String doi = StringUtils.defaultString(line[0], "");
            return new Fun.Tuple2<>(citationString, doi);
        }
    }).make();
    watch.stop();
    LOG.info("doi cache built in [" + watch.getTime() / 1000 + "] s.");
}
Also used : CSVParser(com.Ostermiller.util.CSVParser) IOException(java.io.IOException) DB(org.mapdb.DB) Fun(org.mapdb.Fun) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 4 with StringUtils.isNoneBlank

use of org.apache.commons.lang3.StringUtils.isNoneBlank in project azure-tools-for-java by Microsoft.

the class AzureSdkLibraryService method loadAzureSDKEntities.

public static List<AzureJavaSdkEntity> loadAzureSDKEntities(final URL destination) {
    try {
        final ObjectReader reader = CSV_MAPPER.readerFor(AzureJavaSdkEntity.class).with(CsvSchema.emptySchema().withHeader());
        final MappingIterator<AzureJavaSdkEntity> data = reader.readValues(destination);
        return data.readAll().stream().filter(e -> StringUtils.isNoneBlank(e.getArtifactId(), e.getGroupId())).collect(Collectors.toList());
    } catch (final IOException e) {
        log.warn(String.format("failed to load Azure SDK list from \"%s\"", destination.toString()), e);
    }
    return Collections.emptyList();
}
Also used : java.util(java.util) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) SneakyThrows(lombok.SneakyThrows) URL(java.net.URL) MappingIterator(com.fasterxml.jackson.databind.MappingIterator) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) AzureSdkAllowListEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkAllowListEntity) CacheEvict(com.microsoft.azure.toolkit.lib.common.cache.CacheEvict) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) CacheManager(com.microsoft.azure.toolkit.lib.common.cache.CacheManager) Cacheable(com.microsoft.azure.toolkit.lib.common.cache.Cacheable) Preload(com.microsoft.azure.toolkit.lib.common.cache.Preload) Nonnull(javax.annotation.Nonnull) AzureSdkArtifactEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkArtifactEntity) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) ImmutableMap(com.google.common.collect.ImmutableMap) MalformedURLException(java.net.MalformedURLException) CsvMapper(com.fasterxml.jackson.dataformat.csv.CsvMapper) AzureJavaSdkEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureJavaSdkEntity) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) Slf4j(lombok.extern.slf4j.Slf4j) AzureSdkFeatureEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkFeatureEntity) AzureSdkServiceEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkServiceEntity) AzureJavaSdkEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureJavaSdkEntity) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) IOException(java.io.IOException)

Example 5 with StringUtils.isNoneBlank

use of org.apache.commons.lang3.StringUtils.isNoneBlank in project azure-tools-for-java by Microsoft.

the class AzurePlugin method runActivity.

@Override
public void runActivity(@NotNull Project project) {
    // read legacy settings from old data.xml
    final String installationId = "wangmi-azure-intellij-plugin-base";
    final String pluginVersion = "0.0.1-SNAPSHOT";
    // check non-empty for valid data.xml
    if (StringUtils.isNoneBlank(installationId, pluginVersion)) {
        final IntellijStore.AzureConfigurationData config = IntellijStore.getInstance().getState();
        IntellijStore.getInstance().loadState(config);
    }
    final IntellijStore.AzureConfigurationData config = IntellijStore.getInstance().getState();
    String installationID = InstallationIdUtils.getHashMac();
    if (StringUtils.isBlank(installationID)) {
        installationID = StringUtils.firstNonBlank(InstallationIdUtils.getHashMac(), InstallationIdUtils.hash(PermanentInstallationID.get()));
    }
    final String userAgent = String.format(USER_AGENT, PLUGIN_VERSION, installationID);
    Azure.az().config().setLogLevel("NONE");
    Azure.az().config().setUserAgent(userAgent);
    final AnAction action = ActionManager.getInstance().getAction(WhatsNewAction.ID);
    final DataContext context = dataId -> CommonDataKeys.PROJECT.getName().equals(dataId) ? project : null;
    AzureTaskManager.getInstance().runLater(() -> ActionUtil.invokeAction(action, context, "AzurePluginStartupActivity", null, null));
}
Also used : Azure(com.microsoft.azure.toolkit.lib.Azure) WhatsNewAction(com.microsoft.azure.toolkit.intellij.common.action.WhatsNewAction) DataContext(com.intellij.openapi.actionSystem.DataContext) PermanentInstallationID(com.intellij.openapi.application.PermanentInstallationID) ActionUtil(com.intellij.openapi.actionSystem.ex.ActionUtil) StartupActivity(com.intellij.openapi.startup.StartupActivity) PluginManagerCore(com.intellij.ide.plugins.PluginManagerCore) PlatformUtils(com.intellij.util.PlatformUtils) AnAction(com.intellij.openapi.actionSystem.AnAction) StringUtils(org.apache.commons.lang3.StringUtils) SystemInfo(com.intellij.openapi.util.SystemInfo) IntellijStore(com.microsoft.azure.toolkit.intellij.common.settings.IntellijStore) ActionManager(com.intellij.openapi.actionSystem.ActionManager) InstallationIdUtils(com.microsoft.azure.toolkit.lib.common.utils.InstallationIdUtils) Objects(java.util.Objects) PluginStateListener(com.intellij.ide.plugins.PluginStateListener) EventListenerList(javax.swing.event.EventListenerList) Project(com.intellij.openapi.project.Project) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) Logger(com.intellij.openapi.diagnostic.Logger) NotNull(org.jetbrains.annotations.NotNull) PluginId(com.intellij.openapi.extensions.PluginId) AzureTaskManager(com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager) DataContext(com.intellij.openapi.actionSystem.DataContext) IntellijStore(com.microsoft.azure.toolkit.intellij.common.settings.IntellijStore) AnAction(com.intellij.openapi.actionSystem.AnAction)

Aggregations

StringUtils (org.apache.commons.lang3.StringUtils)4 URL (java.net.URL)3 Collectors (java.util.stream.Collectors)3 Slf4j (lombok.extern.slf4j.Slf4j)3 IOException (java.io.IOException)2 CSVParser (com.Ostermiller.util.CSVParser)1 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1 MappingIterator (com.fasterxml.jackson.databind.MappingIterator)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 CsvMapper (com.fasterxml.jackson.dataformat.csv.CsvMapper)1 CsvSchema (com.fasterxml.jackson.dataformat.csv.CsvSchema)1 YAMLMapper (com.fasterxml.jackson.dataformat.yaml.YAMLMapper)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Multimap (com.google.common.collect.Multimap)1 PluginManagerCore (com.intellij.ide.plugins.PluginManagerCore)1 PluginStateListener (com.intellij.ide.plugins.PluginStateListener)1 ActionManager (com.intellij.openapi.actionSystem.ActionManager)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 CommonDataKeys (com.intellij.openapi.actionSystem.CommonDataKeys)1