Tuesday 15 July 2014

java - Spring Security Login returns Request method 'POST' not supported -



java - Spring Security Login returns Request method 'POST' not supported -

i created simple spirng mvc application spring security , hibernate. when trying login returns error message "request method 'post' not supported". here web.xml , servelet contexts.

web.xml <?xml version="1.0" encoding="utf-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-- spring mvc --> <servlet> <servlet-name>appservlet</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>appservlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <listener> <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> <context-param> <param-name>contextconfiglocation</param-name> <param-value> /web-inf/spring/appservlet/servlet-context.xml, /web-inf/spring/springsecurity-servlet.xml </param-value> </context-param> <!-- spring security --> <filter> <filter-name>springsecurityfilterchain</filter-name> <filter-class>org.springframework.web.filter.delegatingfilterproxy</filter-class> </filter> <filter-mapping> <filter-name>springsecurityfilterchain</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app> servletcontext.xml <?xml version="1.0" encoding="utf-8"?> <beans:beans xmlns="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemalocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"> <!-- dispatcherservlet context: defines servlet's request-processing infrastructure --> <!-- enables spring mvc @controller programming model --> <annotation-driven /> <!-- handles http requests /resources/** efficiently serving static resources in ${webapproot}/resources directory --> <resources mapping="/resources/**" location="/resources/" /> <!-- resolves views selected rendering @controllers .jsp resources in /web-inf/views directory --> <beans:bean class="org.springframework.web.servlet.view.internalresourceviewresolver"> <beans:property name="prefix" value="/web-inf/views/" /> <beans:property name="suffix" value=".jsp" /> </beans:bean> <!-- configure plugin json request , response in method handler --> <beans:bean class="org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter"> <beans:property name="messageconverters"> <beans:list> <beans:ref bean="jsonmessageconverter"/> </beans:list> </beans:property> </beans:bean> <!-- configure bean convert json pojo , vice versa --> <beans:bean id="jsonmessageconverter" class="org.springframework.http.converter.json.mappingjackson2httpmessageconverter"> </beans:bean> <!-- <beans:bean id="datasource" class="org.apache.commons.dbcp.basicdatasource" destroy-method="close"> <beans:property name="driverclassname" value="net.sourceforge.jtds.jdbc.driver" /> <beans:property name="url" value="jdbc:jtds:sqlserver://10.0.0.25:1433;databasename=3pltest;" /> <beans:property name="username" value="sa" /> <beans:property name="password" value="sa" /> </beans:bean> --> <beans:bean id="datasource" class="org.apache.commons.dbcp.basicdatasource" destroy-method="close"> <beans:property name="driverclassname" value="com.microsoft.sqlserver.jdbc.sqlserverdriver" /> <beans:property name="url" value="jdbc:sqlserver://sys-001\sqlexpress:1433;databasename=3pltest" /> <beans:property name="username" value="sa" /> <beans:property name="password" value="sa" /> </beans:bean> <!-- hibernate 4 sessionfactory bean definition --> <beans:bean id="hibernate4annotatedsessionfactory" class="org.springframework.orm.hibernate4.localsessionfactorybean"> <beans:property name="datasource" ref="datasource" /> <beans:property name="annotatedclasses"> <beans:list> <beans:value>com.dimensions.warehouse.model.employee</beans:value> <beans:value>com.dimensions.warehouse.model.user</beans:value> </beans:list> </beans:property> <beans:property name="hibernateproperties"> <beans:props> <beans:prop key="hibernate.dialect">org.hibernate.dialect.sqlserverdialect </beans:prop> <beans:prop key="hibernate.show_sql">true</beans:prop> </beans:props> </beans:property> </beans:bean> <beans:bean id="employeedao" class="com.dimensions.warehouse.dao.employeedaoimpl"> <beans:property name="sessionfactory" ref="hibernate4annotatedsessionfactory" /> </beans:bean> <beans:bean id="employeeservice" class="com.dimensions.warehouse.service.employeeserviceimpl"> <beans:property name="employeedao" ref="employeedao"></beans:property> </beans:bean> <beans:bean id="userdao" class="com.dimensions.warehouse.dao.userdaoimpl"> <beans:property name="sessionfactory" ref="hibernate4annotatedsessionfactory" /> </beans:bean> <beans:bean id="userservice" class="com.dimensions.warehouse.service.userserviceimpl"> <beans:property name="userdao" ref="userdao"></beans:property> </beans:bean> <beans:bean id="userdetailsservice" class="com.dimensions.warehouse.service.userdetailsserviceimp"> <beans:property name="userdao" ref="userdao" ></beans:property> </beans:bean> <context:component-scan base-package="com.dimensions.warehouse" /> <tx:annotation-driven transaction-manager="transactionmanager"/> <beans:bean id="transactionmanager" class="org.springframework.orm.hibernate4.hibernatetransactionmanager"> <beans:property name="sessionfactory" ref="hibernate4annotatedsessionfactory" /> </beans:bean> <tx:advice id="txadvice" transaction-manager="transactionmanager"> <tx:attributes> <tx:method name="get*" read-only="true" /> <tx:method name="find*" read-only="true" /> <tx:method name="*" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="userservicepointcut" expression="execution(* com.dimensions.warehouse.service.*service.*(..))" /> <aop:advisor advice-ref="txadvice" pointcut-ref="userservicepointcut" /> </aop:config> </beans:beans> springsecurity-servlet.xml <beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd"> <!-- enable use-expressions --> <http auto-config="true" use-expressions="true"> <intercept-url pattern="/employees**" access="hasrole('role_admin')" /> <!-- access denied page --> <access-denied-handler error-page="/403" /> <form-login login-page="/login" default-target-url="/welcome" authentication-failure-url="/login?error" username-parameter="username" password-parameter="password" /> <logout logout-success-url="/login?logout" /> <!-- enable csrf protection --> <csrf /> </http> <authentication-manager> <authentication-provider user-service-ref="userdetailsservice" > <password-encoder hash="plaintext" /> </authentication-provider> </authentication-manager> </beans:beans> appservlet.xml <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> <context:component-scan base-package="com.dimensions.warehouse.*" /> <bean class="org.springframework.web.servlet.view.internalresourceviewresolver"> <property name="prefix"> <value>/web-inf/views/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean> </beans>

java spring authentication spring-security

No comments:

Post a Comment