Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add missing create event method for social sign in #6922

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,24 @@ public void createEvent(String orcid, EventType eventType, HttpServletRequest re
String redirectUrl = null;
String publicPage = null;

switch (eventType) {
case PUBLIC_PAGE:
publicPage = orcid;
orcid = null;
break;
case REAUTHORIZE:
if (eventType == EventType.PUBLIC_PAGE) {
publicPage = orcid;
orcid = null;
} else {
if (request != null) {
Boolean isOauth2ScreensRequest = (Boolean) request.getSession().getAttribute(OrcidOauth2Constants.OAUTH_2SCREENS);
if (isOauth2ScreensRequest != null && isOauth2ScreensRequest) {
String queryString = (String) request.getSession().getAttribute(OrcidOauth2Constants.OAUTH_QUERY_STRING);
clientId = getParameterValue(queryString, "client_id");
redirectUrl = getParameterValue(queryString, "redirect_uri");
ClientDetailsEntity clientDetailsEntity = clientDetailsEntityCacheManager.retrieve(clientId);
label = "OAuth " + clientDetailsEntity.getClientName();
}
} else if (requestInfoForm != null) {
clientId = requestInfoForm.getClientId();
redirectUrl = requestInfoForm.getRedirectUrl();
redirectUrl = removeAttributesFromUrl(requestInfoForm.getRedirectUrl());
label = "OAuth " + requestInfoForm.getClientName();
break;
default:
if (request != null) {
Boolean isOauth2ScreensRequest = (Boolean) request.getSession().getAttribute(OrcidOauth2Constants.OAUTH_2SCREENS);
if (isOauth2ScreensRequest != null && isOauth2ScreensRequest) {
String queryString = (String) request.getSession().getAttribute(OrcidOauth2Constants.OAUTH_QUERY_STRING);
clientId = getParameterValue(queryString, "client_id");
redirectUrl = getParameterValue(queryString, "redirect_uri");
ClientDetailsEntity clientDetailsEntity = clientDetailsEntityCacheManager.retrieve(clientId);
label = "OAuth " + clientDetailsEntity.getClientName();
}
}
}
}

EventEntity eventEntity = new EventEntity();
Expand Down Expand Up @@ -94,4 +91,11 @@ private String getParameterValue(String queryString, String parameter) {
}
return null;
}

private String removeAttributesFromUrl(String url) {
if (url.contains("?")) {
return url.substring(0, url.indexOf("?"));
}
return url;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.apache.commons.lang3.StringUtils;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.orcid.core.common.manager.EventManager;
import org.orcid.core.constants.OrcidOauth2Constants;
import org.orcid.core.exception.ClientDeactivatedException;
import org.orcid.core.exception.LockedException;
Expand All @@ -23,6 +24,8 @@
import org.orcid.core.oauth.service.OrcidAuthorizationEndpoint;
import org.orcid.core.oauth.service.OrcidOAuth2RequestValidator;
import org.orcid.core.security.OrcidUserDetailsService;
import org.orcid.core.togglz.Features;
import org.orcid.core.utils.EventType;
import org.orcid.frontend.spring.web.social.config.SocialSignInUtils;
import org.orcid.frontend.spring.web.social.config.SocialType;
import org.orcid.frontend.spring.web.social.config.UserCookieGenerator;
Expand Down Expand Up @@ -86,6 +89,9 @@ public class LoginController extends OauthControllerBase {

@Resource
private OauthHelper oauthHelper;

@Resource
private EventManager eventManager;

@RequestMapping(value = "/account/names/{type}", method = RequestMethod.GET)
public @ResponseBody Names getAccountNames(@PathVariable String type) {
Expand Down Expand Up @@ -320,6 +326,9 @@ private ModelAndView processSocialLogin(HttpServletRequest request, HttpServletR
userConnectionId = userConnection.getId().getUserid();
// Store relevant data in the session
socialSignInUtils.setSignedInData(request, userData);
if (Features.EVENTS.isActive()) {
eventManager.createEvent(userConnection.getOrcid(), EventType.SIGN_IN, request, null);
}

if(userConnection.isLinked()) {
// If user exists and is linked update user connection info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.orcid.core.exception.LockedException;
import org.orcid.core.common.manager.EventManager;
import org.orcid.core.manager.v3.ProfileEntityManager;
import org.orcid.core.oauth.OrcidProfileUserDetails;
import org.orcid.core.oauth.OrcidRandomValueTokenServices;
import org.orcid.core.togglz.Features;
import org.orcid.core.utils.EventType;
Expand Down Expand Up @@ -252,7 +253,14 @@ public ModelAndView loginGetHandler(HttpServletRequest request, HttpServletRespo
requestInfoForm.setRedirectUrl(view.getUrl());
if (Features.EVENTS.isActive()) {
EventType eventType = "true".equals(approvalParams.get("user_oauth_approval")) ? EventType.AUTHORIZE : EventType.AUTHORIZE_DENY;
eventManager.createEvent(auth.getPrincipal().toString(), eventType, null, requestInfoForm);
String orcid = null;
Object principal = auth.getPrincipal();
if (principal instanceof OrcidProfileUserDetails) {
orcid = ((OrcidProfileUserDetails) principal).getOrcid();
} else {
orcid = auth.getPrincipal().toString();
}
eventManager.createEvent(orcid, eventType, null, requestInfoForm);
}
if(new HttpSessionRequestCache().getRequest(request, response) != null)
new HttpSessionRequestCache().removeRequest(request, response);
Expand Down