Skip to content
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.

Commit

Permalink
added attempt to "login" without prompt if fails redirect to login pa…
Browse files Browse the repository at this point in the history
…ge (#161)
  • Loading branch information
jungwire authored Dec 14, 2022
1 parent 27a6ea8 commit e335523
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@

import de.samply.bbmri.negotiator.NegotiatorConfig;
import de.samply.bbmri.negotiator.control.UserBean;
import de.samply.common.config.OAuth2Client;
import eu.bbmri.eric.csit.service.negotiator.authentication.client.AuthClient;
import eu.bbmri.eric.csit.service.negotiator.authentication.client.InvalidKeyException;
import eu.bbmri.eric.csit.service.negotiator.authentication.client.InvalidTokenException;
import eu.bbmri.eric.csit.service.negotiator.authentication.client.jwt.KeyLoader;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;

Expand All @@ -36,7 +41,12 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.ws.rs.NotFoundException;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.util.HashMap;
import javax.ws.rs.core.UriBuilder;

/**
* This filter checks if there is a user logged in or not. If no valid user is
Expand Down Expand Up @@ -145,11 +155,28 @@ public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
return;
}



// if a user came from the directory before being logged in, we need to save the query ID into the
// usersession
if (request.getQueryString() != null) {
logger.debug("Setting userbean redirect url");
userBean.setNewQueryRedirectURL(request.getServletPath() + "?" + request.getQueryString());

//Check if param error login_required then directly redirect

HashMap<String, String> uriparams = getQueryMap(request.getQueryString());
if(uriparams.containsKey("error") && uriparams.get("error").equals("login_required")){
logger.debug("Redirecting invalid user to login.xhtml");
response.sendRedirect(request.getContextPath() + "/login.xhtml");
return;
}
// TODO might only work for perun and 1not work for different AAIs
URI noprompt_auth_uri = UriBuilder.fromUri(userBean.getAuthenticationUrl(request)).queryParam("prompt", "none").build();
// response.sendRedirect(userBean.getAuthenticationUrl(request)+"&"+"prompt=none");

response.sendRedirect(noprompt_auth_uri.toString());
return;
}

logger.debug("Redirecting invalid user to login.xhtml");
Expand All @@ -164,4 +191,16 @@ public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
public void init(FilterConfig arg0) throws ServletException {
}


public static HashMap<String, String> getQueryMap(String query) {
String[] params = query.split("&");
HashMap<String, String> map = new HashMap<String, String>();

for (String param : params) {
String name = param.split("=")[0];
String value = param.split("=")[1];
map.put(name, value);
}
return map;
}
}

0 comments on commit e335523

Please sign in to comment.