title: Access to the specified resource has been forbidden in simple Spring webservice Demo
body: <p>I have created simple spring security demo with REST webservice.
      I have spent lot of hours on It.Need strong pointers regarding simple working spring security for rest webservice with latest versions.
      My Controller is</p>
  
  <pre><code>@Controller
  public class RestContoller {
      @RequestMapping(value = "/countryJSONProduce", method = RequestMethod.GET)
      public ResponseEntity&lt;CountryDetail&gt; getCountryJSON() {
  
          CountryDetail countryDetail = new CountryDetail("Values");
          ResponseEntity&lt;CountryDetail&gt; rentity = new ResponseEntity&lt;CountryDetail&gt;(countryDetail, HttpStatus.OK);
  
          return rentity;
      }
  
  @RequestMapping(value = "/countryJSONConsume", consumes = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
      public String consumeJSON(@RequestBody CountryDetail countryDetail) {
      System.out.println("Country Detail Example");
          return "home";
      }
  }
  web.xml is 
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;springrest&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;springrest&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/hello/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
      &lt;filter&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
      &lt;/filter&gt;
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/spring-security.xml
              /WEB-INF/springrest-servlet.xml
          &lt;/param-value&gt;
      &lt;/context-param&gt;
  
  
  my pom.xml is
  &lt;properties&gt;
          &lt;spring.version&gt;4.1.0.RELEASE&lt;/spring.version&gt;
          &lt;springsecurity.version&gt;4.0.2.RELEASE&lt;/springsecurity.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
  
          &lt;!-- for Jsp use --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
              &lt;version&gt;3.1.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- Spring mvc and Core --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- Spring mvc and Core --&gt;
          &lt;!-- JSON Response Spring Framework 4.1, the minimum jackson version should 
              be 2.1 --&gt;
  
  
          &lt;!-- Compatiable Spring Framework 4.1 --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
              &lt;version&gt;2.5.3&lt;/version&gt;
          &lt;/dependency&gt;
  
  
          &lt;!-- Spring Authentication Start --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
              &lt;artifactId&gt;spring-security-web&lt;/artifactId&gt;
              &lt;version&gt;${springsecurity.version}&lt;/version&gt;
  
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
              &lt;artifactId&gt;spring-security-config&lt;/artifactId&gt;
              &lt;version&gt;${springsecurity.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- Spring Authentication End --&gt;
  
      &lt;/dependencies&gt;
  
  When I Run the code sometimes it shows popup in my Eclipse Mars INTENAL
  browser for user and password.when i put my credentials it will goes to
  localhost:8080/SpringMavenRest2/ welcome page ok.when I hit the
  url localhost:8080/SpringMavenRest2/hello/countryJSONProduce
  which is calling my first service.. it is showing the Error :Access to
  the specified resource has been forbidden.403
  Even I put user name and
  password as basic auth.Now I am testing this second url  FROM CHROME
  POSTMAN CLIENT.
  I am using this configuration Java 1.8 ,Tomcat 8.0
  spring.version4.1.0.RELEASE ,springsecurity.version 4.0.2.RELEASE.
  and maven 3.3
  Its
  working well without authentication.Could you give any best referenced demo
  for spring security with basic authentication.  I have refered this also
   http://www.mkyong.com/spring-security/spring-security-hello-world-example/
  </code></pre>