org.springframework.ldap.CommunicationException Java Examples
The following examples show how to use
org.springframework.ldap.CommunicationException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LdapIdentityLookup.java From gravitee-management-rest-api with Apache License 2.0 | 5 votes |
@Override public Collection<User> search(String query) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); String usersSearchFilter = environment.getProperty("lookup.user.filter", LDAP_DEFAULT_LOOKUP_FILTER); String hardcodedFilter = usersSearchFilter.replaceAll("\\{0}", LdapUtils.addWhitespaceWildcards(query)); LdapQuery ldapQuery = LdapQueryBuilder .query() .base(baseDn) .countLimit(20) .timeLimit(5000) .searchScope(SearchScope.SUBTREE) .attributes( LDAP_ATTRIBUTE_GIVENNAME, LDAP_ATTRIBUTE_SURNAME, LDAP_ATTRIBUTE_MAIL, LDAP_ATTRIBUTE_DISPLAYNAME) .filter(new HardcodedFilter(hardcodedFilter)); return ldapTemplate.search(ldapQuery, USER_CONTEXT_MAPPER); } catch(LimitExceededException lee) { LOGGER.info("Too much results while searching for [{}]. Returns an empty list.", query); return Collections.emptyList(); } catch(CommunicationException ce) { LOGGER.error("LDAP server is not reachable."); return Collections.emptyList(); } finally { Thread.currentThread().setContextClassLoader(classLoader); } }
Example #2
Source File: ContextSourceParser.java From spring-ldap with Apache License 2.0 | 5 votes |
private void populatePoolValidationProperties(BeanDefinitionBuilder builder, Element element, boolean testOnBorrow, boolean testOnReturn, boolean testWhileIdle) { builder.addPropertyValue("testOnBorrow", testOnBorrow); builder.addPropertyValue("testOnReturn", testOnReturn); builder.addPropertyValue("testWhileIdle", testWhileIdle); BeanDefinitionBuilder validatorBuilder = BeanDefinitionBuilder.rootBeanDefinition(DefaultDirContextValidator.class); validatorBuilder.addPropertyValue("base", getString(element, ATT_VALIDATION_QUERY_BASE, "")); validatorBuilder.addPropertyValue("filter", getString(element, ATT_VALIDATION_QUERY_FILTER, DefaultDirContextValidator.DEFAULT_FILTER)); String searchControlsRef = element.getAttribute(ATT_VALIDATION_QUERY_SEARCH_CONTROLS_REF); if(StringUtils.hasText(searchControlsRef)) { validatorBuilder.addPropertyReference("searchControls", searchControlsRef); } builder.addPropertyValue("dirContextValidator", validatorBuilder.getBeanDefinition()); builder.addPropertyValue("timeBetweenEvictionRunsMillis", getString(element, ATT_EVICTION_RUN_MILLIS, String.valueOf(DEFAULT_EVICTION_RUN_MILLIS))); builder.addPropertyValue("numTestsPerEvictionRun", getInt(element, ATT_TESTS_PER_EVICTION_RUN, DEFAULT_TESTS_PER_EVICTION_RUN)); builder.addPropertyValue("minEvictableIdleTimeMillis", getString(element, ATT_EVICTABLE_TIME_MILLIS, String.valueOf(DEFAULT_EVICTABLE_MILLIS))); String nonTransientExceptions = getString(element, ATT_NON_TRANSIENT_EXCEPTIONS, CommunicationException.class.getName()); String[] strings = StringUtils.commaDelimitedListToStringArray(nonTransientExceptions); Set<Class<?>> nonTransientExceptionClasses = new HashSet<Class<?>>(); for (String className : strings) { try { nonTransientExceptionClasses.add(ClassUtils.getDefaultClassLoader().loadClass(className)); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(String.format("%s is not a valid class name", className), e); } } builder.addPropertyValue("nonTransientExceptions", nonTransientExceptionClasses); }
Example #3
Source File: ContextSourceParser.java From spring-ldap with Apache License 2.0 | 5 votes |
private void populatePoolValidationProperties(BeanDefinitionBuilder builder, Element element) { BeanDefinitionBuilder validatorBuilder = BeanDefinitionBuilder.rootBeanDefinition( org.springframework.ldap.pool2.validation.DefaultDirContextValidator.class); validatorBuilder.addPropertyValue("base", getString(element, ATT_VALIDATION_QUERY_BASE, "")); validatorBuilder.addPropertyValue("filter", getString(element, ATT_VALIDATION_QUERY_FILTER, org.springframework.ldap.pool2.validation.DefaultDirContextValidator.DEFAULT_FILTER)); String searchControlsRef = element.getAttribute(ATT_VALIDATION_QUERY_SEARCH_CONTROLS_REF); if(StringUtils.hasText(searchControlsRef)) { validatorBuilder.addPropertyReference("searchControls", searchControlsRef); } builder.addPropertyValue("dirContextValidator", validatorBuilder.getBeanDefinition()); String nonTransientExceptions = getString(element, ATT_NON_TRANSIENT_EXCEPTIONS, CommunicationException.class.getName()); String[] strings = StringUtils.commaDelimitedListToStringArray(nonTransientExceptions); Set<Class<?>> nonTransientExceptionClasses = new HashSet<Class<?>>(); for (String className : strings) { try { nonTransientExceptionClasses.add(ClassUtils.getDefaultClassLoader().loadClass(className)); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(String.format("%s is not a valid class name", className), e); } } builder.addPropertyValue("nonTransientExceptions", nonTransientExceptionClasses); }