Skip to content

Commit 881eb85

Browse files
author
Sebastian Riemer
committed
SAK-51161 Skip authentication if already authenticated and follow URL in url-parameter instead
1 parent 1dd2ec0 commit 881eb85

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

login/login-tool/tool/src/java/org/sakaiproject/login/tool/SkinnableLogin.java

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
***********************************************************************************
55
*
66
* Copyright (c) 2008 The Sakai Foundation.
7-
*
7+
*
88
* Licensed under the Educational Community License, Version 1.0 (the "License");
99
* you may not use this file except in compliance with the License.
1010
* You may obtain a copy of the License at
11-
*
11+
*
1212
* http://www.opensource.org/licenses/ecl1.php
13-
*
13+
*
1414
* Unless required by applicable law or agreed to in writing, software
1515
* distributed under the License is distributed on an "AS IS" BASIS,
1616
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -89,7 +89,7 @@ public class SkinnableLogin extends HttpServlet implements Login {
8989
private transient LoginService loginService;
9090

9191
private static ResourceLoader rb = new ResourceLoader("auth");
92-
92+
9393
// the list of login choices that could be supplied
9494
enum AuthChoices {
9595
CONTAINER,
@@ -137,7 +137,7 @@ public String getServletInfo()
137137

138138
@SuppressWarnings(value = "HRS_REQUEST_PARAMETER_TO_HTTP_HEADER", justification = "Looks like the data is already URL encoded")
139139
protected void doGet(HttpServletRequest req, HttpServletResponse res)
140-
throws ServletException, IOException
140+
throws ServletException, IOException
141141
{
142142
// get the session
143143
Session session = SessionManager.getCurrentSession();
@@ -174,7 +174,7 @@ else if ("/xlogin".equals(option))
174174
{
175175

176176
// if this is an impersonation, then reset the users old session and
177-
if (isImpersonating())
177+
if (isImpersonating())
178178
{
179179
UsageSession oldSession = (UsageSession) session.getAttribute(UsageSessionService.USAGE_SESSION_KEY);
180180
String impersonatingEid = session.getUserEid();
@@ -191,12 +191,12 @@ else if ("/xlogin".equals(option))
191191
session.setUserEid(userEid);
192192
authzGroupService.refreshUser(userId);
193193

194-
try
194+
try
195195
{
196196
res.sendRedirect(serverConfigurationService.getString("portalPath", "/portal"));
197197
res.getWriter().close();
198-
}
199-
catch (IOException e)
198+
}
199+
catch (IOException e)
200200
{
201201
log.error("failed to redirect after impersonating", e);
202202
}
@@ -221,7 +221,11 @@ else if ("/xlogin".equals(option))
221221
}
222222
return;
223223
}
224-
224+
if(session != null && session.getUserId() != null) {
225+
String returnUrl = (String) session.getAttribute(Tool.HELPER_DONE_URL);
226+
complete(returnUrl, session, tool, res);
227+
}
228+
225229
//SAK-29092 if an auth is specified in the URL, skip any other checks and go straight to it
226230
String authPreferred = req.getParameter("auth");
227231
log.debug("authPreferred: " + authPreferred);
@@ -230,7 +234,7 @@ else if ("/xlogin".equals(option))
230234
log.debug("Going straight to xlogin");
231235
skipContainer = true;
232236
}
233-
237+
234238
// see if we need to check container
235239
boolean checkContainer = serverConfigurationService.getBoolean("container.login", false);
236240
if (checkContainer && !skipContainer)
@@ -267,8 +271,8 @@ else if ("/xlogin".equals(option))
267271
log.debug("Going straight to container login");
268272
showAuthChoice = false;
269273
}
270-
271-
if (showAuthChoice && !(StringUtils.isEmpty(helperPath) || helperPath.equals("/portal") ||
274+
275+
if (showAuthChoice && !(StringUtils.isEmpty(helperPath) || helperPath.equals("/portal") ||
272276
helperPath.equals("/portal/") )) {
273277
String xloginUrl = serverConfigurationService.getPortalUrl() + "/xlogin";
274278

@@ -395,7 +399,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse res) throws Se
395399
// Decide whether or not to put up the Cancel
396400
String portalUrl = (String) session.getAttribute(Tool.HELPER_DONE_URL);
397401
String actualPortal = serverConfigurationService.getPortalUrl();
398-
if ( portalUrl != null && portalUrl.indexOf("/site/") < 1 && portalUrl.startsWith(actualPortal) ) {
402+
if ( portalUrl != null && portalUrl.indexOf("/site/") < 1 && portalUrl.startsWith(actualPortal) ) {
399403
rcontext.put("doCancel", Boolean.TRUE);
400404
}
401405

@@ -603,7 +607,7 @@ protected String getPasswordResetUrl()
603607
/**
604608
* Helper to log failed login attempts (SAK-22430)
605609
* @param credentials the credentials supplied
606-
*
610+
*
607611
* Note that this could easily be extedned to track login attempts per session and report on it here
608612
*/
609613
private void logFailedAttempt(LoginCredentials credentials) {
@@ -615,30 +619,30 @@ private void logFailedAttempt(LoginCredentials credentials) {
615619

616620
/**
617621
* Helper to see if this session has used SuTool to become another user
618-
*
622+
*
619623
* Returns true if the user is currently impersonating.
620624
*/
621-
private boolean isImpersonating()
625+
private boolean isImpersonating()
622626
{
623627
Session s = SessionManager.getCurrentSession();
624628
String userId = s.getUserId();
625629
UsageSession session = (UsageSession) s.getAttribute(UsageSessionService.USAGE_SESSION_KEY);
626630

627-
if (session != null)
631+
if (session != null)
628632
{
629633
// If we have a session for this user, simply reuse
630634
if (userId != null)
631635
{
632636
if (userId.equals(session.getUserId()))
633637
{
634638
return false;
635-
}
636-
else
639+
}
640+
else
637641
{
638642
return true;
639643
}
640644
}
641-
else
645+
else
642646
{
643647
log.error("null userId in check isImpersonating");
644648
}

0 commit comments

Comments
 (0)