Skip to content

Commit

Permalink
#44 - adds debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
tjuerge committed Aug 22, 2021
1 parent 602da94 commit 7678c1d
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.api.web.ServletFilter;

public class AutoLoginFilter extends ServletFilter {

private static final Logger LOGGER = Loggers.get(AutoLoginFilter.class);

private static final String LOGIN_URL = "/sessions/new";
private static final String OIDC_URL = "/sessions/init/" + OidcIdentityProvider.KEY + "?return_to=/projects";
private static final String SKIP_REQUEST_PARAM = "auto_login=false";
Expand All @@ -52,9 +56,11 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
if (config.isEnabled() && config.isAutoLogin()) {
if (request instanceof HttpServletRequest) {
String referrer = ((HttpServletRequest) request).getHeader("referer");
LOGGER.debug("Referrer: {}", referrer);

// Skip if disabled via request parameter
if (referrer == null || !referrer.endsWith(SKIP_REQUEST_PARAM)) {
LOGGER.debug("Redirecting to OIDC login page: {}", config.getBaseUrl() + OIDC_URL);
((HttpServletResponse) response).sendRedirect(config.getBaseUrl() + OIDC_URL);
return;
}
Expand All @@ -65,10 +71,12 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha

@Override
public void init(FilterConfig filterConfig) throws ServletException {
// Not needed here
}

@Override
public void destroy() {
// Not needed here
}

}

0 comments on commit 7678c1d

Please sign in to comment.