1
14
15 package com.liferay.portal.security.ldap;
16
17 import com.liferay.portal.kernel.util.Validator;
18 import com.liferay.util.ldap.DummyDirContext;
19
20 import javax.naming.Name;
21 import javax.naming.NameNotFoundException;
22 import javax.naming.NamingException;
23 import javax.naming.directory.Attribute;
24 import javax.naming.directory.Attributes;
25 import javax.naming.directory.BasicAttributes;
26
27
32 public class PortalLDAPContext extends DummyDirContext {
33
34 public PortalLDAPContext(Attributes attributes) {
35 _attributes = attributes;
36 }
37
38 public PortalLDAPContext(boolean ignoreCase) {
39 _attributes = new BasicAttributes(ignoreCase);
40 }
41
42 public void addAttribute(String name, Object object) {
43 _attributes.put(name, object);
44 }
45
46 public Attributes getAttributes() {
47 return _attributes;
48 }
49
50 public Attributes getAttributes(Name name) throws NamingException {
51 return getAttributes(name.toString());
52 }
53
54 public Attributes getAttributes(Name name, String[] ids)
55 throws NamingException {
56
57 return getAttributes(name.toString(), ids);
58 }
59
60 public Attributes getAttributes(String name) throws NamingException {
61 if (Validator.isNotNull(name)) {
62 throw new NameNotFoundException();
63 }
64
65 return (Attributes)_attributes.clone();
66 }
67
68 public Attributes getAttributes(String name, String[] ids)
69 throws NamingException {
70
71 if (Validator.isNotNull(name)) {
72 throw new NameNotFoundException();
73 }
74
75 Attributes attributes = new BasicAttributes(true);
76
77 for (int i = 0; i < ids.length; i++) {
78 Attribute attribute = _attributes.get(ids[i]);
79
80 if (attribute != null) {
81 attributes.put(attribute);
82 }
83 }
84
85 return attributes;
86 }
87
88 public void setAttributes(Attributes attributes) {
89 _attributes = attributes;
90 }
91
92 private Attributes _attributes;
93
94 }