jquery - How to make an ajax request in login form with spring security? -


i read several articles , followed them didn't work in case. login form follows:-

<div style="text-align: center; padding: 30px; border: 1px solid; width: 300px;">      <form method="post"           action='j_spring_security_check' id="login_form" >        <table>          <tr>            <td colspan="2" style="color: red">${message}</td>          </tr>           <tr>            <td>user name:</td>             <td><input type="text" name="j_username" id="uname"  value='<c:if test="${not empty param.login_error}">                                                      <c:out value="${spring_security_last_username}"/>                                                      </c:if>' /></td>          </tr>           <tr>            <td>password:</td>             <td><input type="password" name="j_password" /></td>          </tr>           <tr>            <td colspan="1"><input type="submit" value="login" /></td>             <td colspan="1"><input name="reset" type="reset" /></td>          </tr>        </table>      </form>    </div> 

i making ajax request follows:-

<script>          $("#login_form").submit(function(e){             var formurl = $("#login_form").attr("action");             var postdata=$("#login_form").serializearray();             $.ajax({                 url:"/abhishekchat/j_spring_security_check",                 method:post,                 data:postdata,                 beforesend: function (xhr) {                      xhr.setrequestheader("x-ajax-call", "true");                  },                  success:function(response){console.log("success");},                 error:function(response){console.log("operation failed");}              });             e.preventdefault();         });         $("#login_form").submit();     </script> 

but unable make ajax request. want ask should in order make ajax request. spring-security.xml follows:-

<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"              xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"              xmlns:security="http://www.springframework.org/schema/security"              xmlns:context="http://www.springframework.org/schema/context"              xmlns:jdbc="http://www.springframework.org/schema/jdbc"              xmlns="http://www.w3.org/1999/xsl/transform"              xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">       <security:http auto-config="true">         <security:intercept-url pattern="/search*" access="role_admin" />         <security:form-login login-page="/login" default-target-url="/search" authentication-failure-url="/login1" />         <security:logout logout-success-url="/logout" />     </security:http>      <security:authentication-manager>         <security:authentication-provider >              <!-- <security:user-service>                    <security:user name="admin" password="admin123" authorities="role_admin" />                </security:user-service>-->             <security:jdbc-user-service data-source-ref="datasource"                                         users-by-username-query="select firstname,password,enabled user100 firstname=?"                                         authorities-by-username-query="select u100.firstname,role user_roles urole, user100 u100 urole.firstname=?"                     />             <!--</security:authentication-provider>         </security:authentication-manager>-->             <!--<security:authentication-manager>                 <security:authentication-provider>                     <security:jdbc-user-service data-source-ref="datasource"                                         users-by-username-query="                           select login username,password                           users100 login=?"                                         authorities-by-username-query="role_admin"                              />-->         </security:authentication-provider>     </security:authentication-manager>      <!--<beans:bean id="myuserdetailsservice"                 class="org.springframework.security.core.userdetails.jdbc.jdbcdaoimpl">         <beans:property name="datasource" ref="datasource"/>     </beans:bean>-->      <beans:bean id="datasource"                 class="org.springframework.jdbc.datasource.drivermanagerdatasource">         <beans:property name="driverclassname" value="com.mysql.jdbc.driver" />         <beans:property name="url" value="jdbc:mysql://localhost:3306/abhi" />         <beans:property name="username" value="root" />         <beans:property name="password" value="system" />     </beans:bean>     <beans:bean id="mysessionfactory"  class="org.springframework.orm.hibernate3.localsessionfactorybean">         <beans:property name="datasource" ref="datasource"></beans:property>          <beans:property name="mappingresources">             <beans:list>                 <beans:value>user.hbm.xml</beans:value>             </beans:list>         </beans:property>          <beans:property name="hibernateproperties">             <beans:props>                 <beans:prop key="hibernate.dialect">org.hibernate.dialect.mysqldialect</beans:prop>                  <beans:prop key="hibernate.hbm2ddl.auto">update</beans:prop>                 <beans:prop key="hibernate.show_sql">true</beans:prop>              </beans:props>         </beans:property>     </beans:bean>      <beans:bean id="template" class="org.springframework.orm.hibernate3.hibernatetemplate">         <beans:property name="sessionfactory" ref="mysessionfactory"></beans:property>     </beans:bean>       <!---<jdbc:embedded-database id="datasource"/>--> </beans:beans> 


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -