use of org.orcid.persistence.jpa.entities.ClientDetailsEntity in project ORCID-Source by ORCID.
the class NotificationManagerTest method testAddedDelegatesSentCorrectEmail.
@Test
public void testAddedDelegatesSentCorrectEmail() throws JAXBException, IOException, URISyntaxException {
TargetProxyHelper.injectIntoProxy(notificationManager, "profileEntityCacheManager", mockProfileEntityCacheManager);
TargetProxyHelper.injectIntoProxy(notificationManager, "emailManager", mockEmailManager);
TargetProxyHelper.injectIntoProxy(notificationManager, "profileDao", mockProfileDao);
TargetProxyHelper.injectIntoProxy(notificationManager, "notificationDao", mockNotificationDao);
TargetProxyHelper.injectIntoProxy(notificationManager, "notificationAdapter", mockNotificationAdapter);
final String orcid = "0000-0000-0000-0003";
String delegateOrcid = "1234-5678-1234-5678";
ProfileEntity profile = new ProfileEntity();
RecordNameEntity recordName = new RecordNameEntity();
recordName.setCreditName("My credit name");
recordName.setVisibility(Visibility.PUBLIC);
profile.setRecordNameEntity(recordName);
profile.setSendAdministrativeChangeNotifications(true);
profile.setSendChangeNotifications(true);
profile.setSendMemberUpdateRequests(true);
profile.setSendOrcidNews(true);
EmailEntity emailEntity = new EmailEntity();
emailEntity.setId("test@email.com");
emailEntity.setPrimary(true);
emailEntity.setCurrent(true);
Set<EmailEntity> emails = new HashSet<EmailEntity>();
emails.add(emailEntity);
profile.setEmails(emails);
SourceEntity sourceEntity = new SourceEntity(new ClientDetailsEntity("APP-5555555555555555"));
when(sourceManager.retrieveSourceEntity()).thenReturn(sourceEntity);
when(sourceManager.retrieveSourceOrcid()).thenReturn("APP-5555555555555555");
when(mockNotificationAdapter.toNotificationEntity(Mockito.any(Notification.class))).thenReturn(new NotificationCustomEntity());
Email email = new Email();
email.setEmail("test@email.com");
when(mockProfileEntityCacheManager.retrieve(Mockito.anyString())).thenAnswer(new Answer<ProfileEntity>() {
@Override
public ProfileEntity answer(InvocationOnMock invocation) throws Throwable {
profile.setId(invocation.getArgument(0));
return profile;
}
});
when(mockProfileDao.find(Mockito.anyString())).thenAnswer(new Answer<ProfileEntity>() {
@Override
public ProfileEntity answer(InvocationOnMock invocation) throws Throwable {
profile.setId(invocation.getArgument(0));
return profile;
}
});
when(mockEmailManager.findPrimaryEmail(orcid)).thenReturn(email);
DelegationDetails firstNewDelegate = new DelegationDetails();
DelegateSummary firstNewDelegateSummary = new DelegateSummary();
firstNewDelegateSummary.setCreditName(new CreditName("Jimmy Dove"));
firstNewDelegate.setDelegateSummary(firstNewDelegateSummary);
firstNewDelegateSummary.setOrcidIdentifier(new OrcidIdentifier(delegateOrcid));
for (org.orcid.jaxb.model.common_v2.Locale locale : org.orcid.jaxb.model.common_v2.Locale.values()) {
profile.setLocale(locale);
notificationManager.sendNotificationToAddedDelegate("0000-0000-0000-0003", firstNewDelegate);
}
}
use of org.orcid.persistence.jpa.entities.ClientDetailsEntity in project ORCID-Source by ORCID.
the class OrcidRandomValueTokenServicesTest method tokenExpireInAnHourTest.
/**
* Check that the token created with a non persistent code will expire within an hour
* */
@Test
public void tokenExpireInAnHourTest() throws InterruptedException {
Map<String, String> authorizationParameters = new HashMap<>();
String clientId = "4444-4444-4444-4441";
authorizationParameters.put(OAuth2Utils.CLIENT_ID, clientId);
authorizationParameters.put(OAuth2Utils.SCOPE, "/orcid-works/create");
authorizationParameters.put("code", "code2");
OAuth2Request request = new OAuth2Request(Collections.<String, String>emptyMap(), clientId, Collections.<GrantedAuthority>emptyList(), true, new HashSet<String>(Arrays.asList("/orcid-profile/read-limited")), Collections.<String>emptySet(), null, Collections.<String>emptySet(), Collections.<String, Serializable>emptyMap());
ClientDetailsEntity clientDetails = clientDetailsManager.findByClientId(clientId);
Authentication userAuthentication = new OrcidOauth2ClientAuthentication(clientDetails);
OAuth2Authentication authentication = new OAuth2Authentication(request, userAuthentication);
OAuth2AccessToken oauth2AccessToken = tokenServices.createAccessToken(authentication);
Date tokenExpiration = oauth2AccessToken.getExpiration();
Thread.sleep(2000);
//The token expires in less than one hour
assertFalse(tokenExpiration.after(oneHoursTime()));
}
use of org.orcid.persistence.jpa.entities.ClientDetailsEntity in project ORCID-Source by ORCID.
the class ClientDetailsManagerTest method testLoadClientByClientId.
@Test
@Rollback
@Transactional
public void testLoadClientByClientId() throws Exception {
List<ClientDetailsEntity> all = clientDetailsManager.getAll();
assertEquals(9, all.size());
for (ClientDetailsEntity clientDetailsEntity : all) {
ClientDetails clientDetails = clientDetailsManager.loadClientByClientId(clientDetailsEntity.getId());
assertNotNull(clientDetails);
if (!"APP-5555555555555555".equals(clientDetailsEntity.getId()) && !"APP-5555555555555556".equals(clientDetailsEntity.getId()) && !"APP-6666666666666666".equals(clientDetailsEntity.getId())) {
checkClientDetails(clientDetails);
}
}
}
use of org.orcid.persistence.jpa.entities.ClientDetailsEntity in project ORCID-Source by ORCID.
the class ClientDetailsManagerTest method testCreateClientDetailsWithRandomSecret.
@Test
@Rollback
@Transactional
public void testCreateClientDetailsWithRandomSecret() throws Exception {
Set<String> clientScopes = new HashSet<String>();
clientScopes.add("/orcid-profile/create");
Set<String> clientResourceIds = new HashSet<String>();
clientResourceIds.add("orcid-t2-api");
Set<String> clientAuthorizedGrantTypes = new HashSet<String>();
clientAuthorizedGrantTypes.add("client_credentials");
clientAuthorizedGrantTypes.add("authorization_code");
clientAuthorizedGrantTypes.add("refresh_token");
Set<RedirectUri> clientRegisteredRedirectUris = new HashSet<RedirectUri>();
clientRegisteredRedirectUris.add(new RedirectUri("http://www.google.com/"));
List<String> clientGrantedAuthorities = new ArrayList<String>();
clientGrantedAuthorities.add("ROLE_ADMIN");
ClientDetailsEntity clientDetails = clientDetailsManager.createClientDetails("4444-4444-4444-4446", CLIENT_NAME, CLIENT_DESCRIPTION, null, CLIENT_WEBSITE, ClientType.CREATOR, clientScopes, clientResourceIds, clientAuthorizedGrantTypes, clientRegisteredRedirectUris, clientGrantedAuthorities, true);
assertNotNull(clientDetails);
checkClientDetails(clientDetails);
}
use of org.orcid.persistence.jpa.entities.ClientDetailsEntity in project ORCID-Source by ORCID.
the class DeveloperToolsControllerTest method testResetClientSecret.
@Test
public void testResetClientSecret() throws Exception {
SSOCredentials ssoCredentials = new SSOCredentials();
ssoCredentials.setClientName(Text.valueOf("Client Name"));
ssoCredentials.setClientDescription(Text.valueOf("This is a test"));
ssoCredentials.setClientWebsite(Text.valueOf("http://client.com"));
Set<RedirectUri> redirectUris = new HashSet<RedirectUri>();
RedirectUri rUri = new RedirectUri();
rUri.setType(Text.valueOf("default"));
rUri.setValue(Text.valueOf("http://test.com"));
redirectUris.add(rUri);
ssoCredentials.setRedirectUris(redirectUris);
SSOCredentials result = developerToolsController.generateSSOCredentialsJson(ssoCredentials);
assertNotNull(result);
assertNotNull(result.getErrors());
assertEquals(result.getErrors().size(), 0);
Text clientSecret = result.getClientSecret();
assertTrue(developerToolsController.resetClientSecret(result.getClientOrcid().getValue()));
ClientDetailsEntity clientDetails = clientDetailsDao.findByClientId(result.getClientOrcid().getValue(), System.currentTimeMillis());
assertEquals(result.getClientName().getValue(), clientDetails.getClientName());
assertEquals(result.getClientDescription().getValue(), clientDetails.getClientDescription());
assertEquals(result.getClientOrcid().getValue(), clientDetails.getClientId());
assertEquals(result.getClientWebsite().getValue(), clientDetails.getClientWebsite());
Set<ClientSecretEntity> clientSecrets = clientDetails.getClientSecrets();
assertNotNull(clientSecrets);
assertEquals(2, clientSecrets.size());
for (ClientSecretEntity clientSecretEntity : clientSecrets) {
String secret = encryptionManager.decryptForInternalUse(clientSecretEntity.getClientSecret());
if (!clientSecretEntity.isPrimary())
assertEquals(clientSecret.getValue(), secret);
else
assertFalse(clientSecret.getValue().equals(secret));
}
}
Aggregations