1
14
15 package com.liferay.util.ldap;
16
17 import com.liferay.portal.kernel.util.StringPool;
18
19 import java.util.Properties;
20
21 import javax.naming.NamingException;
22 import javax.naming.directory.Attribute;
23 import javax.naming.directory.Attributes;
24
25
32 public class LDAPUtil {
33
34 public static String getAttributeValue(
35 Attributes attributes, Properties properties, String key)
36 throws NamingException {
37
38 String id = properties.getProperty(key);
39
40 return getAttributeValue(attributes, id);
41 }
42
43 public static String getAttributeValue(
44 Attributes attributes, Properties properties, String key,
45 String defaultValue)
46 throws NamingException {
47
48 String id = properties.getProperty(key);
49
50 return getAttributeValue(attributes, id, defaultValue);
51 }
52
53 public static String getAttributeValue(Attributes attributes, String id)
54 throws NamingException {
55
56 return getAttributeValue(attributes, id, StringPool.BLANK);
57 }
58
59 public static String getAttributeValue(
60 Attributes attributes, String id, String defaultValue)
61 throws NamingException {
62
63 try {
64 Attribute attribute = attributes.get(id);
65
66 Object obj = attribute.get();
67
68 return obj.toString();
69 }
70 catch (NullPointerException npe) {
71 return defaultValue;
72 }
73 }
74
75 public static String getFullProviderURL(String baseURL, String baseDN) {
76 return baseURL + StringPool.SLASH + baseDN;
77 }
78
79 }