use of org.orcid.persistence.jpa.entities.ClientDetailsEntity in project ORCID-Source by ORCID.
the class DeveloperToolsController method resetClientSecret.
@RequestMapping(value = "/reset-client-secret", method = RequestMethod.POST)
@ResponseBody
public boolean resetClientSecret(@RequestBody String clientId) {
//Verify this client belongs to the user
ClientDetailsEntity clientDetails = clientDetailsManager.findByClientId(clientId);
if (clientDetails == null)
return false;
ProfileEntity groupProfile = profileEntityCacheManager.retrieve(clientDetails.getGroupProfileId());
if (groupProfile == null)
return false;
if (!groupProfile.getId().equals(getCurrentUserOrcid()))
return false;
return orcidSSOManager.resetClientSecret(clientId);
}
use of org.orcid.persistence.jpa.entities.ClientDetailsEntity in project ORCID-Source by ORCID.
the class DeveloperToolsController method getSSOCredentialsJson.
@RequestMapping(value = "/get-sso-credentials.json", method = RequestMethod.GET)
@ResponseBody
public SSOCredentials getSSOCredentialsJson() {
SSOCredentials credentials = new SSOCredentials();
String userOrcid = getEffectiveUserOrcid();
ClientDetailsEntity existingClientDetails = orcidSSOManager.getUserCredentials(userOrcid);
if (existingClientDetails != null)
credentials = SSOCredentials.toSSOCredentials(existingClientDetails);
return credentials;
}
use of org.orcid.persistence.jpa.entities.ClientDetailsEntity in project ORCID-Source by ORCID.
the class AnalyticsProcess method getClientDetailsString.
private String getClientDetailsString() {
if (clientDetailsId != null) {
ClientDetailsEntity client = clientDetailsEntityCacheManager.retrieve(clientDetailsId);
StringBuilder clientDetails = new StringBuilder(client.getClientType().value());
clientDetails.append(" | ");
clientDetails.append(client.getClientName());
clientDetails.append(" - ");
clientDetails.append(clientDetailsId);
return clientDetails.toString();
} else {
return PUBLIC_API_USER;
}
}
use of org.orcid.persistence.jpa.entities.ClientDetailsEntity in project ORCID-Source by ORCID.
the class ClientDetailsManagerImpl method cleanOldClientKeys.
/**
* Removes all non primary client secret keys
*
* @param clientId
* */
@Override
@Transactional
public void cleanOldClientKeys() {
LOGGER.info("Starting cron to delete non primary client keys");
Date currentDate = new Date();
List<ClientDetailsEntity> allClientDetails = this.getAll();
if (allClientDetails != null && allClientDetails != null) {
for (ClientDetailsEntity clientDetails : allClientDetails) {
String clientId = clientDetails.getClientId();
LOGGER.info("Deleting non primary keys for client: {}", clientId);
Set<ClientSecretEntity> clientSecrets = clientDetails.getClientSecrets();
for (ClientSecretEntity clientSecret : clientSecrets) {
if (!clientSecret.isPrimary()) {
Date dateRevoked = clientSecret.getLastModified();
Date timeToDeleteMe = DateUtils.addHours(dateRevoked, 24);
// If the key have been revokend more than 24 hours ago
if (timeToDeleteMe.before(currentDate)) {
LOGGER.info("Deleting key for client {}", clientId);
clientSecretDao.removeClientSecret(clientId, clientSecret.getClientSecret());
}
}
}
}
}
LOGGER.info("Cron done");
}
use of org.orcid.persistence.jpa.entities.ClientDetailsEntity in project ORCID-Source by ORCID.
the class ClientDetailsEntityCacheManagerImpl method retrieve.
@Override
public ClientDetailsEntity retrieve(String clientId) throws IllegalArgumentException {
Object key = new ClientIdCacheKey(clientId, releaseName);
Date dbDate = retrieveLastModifiedDate(clientId);
ClientDetailsEntity clientDetails = toClientDetailsEntity(clientDetailsCache.get(key));
if (needsFresh(dbDate, clientDetails)) {
try {
synchronized (lockers.obtainLock(clientId)) {
clientDetails = toClientDetailsEntity(clientDetailsCache.get(key));
if (needsFresh(dbDate, clientDetails)) {
clientDetails = clientDetailsManager.findByClientId(clientId);
if (clientDetails == null)
throw new IllegalArgumentException("Invalid client id " + clientId);
clientDetailsCache.put(new Element(key, clientDetails));
}
}
} finally {
lockers.releaseLock(clientId);
}
}
return clientDetails;
}
Aggregations