LdapTestUtils.java 文件源码

java
阅读 18 收藏 0 点赞 0 评论 0

项目:springboot-shiro-cas-mybatis 作者:
/**
 * Reads an LDIF into a collection of LDAP entries. The components performs a simple property
 * replacement in the LDIF data where <pre>${ldapBaseDn}</pre> is replaced with the environment-specific base
 * DN.
 *
 * @param ldif LDIF resource, typically a file on filesystem or classpath.
 * @param baseDn The directory branch where the entry resides.
 *
 * @return LDAP entries contained in the LDIF.
 *
 * @throws IOException On IO errors reading LDIF.
 */
public static Collection<LdapEntry> readLdif(final InputStream ldif, final String baseDn) throws IOException {
    final StringBuilder builder = new StringBuilder();
    try (final BufferedReader reader = new BufferedReader(new InputStreamReader(ldif))) {
        String line;
        while ((line = reader.readLine()) != null) {
            if (line.contains(BASE_DN_PLACEHOLDER)) {
                builder.append(line.replace(BASE_DN_PLACEHOLDER, baseDn));
            } else {
                builder.append(line);
            }
            builder.append(NEWLINE);
        }
    }
    return new LdifReader(new StringReader(builder.toString())).read().getEntries();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号