mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (4.3/Cloud)
71601: Merged V4.2-BUG-FIX (4.2.3) to HEAD-BUG-FIX (4.3/Cloud) 70356: MNT-11233: DEV to V4.2-BUG-FIX (4.2.3) 67973: MNT-11233: Alfresco CMIS API /alfresco/api/-default-/cmis/versions/1.1/atom cannot be used with external authentication - Move RemoteUserMapper from Web-Client to Repository project. Use RemoteUserMapper in PublicApiAuthenticator to retrieve remote user from request. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@74695 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.web.app.servlet;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.alfresco.repo.management.subsystems.AbstractChainedSubsystemTest;
|
||||
import org.alfresco.repo.management.subsystems.ChildApplicationContextFactory;
|
||||
import org.alfresco.repo.management.subsystems.DefaultChildApplicationContextManager;
|
||||
import org.alfresco.repo.webdav.auth.RemoteUserMapper;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
|
||||
/**
|
||||
* @author dward
|
||||
*
|
||||
*/
|
||||
public class DefaultRemoteUserMapperTest extends AbstractChainedSubsystemTest
|
||||
{
|
||||
ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
|
||||
DefaultChildApplicationContextManager childApplicationContextManager;
|
||||
ChildApplicationContextFactory childApplicationContextFactory;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see junit.framework.TestCase#setUp()
|
||||
*/
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
childApplicationContextManager = (DefaultChildApplicationContextManager) ctx.getBean("Authentication");
|
||||
childApplicationContextManager.stop();
|
||||
childApplicationContextManager.setProperty("chain", "external1:external");
|
||||
childApplicationContextFactory = getChildApplicationContextFactory(childApplicationContextManager, "external1");
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see junit.framework.TestCase#tearDown()
|
||||
*/
|
||||
@Override
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
childApplicationContextManager.destroy();
|
||||
childApplicationContextManager = null;
|
||||
childApplicationContextFactory = null;
|
||||
}
|
||||
|
||||
|
||||
public void testUnproxiedHeader() throws Exception
|
||||
{
|
||||
// Clear the proxy user name
|
||||
childApplicationContextFactory.stop();
|
||||
childApplicationContextFactory.setProperty("external.authentication.proxyUserName", "");
|
||||
|
||||
// Mock a request with a username in the header
|
||||
HttpServletRequest mockRequest = mock(HttpServletRequest.class);
|
||||
when(mockRequest.getHeader("X-Alfresco-Remote-User")).thenReturn("AdMiN");
|
||||
assertEquals("admin", ((RemoteUserMapper) childApplicationContextFactory.getApplicationContext().getBean(
|
||||
"remoteUserMapper")).getRemoteUser(mockRequest));
|
||||
|
||||
// Mock an unauthenticated request
|
||||
when(mockRequest.getHeader("X-Alfresco-Remote-User")).thenReturn(null);
|
||||
assertNull(((RemoteUserMapper) childApplicationContextFactory.getApplicationContext().getBean(
|
||||
"remoteUserMapper")).getRemoteUser(mockRequest));
|
||||
|
||||
// Mock a remote user request
|
||||
when(mockRequest.getRemoteUser()).thenReturn("ADMIN");
|
||||
assertEquals("admin", ((RemoteUserMapper) childApplicationContextFactory.getApplicationContext().getBean(
|
||||
"remoteUserMapper")).getRemoteUser(mockRequest));
|
||||
}
|
||||
|
||||
|
||||
public void testProxiedHeader() throws Exception
|
||||
{
|
||||
// Set the proxy user name
|
||||
childApplicationContextFactory.stop();
|
||||
childApplicationContextFactory.setProperty("external.authentication.proxyUserName", "bob");
|
||||
|
||||
// Mock a request with both a user and a header
|
||||
HttpServletRequest mockRequest = mock(HttpServletRequest.class);
|
||||
when(mockRequest.getRemoteUser()).thenReturn("bob");
|
||||
when(mockRequest.getHeader("X-Alfresco-Remote-User")).thenReturn("AdMiN");
|
||||
assertEquals("admin", ((RemoteUserMapper) childApplicationContextFactory.getApplicationContext().getBean(
|
||||
"remoteUserMapper")).getRemoteUser(mockRequest));
|
||||
|
||||
// Now try header pattern matching
|
||||
childApplicationContextFactory.stop();
|
||||
childApplicationContextFactory.setProperty("external.authentication.userIdPattern", "abc-(.*)-999");
|
||||
when(mockRequest.getHeader("X-Alfresco-Remote-User")).thenReturn("abc-AdMiN-999");
|
||||
assertEquals("admin", ((RemoteUserMapper) childApplicationContextFactory.getApplicationContext().getBean(
|
||||
"remoteUserMapper")).getRemoteUser(mockRequest));
|
||||
|
||||
// Try a request with an invalid match
|
||||
when(mockRequest.getHeader("X-Alfresco-Remote-User")).thenReturn("abc-AdMiN-998");
|
||||
assertNull(((RemoteUserMapper) childApplicationContextFactory.getApplicationContext().getBean(
|
||||
"remoteUserMapper")).getRemoteUser(mockRequest));
|
||||
|
||||
// Try a request without the remote user
|
||||
when(mockRequest.getRemoteUser()).thenReturn(null);
|
||||
assertNull(((RemoteUserMapper) childApplicationContextFactory.getApplicationContext().getBean(
|
||||
"remoteUserMapper")).getRemoteUser(mockRequest));
|
||||
}
|
||||
|
||||
}
|
@@ -38,6 +38,7 @@ import org.alfresco.repo.admin.SysAdminParams;
|
||||
import org.alfresco.repo.security.authentication.TicketComponent;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationServiceImpl;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.external.DefaultRemoteUserMapper;
|
||||
import org.alfresco.repo.security.authentication.jaas.JAASAuthenticationComponent;
|
||||
import org.alfresco.repo.web.auth.NoopAuthenticationListener;
|
||||
import org.alfresco.repo.webdav.auth.KerberosAuthenticationFilter;
|
||||
@@ -45,7 +46,6 @@ import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.alfresco.web.app.servlet.DefaultRemoteUserMapper;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
|
Reference in New Issue
Block a user