Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #15 from cb-nitin/master
Browse files Browse the repository at this point in the history
Modified redirection URL after successful login. All tests have passed. I will submit it for review.
  • Loading branch information
InfoSec812 authored Feb 11, 2019
2 parents f886d96 + 4694ca1 commit 1edd154
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

import java.net.URL;
import java.net.URLDecoder;

import static java.lang.String.format;

@ServerSide
Expand Down Expand Up @@ -122,7 +125,25 @@ public void callback(CallbackContext context) {
GsonUser gsonUser = requestUser(scribe, accessToken);
String redirectTo;
if (settings.oauthDomain()==null || (settings.oauthDomain()!=null && gsonUser.getEmail().endsWith("@"+settings.oauthDomain()))) {
redirectTo = settings.getSonarBaseURL();
redirectTo = settings.getSonarBaseURL();
String referer_url = request.getHeader("referer");
try {
URL urlObj = new URL(referer_url);
String returnToValue = null;
for( String param : urlObj.getQuery().split("&")) {
if( param.startsWith("return_to=")){
System.out.println("Return_to param : " + param);
System.out.println("Web context : " + settings.getWebContext());
param = URLDecoder.decode(param,"UTF-8");
returnToValue = param.split("=",2)[1].replace(settings.getWebContext(),"");
}
}
if(returnToValue != null){
redirectTo = redirectTo.concat(returnToValue);
}
} catch(Exception e) {
LOGGER.trace("Exception while parsing return to URL");
}
UserIdentity userIdentity = userIdentityFactory.create(gsonUser);
context.authenticate(userIdentity);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public class GoogleSettings {
public static final String LOGIN_STRATEGY_DEFAULT_VALUE = LOGIN_STRATEGY_UNIQUE;
public static final String CATEGORY = "security";
public static final String SUBCATEGORY = "googleoauth";
public static final String SONAR_CONTEXT = "sonar.web.context";

private final Settings settings;

Expand Down Expand Up @@ -109,6 +110,10 @@ public String webURL() {
}
return url;
}

public String getWebContext() {
return settings.getString(SONAR_CONTEXT) == null ? "" : settings.getString(SONAR_CONTEXT);
}

public String apiURL() {
String url = settings.getString(API_URL);
Expand Down

0 comments on commit 1edd154

Please sign in to comment.