Search in sources :

Example 61 with ClientDetailsEntity

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);
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 62 with ClientDetailsEntity

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;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SSOCredentials(org.orcid.pojo.ajaxForm.SSOCredentials) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 63 with ClientDetailsEntity

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;
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity)

Example 64 with ClientDetailsEntity

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");
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ClientSecretEntity(org.orcid.persistence.jpa.entities.ClientSecretEntity) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 65 with ClientDetailsEntity

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;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) Element(net.sf.ehcache.Element) Date(java.util.Date)

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