How to restrict REST API v2 to allow POST only?


I am following this to expose a REST API v2 for my services:

5.8.2. Services Configuration

How can I restrict an endpoint to allow POST only?

Thank you.

There is no specific configuration in Cuba to do that. However, you can always define a regular HttpFilter in your web.xml and forbid unwanted requests there.

Thank you Max, glad to know that CUBA also has that certain level of being configurable using standard means.


Could you give any example how we can allow only one method like POST to the services by using HttpFilter.

I am using ContainerRequestFilter to give access control. But this class is not triggering in cuba platform.

//my code

public class RoleBasedResource implements ContainerRequestFilter {
public void filter(ContainerRequestContext requestContext) throws IOException{

While making a rest api service call. @Provider with ContainerRequestFilter is not triggering.Can you please help here.


you may create a regular Filter and register it in web.xml


import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyServletFilter implements Filter {

    public void init(FilterConfig filterConfig) throws ServletException {}

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        HttpServletRequest httpRequest = (HttpServletRequest) request;
        HttpServletResponse httpResponse = (HttpServletResponse) response;
        if (isRestServiceUrl(httpRequest.getRequestURI()) && "GET".equals(httpRequest.getMethod())) {
        } else {
            chain.doFilter(request, response);

    private boolean isRestServiceUrl(String uri) {
        return uri.contains("/rest/v2/services/");

    public void destroy() {}