Search in sources :

Example 1 with Match

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Match(org.springframework.extensions.webscripts.Match)

Example 2 with Match

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;
}
Also used : WebScriptRequest(org.springframework.extensions.webscripts.WebScriptRequest) Matchers.anyString(org.mockito.Matchers.anyString) Match(org.springframework.extensions.webscripts.Match) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Content(org.springframework.extensions.surf.util.Content) InvocationOnMock(org.mockito.invocation.InvocationOnMock) JSONObject(org.json.JSONObject)

Example 3 with Match

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);
    }
}
Also used : Match(org.springframework.extensions.webscripts.Match)

Example 4 with Match

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;
}
Also used : Match(org.springframework.extensions.webscripts.Match)

Example 5 with Match

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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Description(org.springframework.extensions.webscripts.Description) WebScriptServletRequest(org.springframework.extensions.webscripts.servlet.WebScriptServletRequest) WebScript(org.springframework.extensions.webscripts.WebScript) Match(org.springframework.extensions.webscripts.Match)

Aggregations

Match (org.springframework.extensions.webscripts.Match)15 WebScriptRequest (org.springframework.extensions.webscripts.WebScriptRequest)8 HashMap (java.util.HashMap)6 Params (org.alfresco.rest.framework.resource.parameters.Params)6 Test (org.junit.Test)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Content (org.springframework.extensions.surf.util.Content)4 StringReader (java.io.StringReader)3 UnsupportedResourceOperationException (org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException)3 Farmer (org.alfresco.rest.framework.tests.api.mocks.Farmer)3 ResourceWebScriptPost (org.alfresco.rest.framework.webscripts.ResourceWebScriptPost)3 List (java.util.List)2 ResourceWebScriptGet (org.alfresco.rest.framework.webscripts.ResourceWebScriptGet)2 Matchers.anyString (org.mockito.Matchers.anyString)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Description (org.springframework.extensions.webscripts.Description)2 WebScript (org.springframework.extensions.webscripts.WebScript)2 WebScriptServletRequest (org.springframework.extensions.webscripts.servlet.WebScriptServletRequest)2 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1