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();
}
}
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);
}
}
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);
}
}
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);
}
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);
}
Aggregations