Search in sources :

Example 86 with ClientDetailsEntity

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

the class InstitutionalSignInManagerTest method testDontPersistIfUserConnectionAlreadyExists.

@Test
public void testDontPersistIfUserConnectionAlreadyExists() throws UnsupportedEncodingException {
    ClientDetailsEntity testClient = new ClientDetailsEntity(clientId);
    when(mock_userConnectionDao.findByProviderIdAndProviderUserIdAndIdType(anyString(), anyString(), anyString())).thenReturn(new UserconnectionEntity());
    when(mock_clientDetailsEntityCacheManager.retrieveByIdP(anyString())).thenReturn(testClient);
    when(mock_orcidOauth2TokenDetailService.doesClientKnowUser(anyString(), anyString())).thenReturn(false);
    institutionalSignInManager.createUserConnectionAndNotify("idType", "remoteUserId", "displayName", "providerId", userOrcid, Collections.<String, String>emptyMap());
    verify(mock_userConnectionDao, never()).persist(any());
    verify(mock_notificationManager, times(1)).sendAcknowledgeMessage(userOrcid, clientId);
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) UserconnectionEntity(org.orcid.persistence.jpa.entities.UserconnectionEntity) Test(org.junit.Test)

Example 87 with ClientDetailsEntity

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

the class InstitutionalSignInManagerTest method testCreateUserConnectionAndNotify.

@Test
public void testCreateUserConnectionAndNotify() throws UnsupportedEncodingException {
    ClientDetailsEntity testClient = new ClientDetailsEntity(clientId);
    when(mock_userConnectionDao.findByProviderIdAndProviderUserIdAndIdType(anyString(), anyString(), anyString())).thenReturn(null);
    when(mock_clientDetailsEntityCacheManager.retrieveByIdP(anyString())).thenReturn(testClient);
    when(mock_orcidOauth2TokenDetailService.doesClientKnowUser(anyString(), anyString())).thenReturn(false);
    institutionalSignInManager.createUserConnectionAndNotify("idType", "remoteUserId", "displayName", "providerId", userOrcid, Collections.<String, String>emptyMap());
    verify(mock_userConnectionDao, times(1)).persist(any());
    verify(mock_notificationManager, times(1)).sendAcknowledgeMessage(userOrcid, clientId);
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) Test(org.junit.Test)

Example 88 with ClientDetailsEntity

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

the class IdentifierTypeManagerTest method before.

@Before
public void before() throws Exception {
    TargetProxyHelper.injectIntoProxy(idTypeMan, "sourceManager", sourceManager);
    TargetProxyHelper.injectIntoProxy(idTypeMan, "securityManager", securityManager);
    doNothing().when(securityManager).checkSource(Matchers.any(IdentifierTypeEntity.class));
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) IdentifierTypeEntity(org.orcid.persistence.jpa.entities.IdentifierTypeEntity) Before(org.junit.Before)

Example 89 with ClientDetailsEntity

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

the class OrcidClientGroupManagerTest method testCreateOrcidClientGroup.

@Test
public void testCreateOrcidClientGroup() {
    OrcidClientGroup createdGroup = orcidClientGroupManager.createOrUpdateOrcidClientGroup(group);
    assertNotNull(createdGroup);
    assertEquals(group.getGroupName(), createdGroup.getGroupName());
    assertEquals(group.getEmail(), createdGroup.getEmail());
    assertNotNull(createdGroup.getGroupOrcid());
    List<OrcidClient> createdClients = createdGroup.getOrcidClient();
    assertNotNull(createdClients);
    assertEquals(2, createdClients.size());
    Map<String, OrcidClient> createdClientsMappedByName = new HashMap<String, OrcidClient>();
    for (OrcidClient createdClient : createdClients) {
        assertNotNull(createdClient.getClientId());
        assertNotNull(createdClient.getClientSecret());
        assertNotNull(createdClient.getIdp());
        createdClientsMappedByName.put(createdClient.getDisplayName(), createdClient);
    }
    OrcidClient complexityClient = createdClientsMappedByName.get("Ecological Complexity");
    assertNotNull(complexityClient);
    assertEquals("http://www.journals.elsevier.com/ecological-complexity", complexityClient.getWebsite());
    assertEquals("An International Journal on Biocomplexity in the Environment and Theoretical Ecology", complexityClient.getShortDescription());
    List<RedirectUri> createdRedirectUris = complexityClient.getRedirectUris().getRedirectUri();
    assertNotNull(createdRedirectUris);
    assertEquals(1, createdRedirectUris.size());
    assertEquals("http://www.journals.elsevier.com/ecological-complexity/orcid-callback", createdRedirectUris.get(0).getValue());
    assertEquals("grant-read-wizard", createdRedirectUris.get(0).getType().value());
    List<ScopePathType> scopesForRedirect = createdRedirectUris.get(0).getScope();
    assertTrue(scopesForRedirect.size() == 2);
    assertTrue(scopesForRedirect.contains(ScopePathType.ORCID_PROFILE_CREATE) && scopesForRedirect.contains(ScopePathType.ORCID_BIO_READ_LIMITED));
    assertEquals("http://www.journals.elsevier.com/ecological-complexity/orcid-callback", createdRedirectUris.get(0).getValue());
    assertEquals("grant-read-wizard", createdRedirectUris.get(0).getType().value());
    // Look up client details directly to check scopes
    ClientDetailsEntity complexityEntity = clientDetailsManager.findByClientId(complexityClient.getClientId());
    Set<String> clientScopeTypes = complexityEntity.getScope();
    assertNotNull(clientScopeTypes);
    assertTrue(clientScopeTypes.contains("/orcid-bio/update"));
    assertTrue(clientScopeTypes.contains("/orcid-bio/read-limited"));
    assertTrue(clientScopeTypes.contains("/orcid-works/read-limited"));
    assertFalse(clientScopeTypes.contains("/orcid-profile/create"));
    assertTrue(clientScopeTypes.contains("/authenticate"));
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) OrcidClientGroup(org.orcid.jaxb.model.clientgroup.OrcidClientGroup) HashMap(java.util.HashMap) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) RedirectUri(org.orcid.jaxb.model.clientgroup.RedirectUri) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 90 with ClientDetailsEntity

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

the class OrcidClientGroupManagerTest method testUpdateGroup.

@Test
public void testUpdateGroup() {
    final OrcidClientGroup createdGroup = transactionTemplate.execute(new TransactionCallback<OrcidClientGroup>() {

        public OrcidClientGroup doInTransaction(TransactionStatus status) {
            return orcidClientGroupManager.createOrUpdateOrcidClientGroup(group);
        }
    });
    assertNotNull(createdGroup);
    assertEquals(MemberType.PREMIUM, createdGroup.getType());
    Set<String> premiumScopes = orcidClientGroupManager.premiumUpdaterScopes();
    //Get existing clients
    List<ClientDetailsEntity> clients = clientDetailsManager.findByGroupId(createdGroup.getGroupOrcid());
    assertEquals(2, clients.size());
    for (ClientDetailsEntity clientDetails : clients) {
        assertEquals(ClientType.PREMIUM_UPDATER, clientDetails.getClientType());
        assertTrue(clientDetails.isScoped());
        assertEquals(premiumScopes.size(), clientDetails.getScope().size());
    }
    //Update the group type
    createdGroup.setType(MemberType.PREMIUM_INSTITUTION);
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            orcidClientGroupManager.updateGroup(createdGroup);
        }
    });
    Set<String> premiumInstitutionScopes = orcidClientGroupManager.premiumCreatorScopes();
    clients = clientDetailsManager.findByGroupId(createdGroup.getGroupOrcid());
    assertEquals(2, clients.size());
    for (ClientDetailsEntity clientDetails : clients) {
        assertEquals(ClientType.PREMIUM_CREATOR, clientDetails.getClientType());
        assertTrue(clientDetails.isScoped());
        assertEquals(premiumInstitutionScopes.size(), clientDetails.getScope().size());
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) OrcidClientGroup(org.orcid.jaxb.model.clientgroup.OrcidClientGroup) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

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