Search in sources :

Example 11 with ProfileEntity

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

the class OrcidClientGroupManagerImpl method createAndPersistClientProfile.

/**
     * Creates a new client and set the group orcid as the owner of that client
     * 
     * @param groupOrcid
     *            The group owner for this client
     * @param client
     *            The new client
     * @return the new OrcidClient
     */
public OrcidClient createAndPersistClientProfile(String groupOrcid, OrcidClient client) throws OrcidClientGroupManagementException {
    if (!isAllowedToAddNewClient(groupOrcid))
        throw new OrcidClientGroupManagementException("Your contract allows you to have only 1 client.");
    ProfileEntity groupProfileEntity = profileDao.find(groupOrcid);
    checkAndSetClientType(client, groupProfileEntity.getGroupType());
    // Use the client details service to create the client details
    ClientDetailsEntity clientDetailsEntity = createClientDetails(groupOrcid, client, client.getType());
    // Link the client to the copy of the profile cached in
    // memory by Hibernate
    SortedSet<ClientDetailsEntity> clientProfileEntities = groupProfileEntity.getClients();
    if (clientProfileEntities == null) {
        clientProfileEntities = new TreeSet<>(new OrcidEntityIdComparator<String>());
        groupProfileEntity.setClients(clientProfileEntities);
    }
    clientProfileEntities.add(clientDetailsEntity);
    return adapter.toOrcidClient(clientDetailsEntity);
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) OrcidEntityIdComparator(org.orcid.persistence.jpa.entities.OrcidEntityIdComparator) OrcidClientGroupManagementException(org.orcid.core.exception.OrcidClientGroupManagementException) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 12 with ProfileEntity

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

the class OrcidClientGroupManagerImpl method retrieveOrcidClientGroup.

@Override
@Transactional
public OrcidClientGroup retrieveOrcidClientGroup(String groupOrcid) {
    ProfileEntity profileEntity = profileDao.find(groupOrcid);
    if (profileEntity == null) {
        return null;
    }
    OrcidClientGroup group = adapter.toOrcidClientGroup(profileEntity);
    for (OrcidClient client : group.getOrcidClient()) {
        client.setClientSecret(encryptionManager.decryptForInternalUse(client.getClientSecret()));
    }
    return group;
}
Also used : OrcidClientGroup(org.orcid.jaxb.model.clientgroup.OrcidClientGroup) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with ProfileEntity

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

the class NotificationManagerImpl method sendOrcidLockedEmail.

@Override
public void sendOrcidLockedEmail(String orcidToLock) {
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcidToLock);
    Locale userLocale = getUserLocaleFromProfileEntity(profile);
    String subject = getSubject("email.subject.locked", userLocale);
    String email = emailManager.findPrimaryEmail(orcidToLock).getEmail();
    String emailFriendlyName = deriveEmailFriendlyName(profile);
    Map<String, Object> templateParams = new HashMap<String, Object>();
    templateParams.put("emailName", emailFriendlyName);
    templateParams.put("orcid", orcidToLock);
    templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
    templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp());
    templateParams.put("subject", subject);
    addMessageParams(templateParams, userLocale);
    // Generate body from template
    String body = templateManager.processTemplate("locked_orcid_email.ftl", templateParams);
    // Generate html from template
    String html = templateManager.processTemplate("locked_orcid_email_html.ftl", templateParams);
    mailGunManager.sendEmail(LOCKED_NOTIFY_ORCID_ORG, email, subject, body, html);
}
Also used : Locale(java.util.Locale) HashMap(java.util.HashMap) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 14 with ProfileEntity

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

the class RecordManagerReadOnlyImpl method getPreferences.

private Preferences getPreferences(String orcid) {
    Preferences preferences = new Preferences();
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
    org.orcid.jaxb.model.common_v2.Locale profileEntityLocale = profile.getLocale();
    if (profileEntityLocale != null) {
        preferences.setLocale(profileEntityLocale);
    }
    return preferences;
}
Also used : Preferences(org.orcid.jaxb.model.record_v2.Preferences) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 15 with ProfileEntity

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

the class DefaultOAuthClientVisibilityTest method testCheckClientPermissionsAllowOnlyPublicAndLimitedVisibility.

@Test
@Transactional
@Rollback
public void testCheckClientPermissionsAllowOnlyPublicAndLimitedVisibility() throws Exception {
    Set<String> resourceIds = new HashSet<String>(Arrays.asList("orcid"));
    HashSet<GrantedAuthority> grantedAuthorities = new HashSet<GrantedAuthority>(Arrays.asList(new SimpleGrantedAuthority("ROLE_CLIENT")));
    AuthorizationRequest request = new AuthorizationRequest("4444-4444-4444-4446", Arrays.asList("/orcid-bio/external-identifiers/create"));
    request.setAuthorities(grantedAuthorities);
    request.setResourceIds(resourceIds);
    ProfileEntity entity = new ProfileEntity("4444-4444-4444-4446");
    OrcidOauth2UserAuthentication oauth2UserAuthentication = new OrcidOauth2UserAuthentication(entity, true);
    // we care only that an OAuth client request results in the correct
    // visibilities
    OrcidOAuth2Authentication oAuth2Authentication = new OrcidOAuth2Authentication(request, oauth2UserAuthentication, "made-up-token");
    OrcidOauth2TokenDetail tokenDetail = new OrcidOauth2TokenDetail();
    tokenDetail.setScope("/orcid-bio/external-identifiers/create");
    tokenDetail.setDateCreated(new Date());
    when(orcidOauth2TokenDetailService.findNonDisabledByTokenValue(any(String.class))).thenReturn(tokenDetail);
    ScopePathType scopePathType = ScopePathType.ORCID_BIO_EXTERNAL_IDENTIFIERS_CREATE;
    Set<Visibility> visibilitiesForClient = permissionChecker.obtainVisibilitiesForAuthentication(oAuth2Authentication, scopePathType, getOrcidMessage());
    assertTrue(visibilitiesForClient.size() == 3);
    assertTrue(visibilitiesForClient.contains(Visibility.LIMITED));
    assertTrue(visibilitiesForClient.contains(Visibility.REGISTERED_ONLY));
    assertTrue(visibilitiesForClient.contains(Visibility.PUBLIC));
}
Also used : AuthorizationRequest(org.springframework.security.oauth2.provider.AuthorizationRequest) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) OrcidOAuth2Authentication(org.orcid.core.oauth.OrcidOAuth2Authentication) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) OrcidOauth2UserAuthentication(org.orcid.core.oauth.OrcidOauth2UserAuthentication) Visibility(org.orcid.jaxb.model.message.Visibility) OrcidOauth2TokenDetail(org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail) HashSet(java.util.HashSet) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)374 Date (java.util.Date)107 Test (org.junit.Test)107 HashMap (java.util.HashMap)74 Transactional (org.springframework.transaction.annotation.Transactional)74 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)71 DBUnitTest (org.orcid.test.DBUnitTest)65 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)48 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)44 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)37 HashSet (java.util.HashSet)35 RecordNameEntity (org.orcid.persistence.jpa.entities.RecordNameEntity)35 Locale (java.util.Locale)34 Rollback (org.springframework.test.annotation.Rollback)27 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)26 ArrayList (java.util.ArrayList)25 EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)21 Set (java.util.Set)17 Authentication (org.springframework.security.core.Authentication)17 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)16