diff --git a/source/java/org/alfresco/repo/web/scripts/servlet/RemoteUserAuthenticatorFactory.java b/source/java/org/alfresco/repo/web/scripts/servlet/RemoteUserAuthenticatorFactory.java
index a3987e7033..c7bd0f0b50 100644
--- a/source/java/org/alfresco/repo/web/scripts/servlet/RemoteUserAuthenticatorFactory.java
+++ b/source/java/org/alfresco/repo/web/scripts/servlet/RemoteUserAuthenticatorFactory.java
@@ -18,11 +18,17 @@
*/
package org.alfresco.repo.web.scripts.servlet;
+import javax.servlet.http.HttpSession;
+
+import org.alfresco.repo.SessionUser;
import org.alfresco.repo.management.subsystems.ActivateableBean;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
+import org.alfresco.repo.security.authentication.AuthenticationException;
import org.alfresco.repo.security.authentication.external.RemoteUserMapper;
import org.alfresco.repo.web.auth.AuthenticationListener;
import org.alfresco.repo.web.auth.TicketCredentials;
+import org.alfresco.repo.web.auth.WebCredentials;
+import org.alfresco.repo.webdav.auth.AuthenticationDriver;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.webscripts.Authenticator;
@@ -80,18 +86,54 @@ public class RemoteUserAuthenticatorFactory extends BasicHttpAuthenticatorFactor
@Override
public boolean authenticate(RequiredAuthentication required, boolean isGuest)
{
+ boolean authenticated = false;
+
// retrieve the remote user if configured and available - authenticate that user directly
final String userId = getRemoteUser();
if (userId != null)
{
authenticationComponent.setCurrentUser(userId);
listener.userAuthenticated(new TicketCredentials(authenticationService.getCurrentTicket()));
- return true;
+ authenticated = true;
}
else
{
- return super.authenticate(required, isGuest);
+ // is there a Session which might contain a valid user ticket?
+ HttpSession session = servletReq.getHttpServletRequest().getSession(false);
+ if (session != null)
+ {
+ try
+ {
+ SessionUser user = (SessionUser)session.getAttribute(AuthenticationDriver.AUTHENTICATION_USER);
+ if (user != null)
+ {
+ // Validate the ticket for the current SessionUser
+ authenticationService.validate(user.getTicket());
+ if (logger.isDebugEnabled())
+ logger.debug("Ticket is valid; retaining cached user in session.");
+ listener.userAuthenticated(new TicketCredentials(user.getTicket()));
+ authenticated = true;
+ }
+ else
+ {
+ authenticated = super.authenticate(required, isGuest);
+ }
+ }
+ catch (AuthenticationException authErr)
+ {
+ if (logger.isDebugEnabled())
+ logger.debug("An Authentication error occur, removing User session: ", authErr);
+ session.removeAttribute(AuthenticationDriver.AUTHENTICATION_USER);
+ session.invalidate();
+ listener.authenticationFailed(new WebCredentials() {});
+ }
+ }
+ else
+ {
+ authenticated = super.authenticate(required, isGuest);
+ }
}
+ return authenticated;
}
/**
diff --git a/source/java/org/alfresco/repo/webdav/auth/AuthenticationDriver.java b/source/java/org/alfresco/repo/webdav/auth/AuthenticationDriver.java
index eb22c3bdcb..044a63e1d3 100644
--- a/source/java/org/alfresco/repo/webdav/auth/AuthenticationDriver.java
+++ b/source/java/org/alfresco/repo/webdav/auth/AuthenticationDriver.java
@@ -33,6 +33,8 @@ import javax.servlet.http.HttpServletResponse;
*/
public interface AuthenticationDriver
{
+ public static final String AUTHENTICATION_USER = "_alfAuthTicket";
+
/**
* Authenticate user based on information in http request such as Authorization header or cached session
* information.
diff --git a/source/java/org/alfresco/repo/webdav/auth/BaseAuthenticationFilter.java b/source/java/org/alfresco/repo/webdav/auth/BaseAuthenticationFilter.java
index e809bae8db..31775c8d2c 100644
--- a/source/java/org/alfresco/repo/webdav/auth/BaseAuthenticationFilter.java
+++ b/source/java/org/alfresco/repo/webdav/auth/BaseAuthenticationFilter.java
@@ -362,7 +362,7 @@ public abstract class BaseAuthenticationFilter
});
// Store the user on the session
- session.setAttribute(getUserAttributeName(), user);
+ session.setAttribute(getUserAttributeName(), user);
setExternalAuth(session, externalAuth);
return user;
}
diff --git a/source/java/org/alfresco/repo/webdav/auth/BaseSSOAuthenticationFilter.java b/source/java/org/alfresco/repo/webdav/auth/BaseSSOAuthenticationFilter.java
index 34d160fa53..3e407c4dfc 100644
--- a/source/java/org/alfresco/repo/webdav/auth/BaseSSOAuthenticationFilter.java
+++ b/source/java/org/alfresco/repo/webdav/auth/BaseSSOAuthenticationFilter.java
@@ -1,25 +1,25 @@
/*
- * Copyright (C) 2005-2013 Alfresco Software Limited.
- *
- * This file is part of Alfresco
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
+ * Copyright (C) 2005-2014 Alfresco Software Limited.
+ *
+ * This file is part of Alfresco
+ *
+ * Alfresco is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Alfresco is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see
Please log in.
"); - out.println(""); - out.close(); - } - } - + final PrintWriter out = resp.getWriter(); + out.println(""); + out.println(""); + out.println("Please log in.
"); + out.println(""); + out.close(); + } + } + /** * Include into response authentication method that is supported by fallback mechanism * @@ -606,13 +603,13 @@ public abstract class BaseSSOAuthenticationFilter extends BaseAuthenticationFilt if (!fallbackSuccess) { restartLoginChallenge(context, req, resp); - + if (getLogger().isDebugEnabled()) { getLogger().debug("Fallback authentication failed. Restarting login..."); } } - + if (fallbackSuccess && getLogger().isDebugEnabled()) { getLogger().debug("Fallback authentication succeeded."); diff --git a/source/java/org/alfresco/repo/webdav/auth/SSOFallbackBasicAuthenticationDriver.java b/source/java/org/alfresco/repo/webdav/auth/SSOFallbackBasicAuthenticationDriver.java index b41081045a..4852326a38 100644 --- a/source/java/org/alfresco/repo/webdav/auth/SSOFallbackBasicAuthenticationDriver.java +++ b/source/java/org/alfresco/repo/webdav/auth/SSOFallbackBasicAuthenticationDriver.java @@ -49,8 +49,6 @@ import org.apache.commons.logging.LogFactory; */ public class SSOFallbackBasicAuthenticationDriver implements AuthenticationDriver { - public static final String AUTHENTICATION_USER = "_alfAuthTicket"; - private Log logger = LogFactory.getLog(SSOFallbackBasicAuthenticationDriver.class); private AuthenticationService authenticationService; @@ -58,7 +56,7 @@ public class SSOFallbackBasicAuthenticationDriver implements AuthenticationDrive private NodeService nodeService; private TransactionService transactionService; - private String userAttributeName = AUTHENTICATION_USER; + private String userAttributeName = AuthenticationDriver.AUTHENTICATION_USER; public void setAuthenticationService(AuthenticationService authenticationService) {