001
014
015 package com.liferay.portal.security.ldap;
016
017 import com.liferay.portal.kernel.ldap.DummyDirContext;
018 import com.liferay.portal.kernel.util.Validator;
019
020 import javax.naming.Name;
021 import javax.naming.NameNotFoundException;
022 import javax.naming.NamingException;
023 import javax.naming.directory.Attribute;
024 import javax.naming.directory.Attributes;
025 import javax.naming.directory.BasicAttributes;
026
027
030 public class PortalLDAPContext extends DummyDirContext {
031
032 public PortalLDAPContext(Attributes attributes) {
033 _attributes = attributes;
034 }
035
036 public PortalLDAPContext(boolean ignoreCase) {
037 _attributes = new BasicAttributes(ignoreCase);
038 }
039
040 public void addAttribute(String name, Object object) {
041 _attributes.put(name, object);
042 }
043
044 public Attributes getAttributes() {
045 return _attributes;
046 }
047
048 @Override
049 public Attributes getAttributes(Name name) throws NamingException {
050 return getAttributes(name.toString());
051 }
052
053 @Override
054 public Attributes getAttributes(Name name, String[] ids)
055 throws NamingException {
056
057 return getAttributes(name.toString(), ids);
058 }
059
060 @Override
061 public Attributes getAttributes(String name) throws NamingException {
062 if (Validator.isNotNull(name)) {
063 throw new NameNotFoundException();
064 }
065
066 return (Attributes)_attributes.clone();
067 }
068
069 @Override
070 public Attributes getAttributes(String name, String[] ids)
071 throws NamingException {
072
073 if (Validator.isNotNull(name)) {
074 throw new NameNotFoundException();
075 }
076
077 Attributes attributes = new BasicAttributes(true);
078
079 for (int i = 0; i < ids.length; i++) {
080 Attribute attribute = _attributes.get(ids[i]);
081
082 if (attribute != null) {
083 attributes.put(attribute);
084 }
085 }
086
087 return attributes;
088 }
089
090 public void setAttributes(Attributes attributes) {
091 _attributes = attributes;
092 }
093
094 private Attributes _attributes;
095
096 }