use of org.orcid.persistence.jpa.entities.UserconnectionEntity in project ORCID-Source by ORCID.
the class InstitutionalSignInManagerTest method testDontPersistAndDontNotify.
@Test
public void testDontPersistAndDontNotify() throws UnsupportedEncodingException {
when(mock_userConnectionDao.findByProviderIdAndProviderUserIdAndIdType(anyString(), anyString(), anyString())).thenReturn(new UserconnectionEntity());
when(mock_clientDetailsEntityCacheManager.retrieveByIdP(anyString())).thenThrow(new IllegalArgumentException());
when(mock_orcidOauth2TokenDetailService.doesClientKnowUser(anyString(), anyString())).thenReturn(true);
institutionalSignInManager.createUserConnectionAndNotify("idType", "remoteUserId", "displayName", "providerId", userOrcid, Collections.<String, String>emptyMap());
verify(mock_userConnectionDao, never()).persist(any());
verify(mock_notificationManager, never()).sendAcknowledgeMessage(userOrcid, clientId);
}
use of org.orcid.persistence.jpa.entities.UserconnectionEntity in project ORCID-Source by ORCID.
the class UserConnectionDaoImpl method updateLoginInformation.
@Override
@Transactional
public void updateLoginInformation(UserconnectionPK pk) {
UserconnectionEntity entity = find(pk);
entity.setLastLogin(new Timestamp(new Date().getTime()));
merge(entity);
}
use of org.orcid.persistence.jpa.entities.UserconnectionEntity 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.UserconnectionEntity in project ORCID-Source by ORCID.
the class ShibbolethController method signinHandler.
@RequestMapping(value = { "/signin" }, method = RequestMethod.GET)
public ModelAndView signinHandler(HttpServletRequest request, HttpServletResponse response, @RequestHeader Map<String, String> headers, ModelAndView mav) {
LOGGER.info("Headers for shibboleth sign in: {}", headers);
checkEnabled();
mav.setViewName("social_link_signin");
String shibIdentityProvider = headers.get(InstitutionalSignInManager.SHIB_IDENTITY_PROVIDER_HEADER);
mav.addObject("providerId", shibIdentityProvider);
String displayName = institutionalSignInManager.retrieveDisplayName(headers);
mav.addObject("accountId", displayName);
RemoteUser remoteUser = institutionalSignInManager.retrieveRemoteUser(headers);
if (remoteUser == null) {
LOGGER.info("Failed federated log in for {}", shibIdentityProvider);
identityProviderManager.incrementFailedCount(shibIdentityProvider);
mav.addObject("unsupportedInstitution", true);
mav.addObject("institutionContactEmail", identityProviderManager.retrieveContactEmailByProviderid(shibIdentityProvider));
return mav;
}
// Check if the Shibboleth user is already linked to an ORCID account.
// If so sign them in automatically.
UserconnectionEntity userConnectionEntity = userConnectionManager.findByProviderIdAndProviderUserIdAndIdType(remoteUser.getUserId(), shibIdentityProvider, remoteUser.getIdType());
if (userConnectionEntity != null) {
LOGGER.info("Found existing user connection: {}", userConnectionEntity);
HeaderCheckResult checkHeadersResult = institutionalSignInManager.checkHeaders(parseOriginalHeaders(userConnectionEntity.getHeadersJson()), headers);
if (!checkHeadersResult.isSuccess()) {
mav.addObject("headerCheckFailed", true);
return mav;
}
ProfileEntity profile = profileEntityCacheManager.retrieve(userConnectionEntity.getOrcid());
if (profile.getUsing2FA()) {
return new ModelAndView("institutional_2FA");
}
try {
notifyUser(shibIdentityProvider, userConnectionEntity);
processAuthentication(remoteUser, userConnectionEntity);
} catch (AuthenticationException e) {
// this should never happen
SecurityContextHolder.getContext().setAuthentication(null);
LOGGER.warn("User {0} should have been logged-in via Shibboleth, but was unable to due to a problem", remoteUser, e);
}
return new ModelAndView("redirect:" + calculateRedirectUrl(request, response));
} else {
// To avoid confusion, force the user to login to ORCID again
mav.addObject("linkType", "shibboleth");
mav.addObject("firstName", (headers.get(InstitutionalSignInManager.GIVEN_NAME_HEADER) == null) ? "" : headers.get(InstitutionalSignInManager.GIVEN_NAME_HEADER));
mav.addObject("lastName", (headers.get(InstitutionalSignInManager.SN_HEADER) == null) ? "" : headers.get(InstitutionalSignInManager.SN_HEADER));
}
return mav;
}
use of org.orcid.persistence.jpa.entities.UserconnectionEntity 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()) {
ProfileEntity profile = profileEntityCacheManager.retrieve(userConnectionEntity.getOrcid());
if (profile.getUsing2FA()) {
return new ModelAndView("social_2FA");
}
UserconnectionPK pk = new UserconnectionPK(userId, providerId, userMap.get("providerUserId"));
String aCredentials = new StringBuffer(providerId).append(":").append(userMap.get("providerUserId")).toString();
PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(userConnectionEntity.getOrcid(), aCredentials);
token.setDetails(getOrcidProfileUserDetails(userConnectionEntity.getOrcid()));
Authentication authentication = authenticationManager.authenticate(token);
userConnectionManager.updateLoginInformation(pk);
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