package com.atlassian.stash.internal.spring;

import org.springframework.security.web.util.matcher.RequestMatcher;

import javax.servlet.http.HttpServletRequest;

/**
 * This class can be configured to match a specific HTTP method.
 */
public class MethodRequestMatcher implements RequestMatcher {

    private final String httpMethod;

    /**
     * Creates a RequestMatcher for the configured HTTP method
     *
     * @param httpMethod the HTTP method to match.
     */
    public MethodRequestMatcher(String httpMethod) {
        this.httpMethod = httpMethod;
    }

    @Override
    public boolean matches(HttpServletRequest request) {
        String currentHttpMethod = request.getMethod();
        if (httpMethod.equals(currentHttpMethod)) {
            return true;
        }
        return false;
    }
}
