Skip to content

Commit

Permalink
Merge branch 'main' into add-summary-to-summary.json-and-mapi-summary…
Browse files Browse the repository at this point in the history
…-endpoint
  • Loading branch information
auumgn committed Nov 5, 2024
2 parents 012da05 + 4f76902 commit 850833b
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 41 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## v2.67.10 - 2024-11-05

[Full Changelog](https://github.com/ORCID/ORCID-Source/compare/v2.67.9...v2.67.10)

## v2.67.9 - 2024-11-05

[Full Changelog](https://github.com/ORCID/ORCID-Source/compare/v2.67.8...v2.67.9)

## v2.67.8 - 2024-11-04

[Full Changelog](https://github.com/ORCID/ORCID-Source/compare/v2.67.7...v2.67.8)

## v2.67.7 - 2024-11-04

[Full Changelog](https://github.com/ORCID/ORCID-Source/compare/v2.67.6...v2.67.7)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ public interface OrcidTokenStore extends TokenStore {
OAuth2Authentication readAuthenticationFromCachedToken(Map<String, String> cachedTokenData);

void isClientEnabled(String clientId) throws InvalidTokenException;

String readClientId(String tokenValue);
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ public OrcidOauth2TokenDetail readOrcidOauth2TokenDetail(String token) {
return orcidOauthTokenDetailService.findIgnoringDisabledByTokenValue(token);
}

@Override
public String readClientId(String token) {
String clientId = null;
OrcidOauth2TokenDetail orcidTokenDetail = orcidOauthTokenDetailService.findIgnoringDisabledByTokenValue(token);
if(orcidTokenDetail != null) {
clientId = orcidTokenDetail.getClientDetailsId();
}
return clientId;
}

/**
* Read the authentication stored under the specified token value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@

<!-- Panoply Redshift -->
<bean id="panoplyRedshiftDataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<property name="driverClassName" value="\${org.orcid.core.utils.panoply.driver:com.amazon.redshift.jdbc.Driver}" />
<property name="jdbcUrl" value="\${org.orcid.core.utils.panoply.jdbcUrl}" />
<property name="username" value="\${org.orcid.core.utils.panoply.username}" />
<property name="password" value="\${org.orcid.core.utils.panoply.password}" />
<property name="maximumPoolSize" value="\${org.orcid.core.utils.panoply.maxPoolSize:5}" />
<property name="idleTimeout" value="\${org.orcid.core.utils.panoply.idleConnectionTimeout:3600}" />
<property name="connectionTimeout" value="\${org.orcid.core.utils.panoply.connectionTimeout:3600}" />
<property name="driverClassName" value="${org.orcid.core.utils.panoply.driver:com.amazon.redshift.jdbc.Driver}" />
<property name="jdbcUrl" value="${org.orcid.core.utils.panoply.jdbcUrl}" />
<property name="username" value="${org.orcid.core.utils.panoply.username}" />
<property name="password" value="${org.orcid.core.utils.panoply.password}" />
<property name="maximumPoolSize" value="${org.orcid.core.utils.panoply.maxPoolSize:5}" />
<property name="idleTimeout" value="${org.orcid.core.utils.panoply.idleConnectionTimeout:3600}" />
<property name="connectionTimeout" value="${org.orcid.core.utils.panoply.connectionTimeout:3600}" />
</bean>

<!-- Panoply JdbcTemplate Bean Definition -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public PublicApiDailyRateLimitDaoImpl() {

@Override
public PublicApiDailyRateLimitEntity findByClientIdAndRequestDate(String clientId, LocalDate requestDate) {
Query nativeQuery = entityManager.createNativeQuery("SELECT * FROM public_api_daily_rate_limit p client_id=:clientId and requestDate=:requestDate",
Query nativeQuery = entityManager.createNativeQuery("SELECT * FROM public_api_daily_rate_limit p where p.client_id=:clientId and p.request_date=:requestDate",
PublicApiDailyRateLimitEntity.class);
nativeQuery.setParameter("clientId", clientId);
nativeQuery.setParameter("requestDate", requestDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,13 +460,13 @@

<!-- Panoply Redshift -->
<bean id="panoplyRedshiftDataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<property name="driverClassName" value="\${org.orcid.core.utils.panoply.driver:com.amazon.redshift.jdbc.Driver}" />
<property name="jdbcUrl" value="\${org.orcid.core.utils.panoply.jdbcUrl}" />
<property name="username" value="\${org.orcid.core.utils.panoply.username}" />
<property name="password" value="\${org.orcid.core.utils.panoply.password}" />
<property name="maximumPoolSize" value="\${org.orcid.core.utils.panoply.maxPoolSize:5}" />
<property name="idleTimeout" value="\${org.orcid.core.utils.panoply.idleConnectionTimeout:3600}" />
<property name="connectionTimeout" value="\${org.orcid.core.utils.panoply.connectionTimeout:3600}" />
<property name="driverClassName" value="${org.orcid.core.utils.panoply.driver:com.amazon.redshift.jdbc.Driver}" />
<property name="jdbcUrl" value="${org.orcid.core.utils.panoply.jdbcUrl}" />
<property name="username" value="${org.orcid.core.utils.panoply.username}" />
<property name="password" value="${org.orcid.core.utils.panoply.password}" />
<property name="maximumPoolSize" value="${org.orcid.core.utils.panoply.maxPoolSize:5}" />
<property name="idleTimeout" value="${org.orcid.core.utils.panoply.idleConnectionTimeout:3600}" />
<property name="connectionTimeout" value="${org.orcid.core.utils.panoply.connectionTimeout:3600}" />
</bean>

<!-- Panoply JdbcTemplate Bean Definition -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.orcid.core.manager.impl.OrcidUrlManager;
import org.orcid.core.manager.v3.EmailManager;
import org.orcid.core.manager.v3.RecordNameManager;
import org.orcid.core.oauth.service.OrcidTokenStore;
import org.orcid.core.utils.OrcidRequestUtil;
import org.orcid.persistence.dao.ProfileDao;
import org.orcid.persistence.dao.PublicApiDailyRateLimitDao;
Expand Down Expand Up @@ -69,9 +70,12 @@ public class ApiRateLimitFilter extends OncePerRequestFilter {

@Autowired
private EmailManager emailManager;

@Resource
private PanoplyRedshiftClient panoplyClient;
private PanoplyRedshiftClient panoplyClient;

@Autowired
private OrcidTokenStore orcidTokenStore;

@Value("${org.orcid.papi.rate.limit.anonymous.requests:10000}")
private int anonymousRequestLimit;
Expand All @@ -81,9 +85,9 @@ public class ApiRateLimitFilter extends OncePerRequestFilter {

@Value("${org.orcid.papi.rate.limit.enabled:false}")
private boolean enableRateLimiting;

@Value("${org.orcid.persistence.panoply.papiExceededRate.production:false}")
private boolean enablePanoplyPapiExceededRateInProduction;
private boolean enablePanoplyPapiExceededRateInProduction;

private static final String TOO_MANY_REQUESTS_MSG = "Too Many Requests - You have exceeded the daily allowance of API calls.\\n"
+ "You can increase your daily quota by registering for and using Public API client credentials "
Expand All @@ -97,8 +101,20 @@ protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServl
throws ServletException, IOException {
LOG.trace("ApiRateLimitFilter starts, rate limit is : " + enableRateLimiting);
if (enableRateLimiting) {
String clientId = orcidSecurityManager.getClientIdFromAPIRequest();
String ipAddress = OrcidRequestUtil.getIpAddress(httpServletRequest);
String tokenValue = null;
if (httpServletRequest.getHeader("Authorization") != null) {
tokenValue = httpServletRequest.getHeader("Authorization").replaceAll("Bearer|bearer", "").trim();
}
String ipAddress = httpServletRequest.getRemoteAddr();

String clientId = null;
if (tokenValue != null) {
try {
clientId = orcidTokenStore.readClientId(tokenValue);
} catch (Exception ex) {
LOG.error("Exception when trying to get the client id from token value, ignoring and treating as anonymous client", ex);
}
}
boolean isAnonymous = (clientId == null);
LocalDate today = LocalDate.now();

Expand Down Expand Up @@ -163,17 +179,16 @@ private void rateLimitClientRequest(String clientId, LocalDate today) {
}
// update the request count
rateLimitEntity.setRequestCount(rateLimitEntity.getRequestCount() + 1);
papiRateLimitingDao.updatePublicApiDailyRateLimit(rateLimitEntity,true);
papiRateLimitingDao.updatePublicApiDailyRateLimit(rateLimitEntity, true);

} else {
// create
rateLimitEntity = new PublicApiDailyRateLimitEntity();
rateLimitEntity.setClientId(clientId);
rateLimitEntity.setRequestCount(0L);
rateLimitEntity.setRequestCount(1L);
rateLimitEntity.setRequestDate(today);
papiRateLimitingDao.persist(rateLimitEntity);
}


}

Expand Down Expand Up @@ -212,15 +227,14 @@ private void sendEmail(String clientId, LocalDate requestDate) {
}

// Send the email
boolean mailSent = mailGunManager.sendEmail(FROM_ADDRESS, email , SUBJECT, body, html);
boolean mailSent = mailGunManager.sendEmail(FROM_ADDRESS, email, SUBJECT, body, html);
if (!mailSent) {
throw new RuntimeException("Failed to send email for papi limits, orcid=" + profile.getId());
}
}



private void setPapiRateExceededItemInPanoply(PanoplyPapiDailyRateExceededItem item) {
//Store the rate exceeded item in panoply Db without blocking
// Store the rate exceeded item in panoply Db without blocking
CompletableFuture.supplyAsync(() -> {
try {
panoplyClient.addPanoplyPapiDailyRateExceeded(item);
Expand All @@ -229,9 +243,9 @@ private void setPapiRateExceededItemInPanoply(PanoplyPapiDailyRateExceededItem i
LOG.error("Cannot store the rateExceededItem to panoply ", e);
return false;
}
}).thenAccept(result -> {
if(! result) {
LOG.error("Async call to panoply for : " + item.toString() + " Stored: "+ result);
}).thenAccept(result -> {
if (!result) {
LOG.error("Async call to panoply for : " + item.toString() + " Stored: " + result);
}

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,12 +535,14 @@ public ModelAndView confirmDeactivateOrcidAccount(HttpServletRequest request, Ht
}
org.orcid.pojo.ajaxForm.Emails emails = org.orcid.pojo.ajaxForm.Emails.valueOf(v2Emails, emailDomains);
// Old emails are missing the source name and id -- assign the user as the source
for (org.orcid.pojo.ajaxForm.Email email: emails.getEmails()) {
if (email.getSource() == null && email.getSourceName() == null) {
String orcid = getCurrentUserOrcid();
String displayName = getPersonDetails(orcid, true).getDisplayName();
email.setSource(orcid);
email.setSourceName(displayName);
if (emails.getEmails() != null) {
for (org.orcid.pojo.ajaxForm.Email email : emails.getEmails()) {
if (email.getSource() == null && email.getSourceName() == null) {
String orcid = getCurrentUserOrcid();
String displayName = getPersonDetails(orcid, true).getDisplayName();
email.setSource(orcid);
email.setSourceName(displayName);
}
}
}
return emails;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,15 @@ PublicRecord getRecord(String orcid) {

org.orcid.pojo.ajaxForm.Emails emails = org.orcid.pojo.ajaxForm.Emails.valueOf(filteredEmails, emailDomains);
// Old emails are missing the source name and id -- assign the user as the source
for (org.orcid.pojo.ajaxForm.Email email: emails.getEmails()) {
if (email.getSource() == null && email.getSourceName() == null) {
email.setSource(orcid);
email.setSourceName(publicRecord.getDisplayName());
if (emails.getEmails() != null) {
for (org.orcid.pojo.ajaxForm.Email email: emails.getEmails()) {
if (email.getSource() == null && email.getSourceName() == null) {
email.setSource(orcid);
email.setSourceName(publicRecord.getDisplayName());
}
}
}

publicRecord.setEmails(emails);

// Fill external identifiers
Expand Down

0 comments on commit 850833b

Please sign in to comment.