In order to let users make good use of the new retail risk prevention and control center and provide convenience to users as much as possible
Come on, what do you want?
It's the address book of Alibaba cloud mailbox, which can query the email group interface.
I'm also bothered by Alibaba cloud mail. You don't want any at present, neither HSF nor HTTP. But thank you for pointing out a direction for me. Open LDAP protocol, my f**k, less hate when books are used, all kinds of Baidu Google
Conceptual encyclopedia knowledge, please study by yourself.
ldap java api
http://directory.apache.org/api/java-api.html
⭐️UnboundID LDAP sdk for java
https://docs.ldap.com/ldap-sdk/docs/index.html
This time, I use unbounded LDAP to implement it. Next, I will directly publish the results and codes to you (springboot project):
Personal email query results
Mail group information query results
application.properties
maven dependence
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-ldap</artifactId> </dependency> <dependency> <groupId>com.unboundid</groupId> <artifactId>unboundid-ldapsdk</artifactId> </dependency>
Bean
@Component public class LdapClient { private Logger logger = LoggerFactory.getLogger(LdapClient.class); @Value("${spring.ldap.ldapBindDN}") private String ldapBindDN; @Value("${spring.ldap.ldapPassword}") private String ldapPassword; @Value("${spring.ldap.domain}") private String ldapHost; @Value("${spring.ldap.port}") private int ldapPort; private LDAPConnectionPool connectionPool = null; @Bean public LDAPConnectionPool initLDAPConnectionPool() { try { SSLUtil sslUtil = new SSLUtil(new TrustAllTrustManager()); LDAPConnection connection = new LDAPConnection(sslUtil.createSSLSocketFactory(), ldapHost, ldapPort); BindResult bindResult = connection.bind(ldapBindDN, ldapPassword); this.connectionPool = new LDAPConnectionPool(connection, 10); } catch (LDAPException | GeneralSecurityException e) { e.printStackTrace(); } return this.connectionPool; } public LDAPConnection getConnection() { try { return connectionPool.getConnection(); } catch (LDAPException e) { e.printStackTrace(); } return null; } }
ServiceImpl
@Service public class LdapServiceImpl implements LdapService { @Value("${spring.ldap.baseDN}") private String baseDN; @Resource private LdapClient ldapClient; @Override public JSONArray queryCn(String keyword) { LDAPConnection connection = ldapClient.getConnection(); try { SearchRequest searchRequest = new SearchRequest(baseDN, SearchScope.SUB, Filter.createEqualityFilter("cn", keyword)); searchRequest.addControl(new SubentriesRequestControl()); SearchResult searchResult = connection.search(searchRequest); if (searchResult.getResultCode() == ResultCode.SUCCESS) { JSONArray jsonArray = new JSONArray(); for (SearchResultEntry entry : searchResult.getSearchEntries()) { JSONObject jsonObject = new JSONObject(); entry.getAttributes().forEach((k) -> { jsonObject.put(k.getName(), k.getValue()); }); jsonArray.add(jsonObject); } return jsonArray; } else { return null; } } catch (LDAPException e) { e.printStackTrace(); } return null; } }
Thank you for reading. Welcome to correct.