use of org.orcid.frontend.spring.web.social.config.SocialType 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.frontend.spring.web.social.config.SocialType 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.frontend.spring.web.social.config.SocialType 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