Search in sources :

Example 1 with ClientDetailsEntity

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

the class OrcidApiServiceDelegatorImpl method redirectClientToGroup.

@Override
public Response redirectClientToGroup(String clientId) {
    ClientDetailsEntity clientDetails = clientDetailsManager.findByClientId(clientId);
    if (clientDetails == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    String groupOrcid = clientDetails.getGroupProfileId();
    URI groupUri;
    try {
        groupUri = new URI(jpa2JaxbAdapter.getOrcidIdBase(groupOrcid).getUri());
        return Response.seeOther(groupUri).build();
    } catch (URISyntaxException e) {
        LOGGER.error("Problem redirecting to group: {}", groupOrcid, e);
        return Response.serverError().build();
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 2 with ClientDetailsEntity

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

the class T2OrcidApiServiceDelegatorImpl method registerWebhook.

/**
     * Register a new webhook to the profile. As with all calls, if the message
     * contains any other elements, a 400 Bad Request will be returned.
     * 
     * @param orcid
     *            the identifier of the profile to add the webhook
     * @param uriInfo
     *            an uri object containing the webhook
     * @return If successful, returns a 2xx.
     * */
@Override
@AccessControl(requiredScope = ScopePathType.WEBHOOK)
public Response registerWebhook(UriInfo uriInfo, String orcid, String webhookUri) {
    @SuppressWarnings("unused") URI validatedWebhookUri = null;
    try {
        validatedWebhookUri = new URI(webhookUri);
    } catch (URISyntaxException e) {
        Object[] params = { webhookUri };
        throw new OrcidBadRequestException(localeManager.resolveMessage("apiError.badrequest_incorrect_webhook.exception", params));
    }
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    ClientDetailsEntity clientDetails = null;
    String clientId = null;
    if (OAuth2Authentication.class.isAssignableFrom(authentication.getClass())) {
        OAuth2Request authorizationRequest = ((OAuth2Authentication) authentication).getOAuth2Request();
        clientId = authorizationRequest.getClientId();
        clientDetails = clientDetailsManager.findByClientId(clientId);
    }
    if (profile != null && clientDetails != null) {
        WebhookEntityPk webhookPk = new WebhookEntityPk(profile, webhookUri);
        WebhookEntity webhook = webhookManager.find(webhookPk);
        boolean isNew = webhook == null;
        if (isNew) {
            webhook = new WebhookEntity();
            webhook.setProfile(profile);
            webhook.setDateCreated(new Date());
            webhook.setEnabled(true);
            webhook.setUri(webhookUri);
            webhook.setClientDetails(clientDetails);
        }
        webhookManager.update(webhook);
        return isNew ? Response.created(uriInfo.getAbsolutePath()).build() : Response.noContent().build();
    } else if (profile == null) {
        Map<String, String> params = new HashMap<String, String>();
        params.put("orcid", orcid);
        throw new OrcidNotFoundException(params);
    } else {
        Map<String, String> params = new HashMap<String, String>();
        params.put("client", clientId);
        throw new OrcidClientNotFoundException(params);
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) WebhookEntityPk(org.orcid.persistence.jpa.entities.keys.WebhookEntityPk) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) OrcidBadRequestException(org.orcid.core.exception.OrcidBadRequestException) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Authentication(org.springframework.security.core.Authentication) WebhookEntity(org.orcid.persistence.jpa.entities.WebhookEntity) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) OrcidNotFoundException(org.orcid.core.exception.OrcidNotFoundException) Map(java.util.Map) HashMap(java.util.HashMap) OrcidClientNotFoundException(org.orcid.core.exception.OrcidClientNotFoundException) AccessControl(org.orcid.core.security.visibility.aop.AccessControl)

Example 3 with ClientDetailsEntity

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

the class T2OrcidApiServiceDelegatorImpl method setSponsorFromAuthentication.

public void setSponsorFromAuthentication(OrcidProfile profile) {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (profile.getOrcidHistory() == null) {
        OrcidHistory orcidHistory = new OrcidHistory();
        orcidHistory.setCreationMethod(CreationMethod.API);
        profile.setOrcidHistory(orcidHistory);
    }
    profile.getOrcidHistory().setSubmissionDate(new SubmissionDate(DateUtils.convertToXMLGregorianCalendar(new Date())));
    if (OAuth2Authentication.class.isAssignableFrom(authentication.getClass())) {
        OAuth2Request authorizationRequest = ((OAuth2Authentication) authentication).getOAuth2Request();
        Source sponsor = new Source();
        String sponsorId = authorizationRequest.getClientId();
        ClientDetailsEntity clientDetails = clientDetailsManager.findByClientId(sponsorId);
        if (clientDetails != null) {
            sponsor.setSourceName(new SourceName(clientDetails.getClientName()));
            if (OrcidStringUtils.isClientId(sponsorId)) {
                sponsor.setSourceClientId(new SourceClientId(sponsorId));
            } else {
                sponsor.setSourceOrcid(new SourceOrcid(sponsorId));
            }
        }
        profile.getOrcidHistory().setSource(sponsor);
    }
}
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) OrcidHistory(org.orcid.jaxb.model.message.OrcidHistory) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) SourceClientId(org.orcid.jaxb.model.message.SourceClientId) SourceName(org.orcid.jaxb.model.message.SourceName) SourceOrcid(org.orcid.jaxb.model.message.SourceOrcid) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) Date(java.util.Date) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) Source(org.orcid.jaxb.model.message.Source)

Example 4 with ClientDetailsEntity

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

the class NotificationManagerImpl method sendAutoDeprecateNotification.

@Override
public void sendAutoDeprecateNotification(String primaryOrcid, String deprecatedOrcid) {
    ProfileEntity primaryProfileEntity = profileEntityCacheManager.retrieve(primaryOrcid);
    ProfileEntity deprecatedProfileEntity = profileEntityCacheManager.retrieve(deprecatedOrcid);
    ClientDetailsEntity clientDetails = clientDetailsEntityCacheManager.retrieve(deprecatedProfileEntity.getSource().getSourceId());
    Locale userLocale = LocaleUtils.toLocale(primaryProfileEntity.getLocale() == null ? org.orcid.jaxb.model.message.Locale.EN.value() : primaryProfileEntity.getLocale().value());
    // Create map of template params
    Map<String, Object> templateParams = new HashMap<String, Object>();
    String subject = getSubject("email.subject.auto_deprecate", userLocale);
    String baseUri = orcidUrlManager.getBaseUrl();
    Date deprecatedAccountCreationDate = deprecatedProfileEntity.getDateCreated();
    // Create map of template params
    templateParams.put("primaryId", primaryOrcid);
    templateParams.put("name", deriveEmailFriendlyName(primaryProfileEntity));
    templateParams.put("baseUri", baseUri);
    templateParams.put("subject", subject);
    templateParams.put("clientName", clientDetails.getClientName());
    templateParams.put("deprecatedAccountCreationDate", deprecatedAccountCreationDate);
    templateParams.put("deprecatedId", deprecatedOrcid);
    addMessageParams(templateParams, userLocale);
    // Generate html from template
    String html = templateManager.processTemplate("auto_deprecated_account_html.ftl", templateParams);
    NotificationCustom notification = new NotificationCustom();
    notification.setNotificationType(NotificationType.CUSTOM);
    notification.setSubject(subject);
    notification.setBodyHtml(html);
    createNotification(primaryOrcid, notification);
}
Also used : Locale(java.util.Locale) NotificationCustom(org.orcid.jaxb.model.notification.custom_v2.NotificationCustom) ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) HashMap(java.util.HashMap) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date)

Example 5 with ClientDetailsEntity

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

the class OrcidClientGroupManagerImpl method updateClient.

/**
     * Updates a client profile, updates can be adding or removing redirect uris
     * or updating the client fields
     * 
     * @param client
     *            The updated client
     * @return the updated OrcidClient
     */
public OrcidClient updateClient(OrcidClient client) {
    ClientDetailsEntity clientDetailsEntity = null;
    if (client.getClientId() != null) {
        // Look up the existing client.
        String clientId = client.getClientId();
        clientDetailsEntity = clientDetailsDao.find(clientId);
        if (clientDetailsEntity == null) {
            // error.
            throw new OrcidClientGroupManagementException("Unable to find client: " + clientId);
        } else {
            // If the existing client is found, then update the client
            // details from the incoming client, and save using the
            // client details manager.
            updateClientDetailsEntityFromClient(client, clientDetailsEntity, true);
            clientDetailsManager.merge(clientDetailsEntity);
        }
    }
    return adapter.toOrcidClient(clientDetailsEntity);
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) OrcidClientGroupManagementException(org.orcid.core.exception.OrcidClientGroupManagementException)

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