use of org.orcid.persistence.jpa.entities.UserconnectionPK in project ORCID-Source by ORCID.
the class ProfileEntityManagerImplTest method testDeprecateProfile.
@Test
public void testDeprecateProfile() throws Exception {
UserconnectionPK pk = new UserconnectionPK();
pk.setProviderid("providerId");
pk.setProvideruserid("provideruserid");
pk.setUserid("4444-4444-4444-4441");
UserconnectionEntity userConnection = new UserconnectionEntity();
userConnection.setAccesstoken("blah");
userConnection.setConnectionSatus(UserConnectionStatus.STARTED);
userConnection.setDisplayname("blah");
userConnection.setDateCreated(new Date());
userConnection.setLastModified(new Date());
userConnection.setEmail("blah@blah.com");
userConnection.setOrcid("4444-4444-4444-4441");
userConnection.setId(pk);
userConnection.setRank(1);
userConnectionDao.persist(userConnection);
ProfileEntity profileEntityToDeprecate = profileEntityCacheManager.retrieve("4444-4444-4444-4441");
assertNull(profileEntityToDeprecate.getPrimaryRecord());
boolean result = profileEntityManager.deprecateProfile("4444-4444-4444-4441", "4444-4444-4444-4442");
assertTrue(result);
profileEntityToDeprecate = profileEntityCacheManager.retrieve("4444-4444-4444-4441");
assertNotNull(profileEntityToDeprecate.getPrimaryRecord());
assertEquals("4444-4444-4444-4442", profileEntityToDeprecate.getPrimaryRecord().getId());
assertEquals(0, userConnectionDao.findByOrcid("4444-4444-4444-4441").size());
}
use of org.orcid.persistence.jpa.entities.UserconnectionPK in project ORCID-Source by ORCID.
the class InstitutionalSignInManagerImpl method createUserConnectionAndNotify.
@Override
@Transactional
public void createUserConnectionAndNotify(String idType, String remoteUserId, String displayName, String providerId, String userOrcid, Map<String, String> headers) throws UnsupportedEncodingException {
UserconnectionEntity userConnectionEntity = userConnectionDao.findByProviderIdAndProviderUserIdAndIdType(remoteUserId, providerId, idType);
if (userConnectionEntity == null) {
LOGGER.info("No user connection found for idType={}, remoteUserId={}, displayName={}, providerId={}, userOrcid={}", new Object[] { idType, remoteUserId, displayName, providerId, userOrcid });
userConnectionEntity = new UserconnectionEntity();
String randomId = Long.toString(new Random(Calendar.getInstance().getTimeInMillis()).nextLong());
UserconnectionPK pk = new UserconnectionPK(randomId, providerId, remoteUserId);
userConnectionEntity.setOrcid(userOrcid);
userConnectionEntity.setProfileurl(orcidUrlManager.getBaseUriHttp() + "/" + userOrcid);
userConnectionEntity.setDisplayname(displayName);
userConnectionEntity.setRank(1);
userConnectionEntity.setId(pk);
userConnectionEntity.setLinked(true);
userConnectionEntity.setLastLogin(new Date());
userConnectionEntity.setIdType(idType);
userConnectionEntity.setConnectionSatus(UserConnectionStatus.NOTIFIED);
userConnectionEntity.setHeadersJson(JsonUtils.convertToJsonString(headers));
userConnectionDao.persist(userConnectionEntity);
} else {
LOGGER.info("Found existing user connection, {}", userConnectionEntity);
}
sendNotification(userOrcid, providerId);
}
use of org.orcid.persistence.jpa.entities.UserconnectionPK in project ORCID-Source by ORCID.
the class SocialController method signinHandler.
@RequestMapping(value = { "/access" }, method = RequestMethod.GET)
public ModelAndView signinHandler(HttpServletRequest request, HttpServletResponse response) {
SocialType connectionType = socialContext.isSignedIn(request, response);
if (connectionType != null) {
Map<String, String> userMap = retrieveUserDetails(connectionType);
String providerId = connectionType.value();
String userId = socialContext.getUserId();
UserconnectionEntity userConnectionEntity = userConnectionManager.findByProviderIdAndProviderUserId(userMap.get("providerUserId"), providerId);
if (userConnectionEntity != null) {
if (userConnectionEntity.isLinked()) {
UserconnectionPK pk = new UserconnectionPK(userId, providerId, userMap.get("providerUserId"));
userConnectionManager.updateLoginInformation(pk);
String aCredentials = new StringBuffer(providerId).append(":").append(userMap.get("providerUserId")).toString();
PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(userConnectionEntity.getOrcid(), aCredentials);
token.setDetails(new WebAuthenticationDetails(request));
Authentication authentication = authenticationManager.authenticate(token);
SecurityContextHolder.getContext().setAuthentication(authentication);
return new ModelAndView("redirect:" + calculateRedirectUrl(request, response));
} else {
ModelAndView mav = new ModelAndView();
mav.setViewName("social_link_signin");
mav.addObject("providerId", providerId);
mav.addObject("accountId", getAccountIdForDisplay(userMap));
mav.addObject("linkType", "social");
mav.addObject("emailId", (userMap.get("email") == null) ? "" : userMap.get("email"));
mav.addObject("firstName", (userMap.get("firstName") == null) ? "" : userMap.get("firstName"));
mav.addObject("lastName", (userMap.get("lastName") == null) ? "" : userMap.get("lastName"));
return mav;
}
} else {
throw new UsernameNotFoundException("Could not find an orcid account associated with the email id.");
}
} else {
throw new UsernameNotFoundException("Could not find an orcid account associated with the email id.");
}
}
Aggregations