use of org.orcid.persistence.jpa.entities.IdentityProviderEntity in project ORCID-Source by ORCID.
the class IdentityProviderManagerImpl method saveOrUpdateIdentityProviderInTransaction.
private void saveOrUpdateIdentityProviderInTransaction(IdentityProviderEntity incoming) {
IdentityProviderEntity existing = identityProviderDao.findByProviderid(incoming.getProviderid());
if (existing == null) {
incoming.getNames().stream().forEach(i -> i.setIdentityProvider(incoming));
identityProviderDao.persist(incoming);
} else {
existing.setProviderid(incoming.getProviderid());
existing.setDisplayName(incoming.getDisplayName());
existing.setSupportEmail(incoming.getSupportEmail());
existing.setAdminEmail(incoming.getAdminEmail());
existing.setTechEmail(incoming.getTechEmail());
mergeNames(incoming, existing);
identityProviderDao.merge(existing);
}
}
use of org.orcid.persistence.jpa.entities.IdentityProviderEntity in project ORCID-Source by ORCID.
the class IdentityProviderManagerImpl method createEntityFromXml.
@Override
public IdentityProviderEntity createEntityFromXml(Element idpElement) {
XPath xpath = createXPath();
XPathExpression mainDisplayNameXpath = compileXPath(xpath, "string(.//md:IDPSSODescriptor//mdui:DisplayName[1])");
XPathExpression displayNamesXpath = compileXPath(xpath, ".//md:IDPSSODescriptor//mdui:DisplayName");
XPathExpression legacyMainDisplayNameXpath = compileXPath(xpath, "string(.//md:OrganizationDisplayName[1])");
XPathExpression legacyDisplayNamesXpath = compileXPath(xpath, ".//md:OrganizationDisplayName");
XPathExpression supportContactXpath = compileXPath(xpath, "string((.//md:ContactPerson[@contactType='support'])[1]/md:EmailAddress[1])");
XPathExpression adminContactXpath = compileXPath(xpath, "string((.//md:ContactPerson[@contactType='administrative'])[1]/md:EmailAddress[1])");
XPathExpression techContactXpath = compileXPath(xpath, "string((.//md:ContactPerson[@contactType='technical'])[1]/md:EmailAddress[1])");
String entityId = idpElement.getAttribute("entityID");
String mainDisplayName = evaluateXPathString(mainDisplayNameXpath, idpElement);
if (StringUtils.isBlank(mainDisplayName)) {
mainDisplayName = evaluateXPathString(legacyMainDisplayNameXpath, idpElement);
}
String supportEmail = tidyEmail(evaluateXPathString(supportContactXpath, idpElement));
String adminEmail = tidyEmail(evaluateXPathString(adminContactXpath, idpElement));
String techEmail = tidyEmail(evaluateXPathString(techContactXpath, idpElement));
List<IdentityProviderNameEntity> nameEntities = createNameEntitiesFromXml(displayNamesXpath, idpElement);
if (nameEntities == null || nameEntities.isEmpty()) {
nameEntities = createNameEntitiesFromXml(legacyDisplayNamesXpath, idpElement);
}
IdentityProviderEntity identityProviderEntity = new IdentityProviderEntity();
identityProviderEntity.setProviderid(entityId);
identityProviderEntity.setDisplayName(mainDisplayName);
identityProviderEntity.setNames(nameEntities);
identityProviderEntity.setSupportEmail(supportEmail);
identityProviderEntity.setAdminEmail(adminEmail);
identityProviderEntity.setTechEmail(techEmail);
return identityProviderEntity;
}
use of org.orcid.persistence.jpa.entities.IdentityProviderEntity in project ORCID-Source by ORCID.
the class IdentityProviderManagerTest method testCreateEntityFromXmlWithLegacyNames.
@Test
public void testCreateEntityFromXmlWithLegacyNames() throws SAXException, IOException, ParserConfigurationException {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
dbFactory.setNamespaceAware(true);
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(getClass().getResourceAsStream("example_idp_legacy.xml"));
Element idpElement = doc.getDocumentElement();
IdentityProviderEntity result = identityProviderManager.createEntityFromXml(idpElement);
assertNotNull(result);
assertEquals("https://registry.shibboleth.example.ac.uk/idp", result.getProviderid());
List<IdentityProviderNameEntity> names = result.getNames();
assertNotNull(names);
assertEquals(1, names.size());
IdentityProviderNameEntity name = names.get(0);
assertEquals("University of Example Display", name.getDisplayName());
assertEquals("en", name.getLang());
assertEquals("University of Example Display", result.getDisplayName());
assertEquals("help@it.example.ac.uk", result.getSupportEmail());
assertEquals("admin@it.example.ac.uk", result.getAdminEmail());
assertEquals("sysdev@it.example.ac.uk", result.getTechEmail());
}
use of org.orcid.persistence.jpa.entities.IdentityProviderEntity in project ORCID-Source by ORCID.
the class IdentityProviderManagerImpl method loadIdentityProviders.
@Override
public void loadIdentityProviders() {
String[] metadataUrls = StringUtils.split(metadataUrlsString);
XPath xpath = createXPath();
XPathExpression entityDescriptorXpath = compileXPath(xpath, "//md:EntityDescriptor");
for (String metadataUrl : metadataUrls) {
Document document = downloadMetadata(metadataUrl);
NodeList nodes = evaluateXPathNodeList(entityDescriptorXpath, document);
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
IdentityProviderEntity incoming = createEntityFromXml(element);
LOGGER.info("Found identity provider: {}", incoming.toShortString());
saveOrUpdateIdentityProvider(incoming);
}
}
}
use of org.orcid.persistence.jpa.entities.IdentityProviderEntity in project ORCID-Source by ORCID.
the class IdentityProviderManagerImpl method retrieveContactEmailByProviderid.
@Override
public String retrieveContactEmailByProviderid(String providerid) {
IdentityProviderEntity idp = identityProviderDao.findByProviderid(providerid);
if (idp == null) {
return null;
}
String supportEmail = idp.getSupportEmail();
if (supportEmail != null) {
return supportEmail;
}
List<String> otherEmails = new ArrayList<>(2);
otherEmails.add(idp.getAdminEmail());
otherEmails.add(idp.getTechEmail());
return String.join(";", otherEmails.stream().filter(e -> e != null).collect(Collectors.toList()));
}
Aggregations