How can I logon and POST to RESTful resource protected by Spring Security? -


i creating restful web appliaction , using spring backend. when wasn't implementing spring security, add new record jpa entity "timestamp" using curl command command line. using spring security when user not authenticated redirected login page. when try curl add record following:

curl -i -x post -v -u myusername:mypass -h "content-type:application/json" -d '{ "timestamp" : "2016-06-16t08:17:20.000z", "peoplein" : "1", "peopleout":"0", "venue": "localhost://8181/venues/12" }' http://localhost:8181/timestamps 

this displayed in terminal:

*   trying ::1... * connected localhost (::1) port 8181 (#0) * server auth using basic user 'harry.quigley2@mail.dcu.ie' > post /timestamps http/1.1 > host: localhost:8181 > authorization: basic agfycnkucxvpz2xletjabwfpbc5ky3uuawu6b2s= > user-agent: curl/7.43.0 > accept: */* > content-type:application/json > content-length: 118 > * upload sent off: 118 out of 118 bytes < http/1.1 302 found http/1.1 302 found < server: apache-coyote/1.1 server: apache-coyote/1.1 < x-content-type-options: nosniff x-content-type-options: nosniff < x-xss-protection: 1; mode=block x-xss-protection: 1; mode=block < cache-control: no-cache, no-store, max-age=0, must-revalidate cache-control: no-cache, no-store, max-age=0, must-revalidate < pragma: no-cache pragma: no-cache < expires: 0 expires: 0 < x-frame-options: deny x-frame-options: deny < set-cookie: jsessionid=a8edfa6339da76b11e0cdf6bb566a748; path=/; httponly set-cookie: jsessionid=a8edfa6339da76b11e0cdf6bb566a748; path=/; httponly < location: http://localhost:8181/login location: http://localhost:8181/login < content-length: 0 content-length: 0 < date: sat, 28 may 2016 16:35:53 gmt date: sat, 28 may 2016 16:35:53 gmt 

i getting 302 redirect. every line repeated twice - i'm not sure why is.

my spring security config is:

@configuration @enablewebsecurity @componentscan(basepackageclasses = customuserdetailsservice.class) public class websecurityconfig extends websecurityconfigureradapter {      @autowired     private userdetailsservice userdetailsservice;      @autowired     public void configureglobal(userdetailsservice userdetailsservice, authenticationmanagerbuilder auth) throws exception {         auth.userdetailsservice(userdetailsservice);     }       @override     protected void configure(httpsecurity http) throws exception {         http                 .authorizerequests()                     .antmatchers("/", "/venue/new", "/static/**").permitall()                     .anyrequest().authenticated();                 http.formlogin()                     .loginpage("/login")                     .permitall()                     .and()                 .logout()                     .permitall();         http.csrf().disable();     }  } 

if understand why i'm being redirected , advise on change in order able post jpa entity, great! thanks

to authenticate curl need setup http basic authentication:

http.httpbasic(); 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -