一、前言
基于jasig-case包中的org.jasig.cas.util.LdapUtils目录协议工具类,用适当的方法替换过滤器中的占位符的实用方法用户名的值,详情参见源码说明部分。
二、源码说明package org.jasig.cas.util;@b@@b@import java.util.HashMap;@b@import java.util.Map;@b@@b@import javax.naming.NamingException;@b@import javax.naming.directory.DirContext;@b@@b@import org.apache.commons.logging.Log;@b@import org.apache.commons.logging.LogFactory;@b@@b@/**@b@ * Utilities related to LDAP functions.@b@ * @b@ * @author Scott Battaglia@b@ * @version $Revision: 42053 $ $Date: 2007-06-10 09:17:55 -0400 (Sun, 10 Jun 2007) $@b@ * @since 3.0@b@ */@b@public final class LdapUtils {@b@@b@ private static final Log logger = LogFactory.getLog(LdapUtils.class);@b@@b@ private LdapUtils() {@b@ // private constructor so that no one can instantiate.@b@ }@b@@b@ /**@b@ * Utility method to replace the placeholders in the filter with the proper@b@ * values from the userName.@b@ * @b@ * @param filter@b@ * @param userName@b@ * @return the filtered string populated with the username@b@ */@b@ public static String getFilterWithValues(final String filter,@b@ final String userName) {@b@ final Map properties = new HashMap();@b@ final String[] userDomain;@b@ String newFilter = filter;@b@@b@ properties.put("%u", userName.replace("\\", "\\\\"));@b@@b@ userDomain = userName.split("@");@b@@b@ properties.put("%U", userDomain[0]);@b@@b@ if (userDomain.length > 1) {@b@ properties.put("%d", userDomain[1]);@b@@b@ final String[] dcArray = userDomain[1].split("\\.");@b@@b@ for (int i = 0; i