use of org.springframework.extensions.webscripts.Match in project acs-community-packaging by Alfresco.
the class WebScriptSSOAuthenticationFilter method doFilter.
/* (non-Javadoc)
* @see org.alfresco.repo.webdav.auth.BaseNTLMAuthenticationFilter#doFilter(javax.servlet.ServletContext, javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
*/
public void doFilter(ServletContext context, ServletRequest sreq, ServletResponse sresp, FilterChain chain) throws IOException, ServletException {
// Get the HTTP request/response
HttpServletRequest req = (HttpServletRequest) sreq;
// find a webscript match for the requested URI
String requestURI = req.getRequestURI();
String pathInfo = requestURI.substring((req.getContextPath() + req.getServletPath()).length());
if (getLogger().isDebugEnabled())
getLogger().debug("Processing request: " + requestURI + " SID:" + (req.getSession(false) != null ? req.getSession().getId() : null));
Match match = container.getRegistry().findWebScript(req.getMethod(), URLDecoder.decode(pathInfo));
if (match != null && match.getWebScript() != null) {
// the filters down the chain to require any authentication checks
if (RequiredAuthentication.none == match.getWebScript().getDescription().getRequiredAuthentication()) {
if (getLogger().isDebugEnabled())
getLogger().debug("Found webscript with no authentication - set NO_AUTH_REQUIRED flag.");
req.setAttribute(NO_AUTH_REQUIRED, Boolean.TRUE);
}
}
chain.doFilter(sreq, sresp);
}
use of org.springframework.extensions.webscripts.Match in project records-management by Alfresco.
the class BaseWebScriptUnitTest method getMockedWebScriptRequest.
/**
* Helper method to get the mocked web script request.
*
* @param webScript declarative web script
* @param parameters web script parameter values
* @return {@link WebScriptRequest} mocked web script request
*/
@SuppressWarnings("rawtypes")
protected WebScriptRequest getMockedWebScriptRequest(AbstractWebScript webScript, final Map<String, String> parameters, String content) throws Exception {
Match match = new Match(null, parameters, null, webScript);
org.springframework.extensions.webscripts.Runtime mockedRuntime = mock(org.springframework.extensions.webscripts.Runtime.class);
WebScriptRequest mockedRequest = mock(WebScriptRequest.class);
doReturn(match).when(mockedRequest).getServiceMatch();
doReturn(mockedRuntime).when(mockedRequest).getRuntime();
if (content != null && !content.isEmpty()) {
Content mockedContent = mock(Content.class);
doReturn(content).when(mockedContent).getContent();
doReturn(mockedContent).when(mockedRequest).getContent();
}
String[] paramNames = (String[]) parameters.keySet().toArray(new String[parameters.size()]);
doReturn(paramNames).when(mockedRequest).getParameterNames();
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
String paramName = (String) invocation.getArguments()[0];
return parameters.get(paramName);
}
}).when(mockedRequest).getParameter(anyString());
doReturn(new String[0]).when(mockedRequest).getHeaderNames();
doReturn("json").when(mockedRequest).getFormat();
return mockedRequest;
}
use of org.springframework.extensions.webscripts.Match in project alfresco-remote-api by Alfresco.
the class PublicApiCMISHttpServletRequest method addAttributes.
protected void addAttributes() {
super.addAttributes();
Match match = req.getServiceMatch();
Map<String, String> templateVars = match.getTemplateVars();
String apiScope = templateVars.get("apiScope");
String apiVersion = templateVars.get("apiVersion");
if (apiScope != null) {
httpReq.setAttribute("apiScope", apiScope);
}
if (apiVersion != null) {
httpReq.setAttribute("apiVersion", apiVersion);
}
}
use of org.springframework.extensions.webscripts.Match in project alfresco-remote-api by Alfresco.
the class CMISDispatcherRegistryImpl method getDispatcher.
@Override
public CMISDispatcher getDispatcher(WebScriptRequest req) {
CMISDispatcher dispatcher = null;
Match match = req.getServiceMatch();
Map<String, String> templateVars = match.getTemplateVars();
String bindingStr = templateVars.get("binding");
String apiVersion = templateVars.get("apiVersion");
if (bindingStr != null && apiVersion != null) {
Binding binding = null;
try {
binding = Binding.valueOf(bindingStr);
} catch (IllegalArgumentException e) {
// nothing to do, binding remains null
}
if (binding != null) {
Endpoint endpoint = new Endpoint(binding, apiVersion);
dispatcher = registry.get(endpoint);
} else {
// TODO
}
}
return dispatcher;
}
use of org.springframework.extensions.webscripts.Match in project alfresco-remote-api by Alfresco.
the class BlockingRemoteUserMapper method prepareMockRequest.
private WebScriptServletRequest prepareMockRequest(Set<String> families, String headerToAdd) {
HttpServletRequest mockHttpRequest = mock(HttpServletRequest.class);
when(mockHttpRequest.getScheme()).thenReturn("http");
if (headerToAdd != null) {
when(mockHttpRequest.getHeader("Authorization")).thenReturn(headerToAdd);
}
WebScriptServletRequest mockRequest = mock(WebScriptServletRequest.class);
when(mockRequest.getHttpServletRequest()).thenReturn(mockHttpRequest);
WebScript mockWebScript = mock(WebScript.class);
Match mockMatch = new Match("fake", Collections.EMPTY_MAP, "whatever", mockWebScript);
when(mockRequest.getServiceMatch()).thenReturn(mockMatch);
Description mockDescription = mock(Description.class);
when(mockWebScript.getDescription()).thenReturn(mockDescription);
when(mockDescription.getFamilys()).thenReturn(families);
return mockRequest;
}
Aggregations