mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
- Addition of (optional) scheme, host & port configuration to web-client-config.xml
- Web Scripts are now sensitive to above configuration git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5783 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -33,9 +33,12 @@ import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.alfresco.config.Config;
|
||||
import org.alfresco.config.ConfigService;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.web.config.ServerConfigElement;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
@@ -54,6 +57,10 @@ public class TestWebScriptServer
|
||||
// dependencies
|
||||
protected TransactionService transactionService;
|
||||
protected DeclarativeWebScriptRegistry registry;
|
||||
protected ConfigService configService;
|
||||
|
||||
/** Server Configuration */
|
||||
private ServerConfigElement serverConfig;
|
||||
|
||||
/** The reader for interaction. */
|
||||
private BufferedReader fIn;
|
||||
@@ -87,6 +94,16 @@ public class TestWebScriptServer
|
||||
{
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Config Service
|
||||
*
|
||||
* @param configService
|
||||
*/
|
||||
public void setConfigService(ConfigService configService)
|
||||
{
|
||||
this.configService = configService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -110,6 +127,8 @@ public class TestWebScriptServer
|
||||
public void init()
|
||||
{
|
||||
registry.initWebScripts();
|
||||
Config config = configService.getConfig("Server");
|
||||
serverConfig = (ServerConfigElement)config.getConfigElement(ServerConfigElement.CONFIG_ELEMENT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,7 +161,13 @@ public class TestWebScriptServer
|
||||
*/
|
||||
public static TestWebScriptServer getTestServer()
|
||||
{
|
||||
String[] CONFIG_LOCATIONS = new String[] { "classpath:alfresco/application-context.xml", "classpath:alfresco/web-scripts-application-context.xml", "classpath:alfresco/web-scripts-application-context-test.xml" };
|
||||
String[] CONFIG_LOCATIONS = new String[]
|
||||
{
|
||||
"classpath:alfresco/application-context.xml",
|
||||
"classpath:alfresco/web-scripts-application-context.xml",
|
||||
"classpath:alfresco/web-client-application-context.xml",
|
||||
"classpath:alfresco/web-scripts-application-context-test.xml"
|
||||
};
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(CONFIG_LOCATIONS);
|
||||
TestWebScriptServer testServer = (TestWebScriptServer)context.getBean("webscripts.test");
|
||||
testServer.init();
|
||||
@@ -163,7 +188,7 @@ public class TestWebScriptServer
|
||||
MockHttpServletRequest req = createRequest("get", uri);
|
||||
MockHttpServletResponse res = new MockHttpServletResponse();
|
||||
|
||||
WebScriptRuntime runtime = new WebScriptServletRuntime(registry, transactionService, null, req, res);
|
||||
WebScriptRuntime runtime = new WebScriptServletRuntime(registry, transactionService, null, req, res, serverConfig);
|
||||
runtime.executeScript();
|
||||
|
||||
return res;
|
||||
|
@@ -31,7 +31,10 @@ import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.config.Config;
|
||||
import org.alfresco.config.ConfigService;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.web.config.ServerConfigElement;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -54,8 +57,11 @@ public class WebScriptServlet extends HttpServlet
|
||||
private DeclarativeWebScriptRegistry registry;
|
||||
private TransactionService transactionService;
|
||||
private WebScriptServletAuthenticator authenticator;
|
||||
|
||||
|
||||
protected ConfigService configService;
|
||||
|
||||
/** Host Server Configuration */
|
||||
private static ServerConfigElement serverConfig;
|
||||
|
||||
|
||||
@Override
|
||||
public void init() throws ServletException
|
||||
@@ -64,6 +70,7 @@ public class WebScriptServlet extends HttpServlet
|
||||
ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
|
||||
registry = (DeclarativeWebScriptRegistry)context.getBean("webscripts.registry");
|
||||
transactionService = (TransactionService)context.getBean("transactionComponent");
|
||||
configService = (ConfigService)context.getBean("webClientConfigService");
|
||||
|
||||
// retrieve authenticator via servlet initialisation parameter
|
||||
String authenticatorId = getInitParameter("authenticator");
|
||||
@@ -77,6 +84,10 @@ public class WebScriptServlet extends HttpServlet
|
||||
throw new ServletException("Initialisation parameter 'authenticator' does not refer to a Web Script authenticator (" + authenticatorId + ")");
|
||||
}
|
||||
authenticator = (WebScriptServletAuthenticator)bean;
|
||||
|
||||
// retrieve host server configuration
|
||||
Config config = configService.getConfig("Server");
|
||||
serverConfig = (ServerConfigElement)config.getConfigElement(ServerConfigElement.CONFIG_ELEMENT_ID);
|
||||
}
|
||||
|
||||
|
||||
@@ -94,7 +105,7 @@ public class WebScriptServlet extends HttpServlet
|
||||
res.setHeader("Cache-Control", "no-cache");
|
||||
res.setHeader("Pragma", "no-cache");
|
||||
|
||||
WebScriptRuntime runtime = new WebScriptServletRuntime(registry, transactionService, authenticator, req, res);
|
||||
WebScriptRuntime runtime = new WebScriptServletRuntime(registry, transactionService, authenticator, req, res, serverConfig);
|
||||
runtime.executeScript();
|
||||
}
|
||||
|
||||
|
@@ -28,6 +28,8 @@ import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.alfresco.web.config.ServerConfigElement;
|
||||
|
||||
|
||||
/**
|
||||
* HTTP Servlet Web Script Request
|
||||
@@ -36,6 +38,9 @@ import javax.servlet.http.HttpServletRequest;
|
||||
*/
|
||||
public class WebScriptServletRequest implements WebScriptRequest
|
||||
{
|
||||
/** Server Config */
|
||||
private ServerConfigElement serverConfig;
|
||||
|
||||
/** HTTP Request */
|
||||
private HttpServletRequest req;
|
||||
|
||||
@@ -51,10 +56,23 @@ public class WebScriptServletRequest implements WebScriptRequest
|
||||
*/
|
||||
WebScriptServletRequest(HttpServletRequest req, WebScriptMatch serviceMatch)
|
||||
{
|
||||
this(null, req, serviceMatch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param serverConfig
|
||||
* @param req
|
||||
* @param serviceMatch
|
||||
*/
|
||||
WebScriptServletRequest(ServerConfigElement serverConfig, HttpServletRequest req, WebScriptMatch serviceMatch)
|
||||
{
|
||||
this.serverConfig = serverConfig;
|
||||
this.req = req;
|
||||
this.serviceMatch = serviceMatch;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the HTTP Servlet Request
|
||||
*
|
||||
@@ -84,7 +102,7 @@ public class WebScriptServletRequest implements WebScriptRequest
|
||||
*/
|
||||
public String getServerPath()
|
||||
{
|
||||
return req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort();
|
||||
return getServerScheme() + "://" + getServerName() + ":" + getServerPort();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -221,4 +239,61 @@ public class WebScriptServletRequest implements WebScriptRequest
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Server Scheme
|
||||
*
|
||||
* @return server scheme
|
||||
*/
|
||||
private String getServerScheme()
|
||||
{
|
||||
String scheme = null;
|
||||
if (serverConfig != null)
|
||||
{
|
||||
scheme = serverConfig.getScheme();
|
||||
}
|
||||
if (scheme == null)
|
||||
{
|
||||
scheme = req.getScheme();
|
||||
}
|
||||
return scheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Server Name
|
||||
*
|
||||
* @return server name
|
||||
*/
|
||||
private String getServerName()
|
||||
{
|
||||
String name = null;
|
||||
if (serverConfig != null)
|
||||
{
|
||||
name = serverConfig.getHostName();
|
||||
}
|
||||
if (name == null)
|
||||
{
|
||||
name = req.getServerName();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Server Port
|
||||
*
|
||||
* @return server name
|
||||
*/
|
||||
private int getServerPort()
|
||||
{
|
||||
Integer port = null;
|
||||
if (serverConfig != null)
|
||||
{
|
||||
port = serverConfig.getPort();
|
||||
}
|
||||
if (port == null)
|
||||
{
|
||||
port = req.getServerPort();
|
||||
}
|
||||
return port;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.web.config.ServerConfigElement;
|
||||
import org.alfresco.web.scripts.WebScriptDescription.RequiredAuthentication;
|
||||
|
||||
|
||||
@@ -41,6 +42,7 @@ public class WebScriptServletRuntime extends WebScriptRuntime
|
||||
private HttpServletRequest req;
|
||||
private HttpServletResponse res;
|
||||
private WebScriptServletAuthenticator authenticator;
|
||||
private ServerConfigElement serverConfig;
|
||||
|
||||
|
||||
/**
|
||||
@@ -52,12 +54,14 @@ public class WebScriptServletRuntime extends WebScriptRuntime
|
||||
* @param req
|
||||
* @param res
|
||||
*/
|
||||
public WebScriptServletRuntime(WebScriptRegistry registry, TransactionService transactionService, WebScriptServletAuthenticator authenticator, HttpServletRequest req, HttpServletResponse res)
|
||||
public WebScriptServletRuntime(WebScriptRegistry registry, TransactionService transactionService, WebScriptServletAuthenticator authenticator,
|
||||
HttpServletRequest req, HttpServletResponse res, ServerConfigElement serverConfig)
|
||||
{
|
||||
super(registry, transactionService);
|
||||
this.req = req;
|
||||
this.res = res;
|
||||
this.authenticator = authenticator;
|
||||
this.serverConfig = serverConfig;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -84,7 +88,7 @@ public class WebScriptServletRuntime extends WebScriptRuntime
|
||||
@Override
|
||||
protected WebScriptRequest createRequest(WebScriptMatch match)
|
||||
{
|
||||
return new WebScriptServletRequest(req, match);
|
||||
return new WebScriptServletRequest(serverConfig, req, match);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
Reference in New Issue
Block a user