use of javax.naming.directory.DirContext in project fess by codelibs.
the class LdapManager method login.
public OptionalEntity<FessUser> login(final String username, final String password) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
if (StringUtil.isBlank(fessConfig.getLdapProviderUrl())) {
return OptionalEntity.empty();
}
if (!validate()) {
return OptionalEntity.empty();
}
final Hashtable<String, String> env = createSearchEnv(username, password);
try (DirContextHolder holder = getDirContext(() -> env)) {
final DirContext context = holder.get();
if (logger.isDebugEnabled()) {
logger.debug("Logged in.", context);
}
return OptionalEntity.of(createLdapUser(username, env));
} catch (final Exception e) {
logger.debug("Login failed.", e);
}
return OptionalEntity.empty();
}
use of javax.naming.directory.DirContext in project Lucee by lucee.
the class LDAPClient method modifydn.
/**
* modifies distinguished name attribute for LDAP entries on LDAP server
* @param dn
* @param attributes
* @throws NamingException
*/
public void modifydn(String dn, String attributes) throws NamingException {
DirContext ctx = new InitialDirContext(env);
ctx.rename(dn, attributes);
ctx.close();
}
use of javax.naming.directory.DirContext in project Lucee by lucee.
the class LDAPClient method add.
/**
* adds LDAP entries to LDAP server
* @param dn
* @param attributes
* @param delimiter
* @throws NamingException
* @throws PageException
*/
public void add(String dn, String attributes, String delimiter, String seperator) throws NamingException, PageException {
DirContext ctx = new InitialDirContext(env);
ctx.createSubcontext(dn, toAttributes(attributes, delimiter, seperator));
ctx.close();
}
use of javax.naming.directory.DirContext in project Lucee by lucee.
the class LDAPClient method modify.
public void modify(String dn, int modifytype, String strAttributes, String delimiter, String separator) throws NamingException, PageException {
DirContext context = new InitialDirContext(env);
String[] strArrAttributes = toStringAttributes(strAttributes, delimiter);
int count = 0;
for (int i = 0; i < strArrAttributes.length; i++) {
String[] attributesValues = getAttributesValues(strArrAttributes[i], separator);
if (attributesValues == null)
count++;
else
count += attributesValues.length;
}
ModificationItem[] modItems = new ModificationItem[count];
BasicAttribute basicAttr = null;
int k = 0;
for (int i = 0; i < strArrAttributes.length; i++) {
String attribute = strArrAttributes[i];
String type = getAttrValueType(attribute);
String[] values = getAttributesValues(attribute, separator);
if (modifytype == DirContext.REPLACE_ATTRIBUTE) {
if (values == null)
basicAttr = new BasicAttribute(type);
else
basicAttr = new BasicAttribute(type, values[0]);
modItems[k] = new ModificationItem(modifytype, basicAttr);
k++;
if (values != null && values.length > 1) {
for (int j = 1; j < values.length; j++) {
basicAttr = new BasicAttribute(type, values[j]);
modItems[k] = new ModificationItem(DirContext.ADD_ATTRIBUTE, basicAttr);
k++;
}
}
} else {
for (int j = 0; j < values.length; j++) {
if (type != null || modifytype == DirContext.ADD_ATTRIBUTE)
basicAttr = new BasicAttribute(type, values[j]);
else
basicAttr = new BasicAttribute(values[j]);
modItems[k] = new ModificationItem(modifytype, basicAttr);
k++;
}
}
}
context.modifyAttributes(dn, modItems);
context.close();
}
use of javax.naming.directory.DirContext in project Payara by payara.
the class ContainerBase method setResources.
/**
* Set the resources DirContext object with which this Container is
* associated.
*
* @param resources The newly associated DirContext
* @throws Exception
*/
// XXX: Is exception ever thrown?
@Override
public void setResources(DirContext resources) throws Exception {
// Called from StandardContext.setResources()
// <- StandardContext.start()
// <- ContainerBase.addChildInternal()
// Change components if necessary
DirContext oldResources;
try {
writeLock.lock();
oldResources = this.resources;
if (oldResources == resources)
return;
Hashtable<String, String> env = new Hashtable<String, String>();
if (getParent() != null)
env.put(ProxyDirContext.HOST, getParent().getName());
env.put(ProxyDirContext.CONTEXT, getName());
this.resources = new ProxyDirContext(env, resources);
// Report this property change to interested listeners
} finally {
writeLock.unlock();
}
support.firePropertyChange("resources", oldResources, this.resources);
}
Aggregations