(window.webpackJsonp=window.webpackJsonp||[]).push([[305],{731:function(t,e,a){"use strict";a.r(e);var s=a(56),r=Object(s.a)({},(function(){var t=this,e=t.$createElement,a=t._self._c||e;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h1",{attrs:{id:"testing-form-based-authentication"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#testing-form-based-authentication"}},[t._v("#")]),t._v(" Testing Form Based Authentication")]),t._v(" "),a("p",[t._v("You can easily create a request to test a form based authentication using Spring Security’s testing support.\nFor example, the following "),a("code",[t._v("formLogin")]),t._v(" "),a("RouterLink",{attrs:{to:"/en/spring-security/request-post-processors.html"}},[a("code",[t._v("RequestPostProcessor")])]),t._v(' will submit a POST to "/login" with the username "user", the password "password", and a valid CSRF token:')],1),t._v(" "),a("p",[t._v("Java")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("mvc\n\t.perform(formLogin())\n")])])]),a("p",[t._v("Kotlin")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("mvc\n\t.perform(formLogin())\n")])])]),a("p",[t._v('It is easy to customize the request.\nFor example, the following will submit a POST to "/auth" with the username "admin", the password "pass", and a valid CSRF token:')]),t._v(" "),a("p",[t._v("Java")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v('mvc\n\t.perform(formLogin("/auth").user("admin").password("pass"))\n')])])]),a("p",[t._v("Kotlin")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v('mvc\n .perform(formLogin("/auth").user("admin").password("pass"))\n')])])]),a("p",[t._v('We can also customize the parameters names that the username and password are included on.\nFor example, this is the above request modified to include the username on the HTTP parameter "u" and the password on the HTTP parameter "p".')]),t._v(" "),a("p",[t._v("Java")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v('mvc\n\t.perform(formLogin("/auth").user("u","admin").password("p","pass"))\n')])])]),a("p",[t._v("Kotlin")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v('mvc\n .perform(formLogin("/auth").user("u","admin").password("p","pass"))\n')])])]),a("p",[a("RouterLink",{attrs:{to:"/en/spring-security/csrf.html"}},[t._v("Mocking CSRF")]),a("RouterLink",{attrs:{to:"/en/spring-security/http-basic.html"}},[t._v("Mocking HTTP Basic")])],1)])}),[],!1,null,null,null);e.default=r.exports}}]);