use of org.orcid.persistence.jpa.entities.ClientDetailsEntity in project ORCID-Source by ORCID.
the class ProfileDaoTest method testInsertClient.
@Test
@Rollback(true)
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testInsertClient() {
String clientOrcid = "4444-1111-6666-4444";
ClientDetailsEntity client = new ClientDetailsEntity();
client.setId(clientOrcid);
String groupOrcid = "4444-4444-4444-4441";
client.setGroupProfileId(groupOrcid);
clientDetailsDao.persist(client);
clientDetailsDao.flush();
client = clientDetailsDao.find(clientOrcid);
assertNotNull(client);
assertEquals(clientOrcid, client.getId());
ProfileEntity groupProfile = profileDao.find(groupOrcid);
assertNotNull(groupProfile);
assertNotNull(groupProfile.getClients());
assertEquals(1, groupProfile.getClients().size());
assertEquals(clientOrcid, groupProfile.getClients().iterator().next().getId());
}
use of org.orcid.persistence.jpa.entities.ClientDetailsEntity in project ORCID-Source by ORCID.
the class ProfileDaoTest method testInsertGroupWithClients.
@Test
@Rollback(true)
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testInsertGroupWithClients() {
String groupOrcid = "4444-1111-6666-4444";
ProfileEntity groupProfile = new ProfileEntity();
groupProfile.setId(groupOrcid);
groupProfile.setOrcidType(OrcidType.GROUP);
groupProfile.setGroupType(MemberType.BASIC);
SortedSet<ClientDetailsEntity> clients = new TreeSet<>(new OrcidEntityIdComparator<String>());
String clientOrcid1 = "4444-4444-4444-4442";
ClientDetailsEntity clientProfile1 = new ClientDetailsEntity();
clientProfile1.setId(clientOrcid1);
clients.add(clientProfile1);
String clientOrcid2 = "4444-4444-4444-4443";
ClientDetailsEntity clientProfile2 = new ClientDetailsEntity();
clientProfile2.setId(clientOrcid2);
clients.add(clientProfile2);
groupProfile.setClients(clients);
profileDao.persist(groupProfile);
profileDao.flush();
groupProfile = profileDao.find(groupOrcid);
assertNotNull(groupProfile);
assertEquals(groupOrcid, groupProfile.getId());
assertEquals(MemberType.BASIC, groupProfile.getGroupType());
assertNotNull(groupProfile.getClients());
assertEquals(2, groupProfile.getClients().size());
Map<String, ClientDetailsEntity> map = ProfileEntity.mapById(groupProfile.getClients());
assertTrue(map.containsKey(clientOrcid1));
assertTrue(map.containsKey(clientOrcid2));
}
use of org.orcid.persistence.jpa.entities.ClientDetailsEntity in project ORCID-Source by ORCID.
the class IdentifierTypeDaoTest method test4FetchIDList.
@Test
public void test4FetchIDList() {
List<IdentifierTypeEntity> list = idTypeDao.getEntities();
int startSize = list.size();
IdentifierTypeEntity e1 = new IdentifierTypeEntity();
e1.setName("TEST_B");
ClientDetailsEntity sourceClient = new ClientDetailsEntity();
sourceClient.setId("APP-6666666666666666");
e1.setSourceClient(sourceClient);
idTypeDao.addIdentifierType(e1);
list = idTypeDao.getEntities();
assertEquals(startSize + 1, list.size());
}
use of org.orcid.persistence.jpa.entities.ClientDetailsEntity in project ORCID-Source by ORCID.
the class LoginController method handleOauthSignIn.
private ModelAndView handleOauthSignIn(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
String queryString = request.getQueryString();
String redirectUri = null;
// Get and save the request information form
RequestInfoForm requestInfoForm = generateRequestInfoForm(queryString);
request.getSession().setAttribute(REQUEST_INFO_FORM, requestInfoForm);
// Save also the original query string
request.getSession().setAttribute("queryString", queryString);
// Save a flag to indicate this is a request from the new
request.getSession().setAttribute("OAUTH_2SCREENS", true);
// Redirect URI
redirectUri = requestInfoForm.getRedirectUrl();
// Check that the client have the required permissions
// Get client name
String clientId = requestInfoForm.getClientId();
if (PojoUtil.isEmpty(clientId)) {
String redirectUriWithParams = redirectUri + "?error=invalid_client&error_description=invalid client_id";
return new ModelAndView(new RedirectView(redirectUriWithParams));
}
// Validate client details
ClientDetailsEntity clientDetails = clientDetailsEntityCacheManager.retrieve(clientId);
try {
orcidOAuth2RequestValidator.validateClientIsEnabled(clientDetails);
} catch (LockedException e) {
String redirectUriWithParams = redirectUri + "?error=client_locked&error_description=" + e.getMessage();
return new ModelAndView(new RedirectView(redirectUriWithParams));
}
// validate client scopes
try {
authorizationEndpoint.validateScope(requestInfoForm.getScopesAsString(), clientDetails);
} catch (InvalidScopeException e) {
String redirectUriWithParams = redirectUri + "?error=invalid_scope&error_description=" + e.getMessage();
return new ModelAndView(new RedirectView(redirectUriWithParams));
}
ModelAndView mav = new ModelAndView("login");
mav.addObject("hideUserVoiceScript", true);
mav.addObject("oauth2Screens", true);
return mav;
}
use of org.orcid.persistence.jpa.entities.ClientDetailsEntity in project ORCID-Source by ORCID.
the class NotificationController method getInstitutionalConnectionNotificationHtml.
@RequestMapping(value = "/INSTITUTIONAL_CONNECTION/{id}/notification.html", produces = OrcidApiConstants.HTML_UTF)
public ModelAndView getInstitutionalConnectionNotificationHtml(@PathVariable("id") String id) throws UnsupportedEncodingException {
ModelAndView mav = new ModelAndView();
Notification notification = notificationManager.findByOrcidAndId(getCurrentUserOrcid(), Long.valueOf(id));
String clientId = notification.getSource().retrieveSourcePath();
ClientDetailsEntity clientDetails = clientDetailsEntityCacheManager.retrieve(clientId);
String authorizationUrl = notificationManager.buildAuthorizationUrlForInstitutionalSignIn(clientDetails);
addSourceDescription(notification);
mav.addObject("notification", notification);
mav.addObject("baseUri", getBaseUri());
mav.addObject("clientId", clientId);
mav.addObject("authorizationUrl", authorizationUrl);
mav.setViewName("notification/institutional_connection_notification");
mav.addObject("noIndex", true);
return mav;
}
Aggregations