Search in sources :

Example 81 with ClientDetailsEntity

use of org.orcid.persistence.jpa.entities.ClientDetailsEntity in project ORCID-Source by ORCID.

the class Jpa2JaxbAdapterImpl method toOrcidClientGroup.

@Override
public OrcidClientGroup toOrcidClientGroup(ProfileEntity profileEntity) {
    OrcidClientGroup group = new OrcidClientGroup();
    group.setGroupOrcid(profileEntity.getId());
    if (profileEntity.getRecordNameEntity() != null) {
        group.setGroupName(profileEntity.getRecordNameEntity().getCreditName());
    }
    group.setType(profileEntity.getGroupType());
    Set<EmailEntity> emailEntities = profileEntity.getEmails();
    for (EmailEntity emailEntity : emailEntities) {
        group.setEmail(emailEntity.getId());
    }
    for (ClientDetailsEntity clientDetailsEntity : profileEntity.getClients()) {
        OrcidClient client = toOrcidClient(clientDetailsEntity);
        group.getOrcidClient().add(client);
    }
    return group;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) OrcidClientGroup(org.orcid.jaxb.model.clientgroup.OrcidClientGroup) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity)

Example 82 with ClientDetailsEntity

use of org.orcid.persistence.jpa.entities.ClientDetailsEntity in project ORCID-Source by ORCID.

the class ThirdPartyLinkManagerImpl method getClients.

private List<OrcidClient> getClients(RedirectUriType rut) {
    List<OrcidClient> orcidClients = new ArrayList<OrcidClient>();
    List<ClientRedirectUriEntity> entitiesWithPredefinedScopes = clientRedirectDao.findClientDetailsWithRedirectScope();
    for (ClientRedirectUriEntity entity : entitiesWithPredefinedScopes) {
        if (rut.value().equals(entity.getRedirectUriType())) {
            ClientDetailsEntity clientDetails = entity.getClientDetailsEntity();
            RedirectUri redirectUri = new RedirectUri(entity.getRedirectUri());
            String prefefinedScopes = entity.getPredefinedClientScope();
            redirectUri.setScope(new ArrayList<ScopePathType>(ScopePathType.getScopesFromSpaceSeparatedString(prefefinedScopes)));
            redirectUri.setType(RedirectUriType.fromValue(entity.getRedirectUriType()));
            redirectUri.setActType(entity.getUriActType());
            redirectUri.setGeoArea(entity.getUriGeoArea());
            RedirectUris redirectUris = new RedirectUris();
            redirectUris.getRedirectUri().add(redirectUri);
            OrcidClient minimalClientDetails = new OrcidClient();
            minimalClientDetails.setDisplayName(clientDetails.getClientName());
            minimalClientDetails.setShortDescription(clientDetails.getClientDescription());
            minimalClientDetails.setClientId(clientDetails.getClientId());
            minimalClientDetails.setRedirectUris(redirectUris);
            orcidClients.add(minimalClientDetails);
        }
    }
    return orcidClients;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) ArrayList(java.util.ArrayList) RedirectUri(org.orcid.jaxb.model.clientgroup.RedirectUri) RedirectUris(org.orcid.jaxb.model.clientgroup.RedirectUris) ClientRedirectUriEntity(org.orcid.persistence.jpa.entities.ClientRedirectUriEntity)

Example 83 with ClientDetailsEntity

use of org.orcid.persistence.jpa.entities.ClientDetailsEntity in project ORCID-Source by ORCID.

the class SourceManagerImpl method retrieveSourceEntity.

@Override
public SourceEntity retrieveSourceEntity() {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (authentication == null) {
        return null;
    }
    // API
    if (OAuth2Authentication.class.isAssignableFrom(authentication.getClass())) {
        OAuth2Request authorizationRequest = ((OAuth2Authentication) authentication).getOAuth2Request();
        String clientId = authorizationRequest.getClientId();
        ClientDetailsEntity clientDetails = clientDetailsManager.findByClientId(clientId);
        SourceEntity sourceEntity = new SourceEntity();
        sourceEntity.setSourceClient(new ClientDetailsEntity(clientId, clientDetails.getClientName()));
        sourceEntity.getSourceName();
        return sourceEntity;
    }
    String userOrcid = retrieveEffectiveOrcid(authentication);
    if (userOrcid == null) {
        // Must be system role
        return null;
    }
    // Normal web user
    SourceEntity sourceEntity = new SourceEntity();
    sourceEntity.setSourceProfile(new ProfileEntity(userOrcid));
    return sourceEntity;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Authentication(org.springframework.security.core.Authentication) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 84 with ClientDetailsEntity

use of org.orcid.persistence.jpa.entities.ClientDetailsEntity in project ORCID-Source by ORCID.

the class ClientDetailsManagerReadOnlyImpl method findByClientId.

@Override
public ClientDetailsEntity findByClientId(String clientId) {
    ClientDetailsEntity result = null;
    try {
        Date lastModified = clientDetailsDao.getLastModified(clientId);
        result = clientDetailsDao.findByClientId(clientId, lastModified.getTime());
        if (result != null) {
            if (!result.getClientId().equals(clientId))
                LOGGER.error("Client getClientId doesn't match. Requested: " + clientId + " Returned: " + result.getClientId());
            if (!result.getId().equals(clientId))
                LOGGER.error("Client getId() doesn't match. Requested: " + clientId + " Returned: " + result.getId());
        }
    } catch (NoResultException nre) {
        LOGGER.error("Error getting client by id:" + clientId, nre);
    }
    return result;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) NoResultException(javax.persistence.NoResultException) Date(java.util.Date)

Example 85 with ClientDetailsEntity

use of org.orcid.persistence.jpa.entities.ClientDetailsEntity in project ORCID-Source by ORCID.

the class NotificationManagerTest method testAmendEmail.

@Test
public void testAmendEmail() throws JAXBException, IOException, URISyntaxException {
    SourceEntity sourceEntity = new SourceEntity(new ClientDetailsEntity("APP-5555555555555555"));
    when(sourceManager.retrieveSourceEntity()).thenReturn(sourceEntity);
    when(sourceManager.retrieveSourceOrcid()).thenReturn("APP-5555555555555555");
    String testOrcid = "0000-0000-0000-0003";
    for (Locale locale : Locale.values()) {
        NotificationEntity previousNotification = notificationDao.findLatestByOrcid(testOrcid);
        long minNotificationId = previousNotification != null ? previousNotification.getId() : -1;
        OrcidProfile orcidProfile = getProfile(locale);
        notificationManager.sendAmendEmail(orcidProfile, AmendedSection.UNKNOWN);
        // New notification entity should have been created
        NotificationEntity latestNotification = notificationDao.findLatestByOrcid(testOrcid);
        assertNotNull(latestNotification);
        assertTrue(latestNotification.getId() > minNotificationId);
        assertEquals(NotificationType.AMENDED, latestNotification.getNotificationType());
    }
}
Also used : Locale(org.orcid.jaxb.model.message.Locale) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) NotificationEntity(org.orcid.persistence.jpa.entities.NotificationEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)149 Test (org.junit.Test)75 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)57 BaseTest (org.orcid.core.BaseTest)51 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)33 Date (java.util.Date)23 Transactional (org.springframework.transaction.annotation.Transactional)16 HashSet (java.util.HashSet)15 DBUnitTest (org.orcid.test.DBUnitTest)15 HashMap (java.util.HashMap)14 Authentication (org.springframework.security.core.Authentication)13 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)13 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)11 Work (org.orcid.jaxb.model.record_v2.Work)9 Before (org.junit.Before)8 ArrayList (java.util.ArrayList)7 OrcidClient (org.orcid.jaxb.model.clientgroup.OrcidClient)7 ClientSecretEntity (org.orcid.persistence.jpa.entities.ClientSecretEntity)7 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)6 Funding (org.orcid.jaxb.model.record_v2.Funding)6