title: How to run curl command to call rest api with spring security implemented
body: <p>I implemented LDAP authentication with Spring Security in a Spring Boot Application. User credentials are passed in through a http login form. Username is taken as <code>{0}</code> in <code>.userDnPatterns("cn={0},ou=institution,ou=people")</code>. However, if I wanted to call rest api with curl command, how should I pass in the username and password from curl (or custom html page)? In other words, how to pass a variable from POST request to the config class?</p>
  
  <p>My websecurityconfig class is as follows:</p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http
              .authorizeRequests()
                  .anyRequest()
                  .authenticated()
                  .and()
              .formLogin();
      }
  
      @Configuration
      protected static class AuthenticationConfiguration extends
              GlobalAuthenticationConfigurerAdapter {
  
          @Override
          public void init(AuthenticationManagerBuilder auth) throws Exception { 
              DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource("ldap://ldap.xxx.edu:389/dc=mdanderson,dc=edu");
              contextSource.setUserDn("cn=ris_flow,ou=service accounts,ou=institution,ou=service accounts,dc=mdanderson,dc=edu");
              contextSource.setPassword("xxxyyyzzz");
              contextSource.afterPropertiesSet();
  
              LdapAuthenticationProviderConfigurer&lt;AuthenticationManagerBuilder&gt; ldapAuthenticationProviderConfigurer = auth.ldapAuthentication();
  
              ldapAuthenticationProviderConfigurer
                  .userDnPatterns("cn={0},ou=institution,ou=people")
                  .userSearchBase("")
                  .contextSource(contextSource);
          }
      }
  }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>When I run </p>
  
  <pre><code>curl -d "username=djiao&amp;password=xxxyyyzzz" http://localhost:8080/ristore/foundation/TRF134936
  </code></pre>
  
  <p>it returns nothing. The same url works in a browser though. By turning on verbose with <code>-v</code>, here is the output of the curl command.</p>
  
  <pre><code>* Hostname was NOT found in DNS cache
  *   Trying ::1...
  * Connected to localhost (::1) port 8080 (#0)
  &gt; POST /ristore/foundation/TRF134936 HTTP/1.1
  &gt; User-Agent: curl/7.37.1
  &gt; Host: localhost:8080
  &gt; Accept: */*
  &gt; Content-Length: 35
  &gt; Content-Type: application/x-www-form-urlencoded
  &gt; 
  * upload completely sent off: 35 out of 35 bytes
  &lt; HTTP/1.1 302 Found
  * Server Apache-Coyote/1.1 is not blacklisted
  &lt; Server: Apache-Coyote/1.1
  &lt; X-Content-Type-Options: nosniff
  &lt; X-XSS-Protection: 1; mode=block
  &lt; Cache-Control: no-cache, no-store, max-age=0, must-revalidate
  &lt; Pragma: no-cache
  &lt; Expires: 0
  &lt; X-Frame-Options: DENY
  &lt; Set-Cookie: JSESSIONID=FE8C94FC8B445A2C8AA1FCFBB5F2826D; Path=/; HttpOnly
  &lt; Location: http://localhost:8080/login
  &lt; Content-Length: 0
  &lt; Date: Wed, 27 Apr 2016 02:19:43 GMT
  &lt; 
  * Connection #0 to host localhost left intact
  </code></pre>