8000 Retrieve UUID from LDAP in same context by ahus1 · Pull Request #29470 · keycloak/keycloak · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Retrieve UUID from LDAP in same context #29470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -101,8 +100,7 @@ public void add(LDAPObject ldapObject) {
}

BasicAttributes ldapAttributes = extractAttributesForSaving(ldapObject, true);
this.operationManager.createSubContext(ldapObject.getDn().getLdapName(), ldapAttributes);
ldapObject.setUuid(getEntryIdentifier(ldapObject));
ldapObject.setUuid(operationManager.createSubContext(ldapObject.getDn().getLdapName(), ldapAttributes));

if (logger.isDebugEnabled()) {
logger.debugf("Type with identifier [%s] and dn [%s] successfully added to LDAP store.", ldapObject.getUuid(), ldapObject.getDn());
Expand Down Expand Up @@ -604,23 +602,4 @@ private BasicAttribute createBinaryBasicAttribute(String attrName, Set<String> a
return attr;
}

protected String getEntryIdentifier(final LDAPObject ldapObject) {
try {
// we need this to retrieve the entry's identifier from the ldap server
String uuidAttrName = getConfig().getUuidLDAPAttributeName();

List<SearchResult> search = this.operationManager.search(ldapObject.getDn().getLdapName(),
new LDAPQueryConditionsBuilder().present(LDAPConstants.OBJECT_CLASS),
Arrays.asList(uuidAttrName), SearchControls.OBJECT_SCOPE);
Attribute id = search.get(0).getAttributes().get(getConfig().getUuidLDAPAttributeName());

if (id == null) {
throw new ModelException("Could not retrieve identifier for entry [" + ldapObject.getDn().toString() + "].");
}

return this.operationManager.decodeEntryUUID(id.get());
} catch (NamingException ne) {
throw new ModelException("Could not retrieve identifier for entry [" + ldapObject.getDn().toString() + "].");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ public void modifyAttributes(final LdapName dn, final ModificationItem[] mods, L
}
}

public void createSubContext(final LdapName name, final Attributes attributes) {
public String createSubContext(final LdapName name, final Attributes attributes) {
try {
if (logger.isTraceEnabled()) {
logger.tracef("Creating entry [%s] with attributes: [", name);
Expand All @@ -622,14 +622,22 @@ public void createSubContext(final LdapName name, final Attributes attributes) {
logger.tracef("]");
}

execute(new LdapOperation<Void>() {
return execute(new LdapOperation<>() {
@Override
public Void execute(LdapContext context) throws NamingException {
public String execute(LdapContext context) throws NamingException {
DirContext subcontext = context.createSubcontext(name, attributes);

subcontext.close();

return null;
try {
String uuidLDAPAttributeName = config.getUuidLDAPAttributeName();
Attribute id = subcontext.getAttributes("", new String[]{uuidLDAPAttributeName}).get(uuidLDAPAttributeName);
if (id == null) {
throw new ModelException("Could not retrieve identifier for entry [" + name + "].");
}
return decodeEntryUUID(id.get());
} catch (NamingException ne) {
throw new ModelException("Could not retrieve identifier for entry [" + name + "].", ne);
} finally {
subcontext.close();
}
}


Expand Down
0