Search in sources :

Example 76 with ClientDetailsEntity

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

the class ProfileDaoTest method testInsertClient.

@Test
@Rollback(true)
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testInsertClient() {
    String clientOrcid = "4444-1111-6666-4444";
    ClientDetailsEntity client = new ClientDetailsEntity();
    client.setId(clientOrcid);
    String groupOrcid = "4444-4444-4444-4441";
    client.setGroupProfileId(groupOrcid);
    clientDetailsDao.persist(client);
    clientDetailsDao.flush();
    client = clientDetailsDao.find(clientOrcid);
    assertNotNull(client);
    assertEquals(clientOrcid, client.getId());
    ProfileEntity groupProfile = profileDao.find(groupOrcid);
    assertNotNull(groupProfile);
    assertNotNull(groupProfile.getClients());
    assertEquals(1, groupProfile.getClients().size());
    assertEquals(clientOrcid, groupProfile.getClients().iterator().next().getId());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 77 with ClientDetailsEntity

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

the class ProfileDaoTest method testInsertGroupWithClients.

@Test
@Rollback(true)
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testInsertGroupWithClients() {
    String groupOrcid = "4444-1111-6666-4444";
    ProfileEntity groupProfile = new ProfileEntity();
    groupProfile.setId(groupOrcid);
    groupProfile.setOrcidType(OrcidType.GROUP);
    groupProfile.setGroupType(MemberType.BASIC);
    SortedSet<ClientDetailsEntity> clients = new TreeSet<>(new OrcidEntityIdComparator<String>());
    String clientOrcid1 = "4444-4444-4444-4442";
    ClientDetailsEntity clientProfile1 = new ClientDetailsEntity();
    clientProfile1.setId(clientOrcid1);
    clients.add(clientProfile1);
    String clientOrcid2 = "4444-4444-4444-4443";
    ClientDetailsEntity clientProfile2 = new ClientDetailsEntity();
    clientProfile2.setId(clientOrcid2);
    clients.add(clientProfile2);
    groupProfile.setClients(clients);
    profileDao.persist(groupProfile);
    profileDao.flush();
    groupProfile = profileDao.find(groupOrcid);
    assertNotNull(groupProfile);
    assertEquals(groupOrcid, groupProfile.getId());
    assertEquals(MemberType.BASIC, groupProfile.getGroupType());
    assertNotNull(groupProfile.getClients());
    assertEquals(2, groupProfile.getClients().size());
    Map<String, ClientDetailsEntity> map = ProfileEntity.mapById(groupProfile.getClients());
    assertTrue(map.containsKey(clientOrcid1));
    assertTrue(map.containsKey(clientOrcid2));
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) TreeSet(java.util.TreeSet) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 78 with ClientDetailsEntity

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

the class IdentifierTypeDaoTest method test4FetchIDList.

@Test
public void test4FetchIDList() {
    List<IdentifierTypeEntity> list = idTypeDao.getEntities();
    int startSize = list.size();
    IdentifierTypeEntity e1 = new IdentifierTypeEntity();
    e1.setName("TEST_B");
    ClientDetailsEntity sourceClient = new ClientDetailsEntity();
    sourceClient.setId("APP-6666666666666666");
    e1.setSourceClient(sourceClient);
    idTypeDao.addIdentifierType(e1);
    list = idTypeDao.getEntities();
    assertEquals(startSize + 1, list.size());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) IdentifierTypeEntity(org.orcid.persistence.jpa.entities.IdentifierTypeEntity) Test(org.junit.Test) DBUnitTest(org.orcid.test.DBUnitTest)

Example 79 with ClientDetailsEntity

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

the class LoginController method handleOauthSignIn.

private ModelAndView handleOauthSignIn(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
    String queryString = request.getQueryString();
    String redirectUri = null;
    // Get and save the request information form
    RequestInfoForm requestInfoForm = generateRequestInfoForm(queryString);
    request.getSession().setAttribute(REQUEST_INFO_FORM, requestInfoForm);
    // Save also the original query string
    request.getSession().setAttribute("queryString", queryString);
    // Save a flag to indicate this is a request from the new 
    request.getSession().setAttribute("OAUTH_2SCREENS", true);
    // Redirect URI
    redirectUri = requestInfoForm.getRedirectUrl();
    // Check that the client have the required permissions
    // Get client name
    String clientId = requestInfoForm.getClientId();
    if (PojoUtil.isEmpty(clientId)) {
        String redirectUriWithParams = redirectUri + "?error=invalid_client&error_description=invalid client_id";
        return new ModelAndView(new RedirectView(redirectUriWithParams));
    }
    // Validate client details
    ClientDetailsEntity clientDetails = clientDetailsEntityCacheManager.retrieve(clientId);
    try {
        orcidOAuth2RequestValidator.validateClientIsEnabled(clientDetails);
    } catch (LockedException e) {
        String redirectUriWithParams = redirectUri + "?error=client_locked&error_description=" + e.getMessage();
        return new ModelAndView(new RedirectView(redirectUriWithParams));
    }
    // validate client scopes
    try {
        authorizationEndpoint.validateScope(requestInfoForm.getScopesAsString(), clientDetails);
    } catch (InvalidScopeException e) {
        String redirectUriWithParams = redirectUri + "?error=invalid_scope&error_description=" + e.getMessage();
        return new ModelAndView(new RedirectView(redirectUriWithParams));
    }
    ModelAndView mav = new ModelAndView("login");
    mav.addObject("hideUserVoiceScript", true);
    mav.addObject("oauth2Screens", true);
    return mav;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) LockedException(org.orcid.core.security.aop.LockedException) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) RequestInfoForm(org.orcid.pojo.ajaxForm.RequestInfoForm) InvalidScopeException(org.springframework.security.oauth2.common.exceptions.InvalidScopeException)

Example 80 with ClientDetailsEntity

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

the class NotificationController method getInstitutionalConnectionNotificationHtml.

@RequestMapping(value = "/INSTITUTIONAL_CONNECTION/{id}/notification.html", produces = OrcidApiConstants.HTML_UTF)
public ModelAndView getInstitutionalConnectionNotificationHtml(@PathVariable("id") String id) throws UnsupportedEncodingException {
    ModelAndView mav = new ModelAndView();
    Notification notification = notificationManager.findByOrcidAndId(getCurrentUserOrcid(), Long.valueOf(id));
    String clientId = notification.getSource().retrieveSourcePath();
    ClientDetailsEntity clientDetails = clientDetailsEntityCacheManager.retrieve(clientId);
    String authorizationUrl = notificationManager.buildAuthorizationUrlForInstitutionalSignIn(clientDetails);
    addSourceDescription(notification);
    mav.addObject("notification", notification);
    mav.addObject("baseUri", getBaseUri());
    mav.addObject("clientId", clientId);
    mav.addObject("authorizationUrl", authorizationUrl);
    mav.setViewName("notification/institutional_connection_notification");
    mav.addObject("noIndex", true);
    return mav;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ModelAndView(org.springframework.web.servlet.ModelAndView) Notification(org.orcid.jaxb.model.notification_v2.Notification) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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