use of org.orcid.persistence.jpa.entities.UserconnectionEntity in project ORCID-Source by ORCID.
the class SocialAjaxAuthenticationSuccessHandler method linkSocialAccount.
public void linkSocialAccount(HttpServletRequest request, HttpServletResponse response) {
SocialType connectionType = socialContext.isSignedIn(request, response);
if (connectionType != null) {
Map<String, String> userMap = retrieveUserDetails(connectionType);
String providerId = connectionType.value();
UserconnectionEntity userConnectionEntity = userConnectionManager.findByProviderIdAndProviderUserId(userMap.get("providerUserId"), providerId);
if (userConnectionEntity != null) {
if (!userConnectionEntity.isLinked()) {
userConnectionEntity.setLinked(true);
userConnectionEntity.setEmail(userMap.get("email"));
userConnectionEntity.setOrcid(getRealUserOrcid());
userConnectionManager.update(userConnectionEntity);
}
} 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.");
}
}
use of org.orcid.persistence.jpa.entities.UserconnectionEntity in project ORCID-Source by ORCID.
the class ShibbolethController method post2FAVerificationCode.
@RequestMapping(value = { "/2FA/submitCode.json" }, method = RequestMethod.POST)
@ResponseBody
public TwoFactorAuthenticationCodes post2FAVerificationCode(@RequestBody TwoFactorAuthenticationCodes codes, HttpServletRequest request, HttpServletResponse response, @RequestHeader Map<String, String> headers) {
checkEnabled();
String shibIdentityProvider = headers.get(InstitutionalSignInManager.SHIB_IDENTITY_PROVIDER_HEADER);
RemoteUser remoteUser = institutionalSignInManager.retrieveRemoteUser(headers);
if (remoteUser == null) {
LOGGER.info("Failed federated log in for {}", shibIdentityProvider);
identityProviderManager.incrementFailedCount(shibIdentityProvider);
codes.setRedirectUrl(orcidUrlManager.getBaseUrl() + "/shibboleth/signin");
return codes;
}
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()) {
codes.setRedirectUrl(orcidUrlManager.getBaseUrl() + "/shibboleth/signin");
return codes;
}
validate2FACodes(userConnectionEntity.getOrcid(), codes);
if (!codes.getErrors().isEmpty()) {
return codes;
}
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);
}
codes.setRedirectUrl(calculateRedirectUrl(request, response));
return codes;
} else {
codes.setRedirectUrl(orcidUrlManager.getBaseUrl() + "/shibboleth/signin");
return codes;
}
}
use of org.orcid.persistence.jpa.entities.UserconnectionEntity in project ORCID-Source by ORCID.
the class SocialController method post2FAVerificationCode.
@RequestMapping(value = { "/2FA/submitCode.json" }, method = RequestMethod.POST)
@ResponseBody
public TwoFactorAuthenticationCodes post2FAVerificationCode(@RequestBody TwoFactorAuthenticationCodes codes, 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()) {
validate2FACodes(userConnectionEntity.getOrcid(), codes);
if (!codes.getErrors().isEmpty()) {
return codes;
}
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);
codes.setRedirectUrl(calculateRedirectUrl(request, response));
} else {
codes.setRedirectUrl(orcidUrlManager.getBaseUrl() + "/social/access");
}
} 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.");
}
return codes;
}
use of org.orcid.persistence.jpa.entities.UserconnectionEntity 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", ProfileEntity.USER_DRIVEN_DEPRECATION, null);
assertTrue(result);
profileEntityToDeprecate = profileEntityCacheManager.retrieve("4444-4444-4444-4441");
assertNotNull(profileEntityToDeprecate.getPrimaryRecord());
assertNotNull(profileEntityToDeprecate.getDeprecatedMethod());
assertEquals(ProfileEntity.USER_DRIVEN_DEPRECATION, profileEntityToDeprecate.getDeprecatedMethod());
assertEquals("4444-4444-4444-4442", profileEntityToDeprecate.getPrimaryRecord().getId());
assertEquals(0, userConnectionDao.findByOrcid("4444-4444-4444-4441").size());
}
use of org.orcid.persistence.jpa.entities.UserconnectionEntity in project ORCID-Source by ORCID.
the class InstitutionalSignInManagerTest method testDontPersistIfUserConnectionAlreadyExists.
@Test
public void testDontPersistIfUserConnectionAlreadyExists() throws UnsupportedEncodingException {
ClientDetailsEntity testClient = new ClientDetailsEntity(clientId);
when(mock_userConnectionDao.findByProviderIdAndProviderUserIdAndIdType(anyString(), anyString(), anyString())).thenReturn(new UserconnectionEntity());
when(mock_clientDetailsEntityCacheManager.retrieveByIdP(anyString())).thenReturn(testClient);
when(mock_orcidOauth2TokenDetailService.doesClientKnowUser(anyString(), anyString())).thenReturn(false);
institutionalSignInManager.createUserConnectionAndNotify("idType", "remoteUserId", "displayName", "providerId", userOrcid, Collections.<String, String>emptyMap());
verify(mock_userConnectionDao, never()).persist(any());
verify(mock_notificationManager, times(1)).sendAcknowledgeMessage(userOrcid, clientId);
}
Aggregations