001
014
015 package com.liferay.util.ldap;
016
017 import com.liferay.portal.kernel.util.StringPool;
018
019 import java.util.Properties;
020
021 import javax.naming.NamingException;
022 import javax.naming.directory.Attribute;
023 import javax.naming.directory.Attributes;
024
025
030 public class LDAPUtil {
031
032 public static String getAttributeValue(
033 Attributes attributes, Properties properties, String key)
034 throws NamingException {
035
036 String id = properties.getProperty(key);
037
038 return getAttributeValue(attributes, id);
039 }
040
041 public static String getAttributeValue(
042 Attributes attributes, Properties properties, String key,
043 String defaultValue)
044 throws NamingException {
045
046 String id = properties.getProperty(key);
047
048 return getAttributeValue(attributes, id, defaultValue);
049 }
050
051 public static String getAttributeValue(Attributes attributes, String id)
052 throws NamingException {
053
054 return getAttributeValue(attributes, id, StringPool.BLANK);
055 }
056
057 public static String getAttributeValue(
058 Attributes attributes, String id, String defaultValue)
059 throws NamingException {
060
061 try {
062 Attribute attribute = attributes.get(id);
063
064 Object obj = attribute.get();
065
066 return obj.toString();
067 }
068 catch (NullPointerException npe) {
069 return defaultValue;
070 }
071 }
072
073 public static String getFullProviderURL(String baseURL, String baseDN) {
074 return baseURL + StringPool.SLASH + baseDN;
075 }
076
077 }