55
66import java .io .IOException ;
77import java .io .PrintWriter ;
8+ import java .net .URLEncoder ;
89import java .util .List ;
910import java .util .Set ;
11+ import java .nio .charset .StandardCharsets ;
1012
1113import javax .servlet .ServletConfig ;
1214import javax .servlet .ServletException ;
1517import javax .servlet .http .HttpServletRequest ;
1618import javax .servlet .http .HttpServletResponse ;
1719
20+ import org .hibernate .loader .custom .Return ;
21+
1822import com .topcoder .security .TCSubject ;
1923import com .topcoder .shared .security .Authorization ;
2024import com .topcoder .shared .security .Resource ;
2125import com .topcoder .shared .security .SimpleResource ;
26+ import com .topcoder .shared .util .TCResourceBundle ;
2227import com .topcoder .shared .security .User ;
2328import com .topcoder .shared .util .logging .Logger ;
2429import com .topcoder .web .common .error .RequestRateExceededException ;
@@ -63,6 +68,9 @@ public abstract class BaseServlet extends HttpServlet {
6368 public static final String URL_KEY = "url" ;
6469 public static final String NEXT_PAGE_KEY = "nextpage" ;
6570 public static final String SESSION_INFO_KEY = "sessionInfo" ;
71+
72+ private static TCResourceBundle bundle = null ;
73+
6674 /**
6775 * <p>
6876 * Represent the qualified name of this class.
@@ -87,7 +95,9 @@ public synchronized void init(ServletConfig config) throws ServletException {
8795 PATH = config .getInitParameter ("processor_path" );
8896 DEFAULT_PROCESSOR = config .getInitParameter ("default_processor" );
8997 LOGIN_PROCESSOR = config .getInitParameter ("login_processor" );
98+
9099 String styleConfig = config .getInitParameter ("is_new_style" );
100+ bundle = new TCResourceBundle ("TC" );
91101
92102 if (styleConfig != null && styleConfig .equalsIgnoreCase ("true" )) {
93103 NEW_STYLE_ENABLED = true ;
@@ -220,6 +230,7 @@ protected void process(HttpServletRequest request, HttpServletResponse response)
220230 authentication = createAuthentication (tcRequest , tcResponse );
221231 TCSubject user = getUser (authentication .getActiveUser ().getId ());
222232 info = createSessionInfo (tcRequest , authentication , user .getPrincipals ());
233+
223234 //we can let browsers/proxies cache pages if the user is anonymous or it's https (they don't really cache https setuff)
224235 if (log .isDebugEnabled ()) {
225236 log .debug ("uri: " + request .getRequestURL ().toString ());
@@ -272,7 +283,6 @@ protected void process(HttpServletRequest request, HttpServletResponse response)
272283
273284 //log.debug("path " + PATH);
274285 String processorName = getFullProcessorName (cmd );
275-
276286 if (log .isDebugEnabled ()) {
277287 log .debug ("creating request processor for " + processorName );
278288 }
@@ -483,7 +493,17 @@ protected void handleLogin(HttpServletRequest request, HttpServletResponse respo
483493 request .setAttribute (NEXT_PAGE_KEY , info .getRequestString ());
484494
485495 request .setAttribute (MODULE , LOGIN_PROCESSOR );
486- fetchRegularPage (request , response , LOGIN_SERVLET == null ? info .getServletPath () : LOGIN_SERVLET , true );
496+ String loginUrl = bundle .getProperty ("login_url" , "" );
497+ StringBuffer returnUrl = new StringBuffer (info .getSecureAbsoluteServletPath ());
498+ returnUrl .append (info .getQueryString ());
499+ StringBuffer redirectUrl = new StringBuffer (loginUrl );
500+ redirectUrl .append ("?retUrl=" ).append (URLEncoder .encode (returnUrl .toString (), StandardCharsets .UTF_8 .toString ()));
501+
502+ // new login. redirect to auth0
503+ fetchRegularPage (request , response , redirectUrl .toString (), false );
504+
505+ // OLD login
506+ //fetchRegularPage(request, response, LOGIN_SERVLET == null ? info.getServletPath() : LOGIN_SERVLET, true);
487507 }
488508 }
489509
0 commit comments