Skip to content

Commit

Permalink
fix: ajust customObjectClass usage in non-ldap backends
Browse files Browse the repository at this point in the history
  • Loading branch information
jgomer2001 committed Feb 28, 2022
1 parent fdf9c7b commit 88c9638
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
43 changes: 24 additions & 19 deletions casa/app/src/main/java/org/gluu/casa/core/PersistenceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import io.jans.orm.PersistenceEntryManager;
import io.jans.orm.PersistenceEntryManagerFactory;
import io.jans.orm.ldap.impl.LdapEntryManagerFactory;
import io.jans.orm.ldap.operation.LdapOperationService;
import io.jans.orm.model.PersistenceConfiguration;
import io.jans.orm.model.SearchScope;
Expand Down Expand Up @@ -340,7 +341,7 @@ private boolean loadApplianceSettings(Properties properties) {

boolean success = false;
try {
loadASSettings(properties.getProperty("jansAuth_ConfigurationEntryDN"));
loadASSettings(properties.getProperty("jansAuth_ConfigurationEntryDN"), properties.getProperty("persistence.type"));
rootDn = "o=jans";
success = true;

Expand All @@ -354,27 +355,31 @@ private boolean loadApplianceSettings(Properties properties) {

}

private void loadASSettings(String dn) throws Exception {
private void loadASSettings(String dn, String persistenceType) throws Exception {

ASConfiguration conf = get(ASConfiguration.class, dn);
dynamicConfig = mapper.readTree(conf.getJansConfStatic());
staticConfig = mapper.readTree(conf.getJansConfDyn());

personCustomObjectClasses = Optional.ofNullable(dynamicConfig.get("personCustomObjectClassList"))
.map(node -> {
try {
Set<String> ocs = new HashSet<>();
Iterator<JsonNode> it = node.elements();
while (it.hasNext()) {
ocs.add(it.next().asText());
dynamicConfig = mapper.readTree(conf.getJansConfDyn());
staticConfig = mapper.readTree(conf.getJansConfStatic());

if (persistenceType.equals(LdapEntryManagerFactory.PERSISTENCE_TYPE)) {

personCustomObjectClasses = Optional.ofNullable(dynamicConfig.get("personCustomObjectClassList"))
.map(node -> {
try {
List<String> ocs = new ArrayList<>();
node.elements().forEachRemaining(e -> ocs.add(e.asText()));

return Set.copyOf(ocs);
} catch (Exception e) {
logger.error(e.getMessage());
return null;
}
return ocs;
} catch (Exception e) {
logger.error(e.getMessage());
return null;
}
})
.orElse(Collections.singleton("gluuCustomPerson"));
})
.orElse(Collections.singleton("jansCustomPerson"));
}
if (personCustomObjectClasses == null) {
personCustomObjectClasses = Collections.emptySet();
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public class ASConfiguration extends Entry {
private String jansConfStatic;

public String getJansConfStatic() {
return jansConfDyn;
return jansConfStatic;
}

public String getJansConfDyn() {
return jansConfStatic;
return jansConfDyn;
}

public void setJansConfDyn(String jansConfDyn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.jans.orm.annotation.DataEntry;
import io.jans.orm.annotation.ObjectClass;

import java.util.HashSet;
import java.util.Set;

import org.gluu.casa.misc.Utils;
Expand All @@ -28,12 +29,10 @@ public class BasePerson extends InumEntry {

static {
IPersistenceService ips = Utils.managedBean(IPersistenceService.class);
if (ips != null) {
Set<String> ocs = ips.getPersonOCs();
ocs.remove("top");
ocs.remove("gluuPerson");
setCustomObjectClasses(ocs.toArray(new String[0]));
}
Set<String> ocs = new HashSet<>(ips.getPersonOCs());
ocs.remove("top");
ocs.remove("jansPerson");
setCustomObjectClasses(ocs.toArray(new String[0]));
}

public String getUid() {
Expand Down

0 comments on commit 88c9638

Please sign in to comment.