Skip to content

Commit

Permalink
chore: allow to lookup entry by dn and objectClass
Browse files Browse the repository at this point in the history
  • Loading branch information
yurem committed Nov 29, 2021
1 parent e52f55a commit cfc3eab
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
12 changes: 12 additions & 0 deletions oxService/src/main/java/org/gluu/model/DisplayNameEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import org.gluu.persist.model.base.Entry;
import org.gluu.persist.annotation.AttributeName;
import org.gluu.persist.annotation.CustomObjectClass;
import org.gluu.persist.annotation.DataEntry;

/**
Expand All @@ -31,6 +32,9 @@ public DisplayNameEntry(String dn, String inum, String displayName) {
this.displayName = displayName;
}

@CustomObjectClass
private String[] customObjectClasses;

@AttributeName(ignoreDuringUpdate = true)
private String inum;

Expand Down Expand Up @@ -76,4 +80,12 @@ public String getUid() {
return uid;
}

public String[] getCustomObjectClasses() {
return customObjectClasses;
}

public void setCustomObjectClasses(String[] customObjectClasses) {
this.customObjectClasses = customObjectClasses;
}

}
30 changes: 25 additions & 5 deletions oxService/src/main/java/org/gluu/service/LookupService.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,28 @@ public class LookupService implements Serializable {
* display name
* @return DisplayNameEntry object
*/
public DisplayNameEntry getDisplayNameEntry(String dn, String objectClass) throws Exception {
String key = "l_" + objectClass + "_" + dn;
DisplayNameEntry entry = (DisplayNameEntry) cacheService.get(OxConstants.CACHE_LOOKUP_NAME, key);
if (entry == null) {
// Prepare sample for search
DisplayNameEntry sample = new DisplayNameEntry();
sample.setBaseDn(dn);
sample.setCustomObjectClasses(new String[] { objectClass });

List<DisplayNameEntry> entries = persistenceEntryManager.findEntries(sample, 1);
if (entries.size() == 1) {
entry = entries.get(0);
}

cacheService.put(OxConstants.CACHE_LOOKUP_NAME, key, entry);
}

return entry;
}

public <T> T getDisplayNameEntry(String dn, Class<T> entryClass) throws Exception {
String key = "l_" + dn;
String key = "l_" + entryClass.getSimpleName() + "_" + dn;
T entry = (T) cacheService.get(OxConstants.CACHE_LOOKUP_NAME, key);
if (entry == null) {
entry = persistenceEntryManager.find(dn, entryClass, null);
Expand Down Expand Up @@ -76,7 +96,7 @@ public Object getTypedEntry(String dn, String clazz) throws Exception {
}

Class entryClass = Class.class.forName(clazz);
String key = "l_" + dn;
String key = "l_" + entryClass.getSimpleName() + "_" + dn;
Object entry = cacheService.get(OxConstants.CACHE_LOOKUP_NAME, key);
if (entry == null) {
entry = persistenceEntryManager.find(entryClass, dn);
Expand All @@ -103,7 +123,7 @@ public <T> List<T> getDisplayNameEntries(String baseDn, Class<T> entryClass, Lis
return null;
}

String key = getCompoundKey(inums);
String key = getCompoundKey(entryClass, inums);
List<T> entries = (List<T>) cacheService.get(OxConstants.CACHE_LOOKUP_NAME, key);
if (entries == null) {
Filter searchFilter = buildInumFilter(inums);
Expand Down Expand Up @@ -144,13 +164,13 @@ public List<String> getInumsFromDns(List<String> dns) {
return inums;
}

private String getCompoundKey(List<String> inums) {
private <T> String getCompoundKey(Class<T> entryClass, List<String> inums) {
StringBuilder compoundKey = new StringBuilder();
for (String inum : inums) {
if (compoundKey.length() > 0) {
compoundKey.append("_");
} else {
compoundKey.append("l_");
compoundKey.append("l_" + entryClass.getSimpleName() + "_");
}
compoundKey.append(inum);
}
Expand Down

0 comments on commit cfc3eab

Please sign in to comment.