Search in sources :

Example 1 with IdentityProviderEntity

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);
    }
}
Also used : IdentityProviderEntity(org.orcid.persistence.jpa.entities.IdentityProviderEntity)

Example 2 with IdentityProviderEntity

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;
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) IdentityProviderNameEntity(org.orcid.persistence.jpa.entities.IdentityProviderNameEntity) IdentityProviderEntity(org.orcid.persistence.jpa.entities.IdentityProviderEntity)

Example 3 with 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());
}
Also used : IdentityProviderNameEntity(org.orcid.persistence.jpa.entities.IdentityProviderNameEntity) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) IdentityProviderEntity(org.orcid.persistence.jpa.entities.IdentityProviderEntity) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 4 with IdentityProviderEntity

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);
        }
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) IdentityProviderEntity(org.orcid.persistence.jpa.entities.IdentityProviderEntity) Document(org.w3c.dom.Document)

Example 5 with IdentityProviderEntity

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()));
}
Also used : ArrayList(java.util.ArrayList) IdentityProviderEntity(org.orcid.persistence.jpa.entities.IdentityProviderEntity)

Aggregations

IdentityProviderEntity (org.orcid.persistence.jpa.entities.IdentityProviderEntity)7 IdentityProviderNameEntity (org.orcid.persistence.jpa.entities.IdentityProviderNameEntity)4 Document (org.w3c.dom.Document)4 Element (org.w3c.dom.Element)4 XPath (javax.xml.xpath.XPath)3 XPathExpression (javax.xml.xpath.XPathExpression)3 ArrayList (java.util.ArrayList)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 Test (org.junit.Test)2 NodeList (org.w3c.dom.NodeList)2 Client (com.sun.jersey.api.client.Client)1 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 WebResource (com.sun.jersey.api.client.WebResource)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Function (java.util.function.Function)1 Pattern (java.util.regex.Pattern)1