use of org.gluu.oxtrust.model.GluuSAMLTrustRelationship in project oxTrust by GluuFederation.
the class Shibboleth3ConfService method initTrustParamMap.
/*
* Prepare trustRelationships to generate files
*/
private HashMap<String, Object> initTrustParamMap(List<GluuSAMLTrustRelationship> trustRelationships) {
log.trace("Starting trust parameters map initialization.");
HashMap<String, Object> trustParams = new HashMap<String, Object>();
// Metadata signature verification engines
// https://wiki.shibboleth.net/confluence/display/SHIB2/IdPTrustEngine
List<Map<String, String>> trustEngines = new ArrayList<Map<String, String>>();
// the map of {inum,number} for easy naming of relying parties.
Map<String, String> trustIds = new HashMap<String, String>();
// Trust relationships that are part of some federation
List<GluuSAMLTrustRelationship> deconstructed = new ArrayList<GluuSAMLTrustRelationship>();
// the map of {inum,number} for easy naming of federated relying
// parties.
Map<String, String> deconstructedIds = new HashMap<String, String>();
// the map of {inum, {inum, inum, inum...}} describing the federations
// and TRs defined from them.
Map<String, List<String>> deconstructedMap = new HashMap<String, List<String>>();
// entityIds defined in each TR.
Map<String, List<String>> trustEntityIds = new HashMap<String, List<String>>();
int id = 1;
for (GluuSAMLTrustRelationship trustRelationship : trustRelationships) {
boolean isPartOfFederation = !(trustRelationship.getSpMetaDataSourceType().equals(GluuMetadataSourceType.URI) || trustRelationship.getSpMetaDataSourceType().equals(GluuMetadataSourceType.FILE));
if (!isPartOfFederation) {
// Set Id
trustIds.put(trustRelationship.getInum(), String.valueOf(id++));
// Set entityId
String idpMetadataFolder = getIdpMetadataDir();
String metadataFile = idpMetadataFolder + trustRelationship.getSpMetaDataFN();
List<String> entityIds = samlMetadataParser.getEntityIdFromMetadataFile(metadataFile);
// user will be able to fix this in UI
if (entityIds == null) {
trustRelationship.setStatus(GluuStatus.INACTIVE);
trustService.updateTrustRelationship(trustRelationship);
continue;
}
trustEntityIds.put(trustRelationship.getInum(), entityIds);
initProfileConfiguration(trustRelationship);
if (trustRelationship.getMetadataFilters().get("signatureValidation") != null) {
Map<String, String> trustEngine = new HashMap<String, String>();
trustEngine.put("id", "Trust" + StringHelper.removePunctuation(trustRelationship.getInum()));
trustEngine.put("certPath", getIdpMetadataDir() + "credentials" + File.separator + trustRelationship.getMetadataFilters().get("signatureValidation").getFilterCertFileName());
trustEngines.add(trustEngine);
}
// If there is an intrusive filter - push it to the end of the list.
if (trustRelationship.getGluuSAMLMetaDataFilter() != null) {
List<String> filtersList = new ArrayList<String>();
String entityRoleWhiteList = null;
for (String filterXML : trustRelationship.getGluuSAMLMetaDataFilter()) {
Document xmlDocument;
try {
xmlDocument = xmlService.getXmlDocument(filterXML.getBytes());
} catch (Exception e) {
log.error("GluuSAMLMetaDataFilter contains invalid value.", e);
e.printStackTrace();
continue;
}
if (xmlDocument.getFirstChild().getAttributes().getNamedItem("xsi:type").getNodeValue().equals(FilterService.ENTITY_ROLE_WHITE_LIST_TYPE)) {
entityRoleWhiteList = filterXML;
continue;
}
filtersList.add(filterXML);
}
if (entityRoleWhiteList != null) {
filtersList.add(entityRoleWhiteList);
}
trustRelationship.setGluuSAMLMetaDataFilter(filtersList);
}
} else {
initProfileConfiguration(trustRelationship);
String federationInum = trustRelationship.getGluuContainerFederation();
if (deconstructedMap.get(federationInum) == null) {
deconstructedMap.put(federationInum, new ArrayList<String>());
}
deconstructedMap.get(federationInum).add(trustRelationship.getEntityId());
deconstructed.add(trustRelationship);
deconstructedIds.put(trustRelationship.getEntityId(), String.valueOf(id++));
}
}
for (String trustRelationshipInum : trustEntityIds.keySet()) {
List<String> federatedSites = deconstructedMap.get(trustRelationshipInum);
if (federatedSites != null) {
trustEntityIds.get(trustRelationshipInum).removeAll(federatedSites);
}
}
trustParams.put("idpCredentialsPath", getIdpMetadataDir() + "credentials" + File.separator);
trustParams.put("deconstructed", deconstructed);
trustParams.put("deconstructedIds", deconstructedIds);
trustParams.put("trustEngines", trustEngines);
trustParams.put("trusts", trustRelationships);
trustParams.put("trustIds", trustIds);
trustParams.put("trustEntityIds", trustEntityIds);
return trustParams;
}
Aggregations