Skip to content

Commit

Permalink
Fix federation trust relationship issue #1148
Browse files Browse the repository at this point in the history
  • Loading branch information
syntrydy committed Sep 3, 2018
1 parent 8210f0c commit 2d40e9f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
Expand Up @@ -80,7 +80,7 @@ public class TrustService implements Serializable {
public static final String GENERATED_SSL_ARTIFACTS_DIR = "ssl";

public void addTrustRelationship(GluuSAMLTrustRelationship trustRelationship) {
log.info("Creating TR " + trustRelationship.getInum());
trustRelationship.setGluuContainerFederation(getRightDn(trustRelationship.getGluuContainerFederation()));
String[] clusterMembers = appConfiguration.getClusteredInums();
String applianceInum = appConfiguration.getApplianceInum();
if (clusterMembers == null || clusterMembers.length == 0) {
Expand Down Expand Up @@ -162,16 +162,39 @@ public void removeTrustRelationship(GluuSAMLTrustRelationship trustRelationship)
}

public GluuSAMLTrustRelationship getRelationshipByInum(String inum) {
return ldapEntryManager.find(GluuSAMLTrustRelationship.class, getDnForTrustRelationShip(inum));
try {
return ldapEntryManager.find(GluuSAMLTrustRelationship.class, getDnForTrustRelationShip(inum));
} catch (Exception e) {
log.error(e.getMessage());
return null;
}

}

public GluuSAMLTrustRelationship getRelationshipByDn(String dn) {
if (dn != null && dn.contains("Entry")) {
dn = getRightDn(dn);
}
if (StringHelper.isNotEmpty(dn)) {
return ldapEntryManager.find(GluuSAMLTrustRelationship.class, dn);
try {
return ldapEntryManager.find(GluuSAMLTrustRelationship.class, dn);
} catch (Exception e) {
log.info(e.getMessage());
}

}
return null;
}

private String getRightDn(String dn) {
String newDn1 = dn.split("\\[")[1];
String newDn2 = newDn1.substring(3);
String[] newDn3 = newDn2.split("\\,");
String valueToBeRemoved = newDn3[newDn3.length - 1];
dn = newDn2.replace(",".concat(valueToBeRemoved), "");
return dn;
}

/**
* This is a LDAP operation as LDAP and IDP will always be in sync. We can just
* call LDAP to fetch all Trust Relationships.
Expand Down Expand Up @@ -405,7 +428,8 @@ public GluuSAMLTrustRelationship getTrustByUnpunctuatedInum(String unpunctuated)
}

public GluuSAMLTrustRelationship getTrustContainerFederation(GluuSAMLTrustRelationship trustRelationship) {
return getRelationshipByDn(trustRelationship.getGluuContainerFederation());
GluuSAMLTrustRelationship relationshipByDn = getRelationshipByDn(trustRelationship.getDn());
return relationshipByDn;
}

public List<GluuSAMLTrustRelationship> searchSAMLTrustRelationships(String pattern, int sizeLimit) {
Expand Down
Expand Up @@ -14,6 +14,7 @@
import java.util.Set;
import java.util.TreeSet;

import javax.inject.Inject;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
Expand All @@ -23,6 +24,7 @@
import org.gluu.site.ldap.persistence.annotation.LdapAttribute;
import org.gluu.site.ldap.persistence.annotation.LdapEntry;
import org.gluu.site.ldap.persistence.annotation.LdapObjectClass;
import org.slf4j.Logger;
import org.xdi.ldap.model.GluuStatus;
import org.xdi.ldap.model.InumEntry;
import org.xdi.service.cdi.util.CdiUtil;
Expand Down Expand Up @@ -123,6 +125,9 @@ public class GluuSAMLTrustRelationship extends InumEntry implements Serializable

@LdapAttribute(name = "gluuEntityType")
private GluuEntityType entityType;

@Inject
private Logger log;



Expand Down
Expand Up @@ -256,7 +256,7 @@

<h:panelGroup id="FederationWizardEntitySelection">
<h:panelGroup
rendered="#{(trustService.getTrustContainerFederation(_trustRelationship) ne null) and (_trustRelationship.spMetaDataSourceType.value eq 'federation')}">
rendered="#{(trustService.getTrustContainerFederation(_trustRelationship) eq null) and (_trustRelationship.spMetaDataSourceType.value eq 'federation')}">
<ox:decorate
id="spMetaDataSourceTypeFederationEntitySelection" label="#{msg['trustmanager.entityID']}">

Expand Down

0 comments on commit 2d40e9f

Please sign in to comment.