Friday, 15 July 2011

Tiles2 with Spring security, login error message not getting displayed -



Tiles2 with Spring security, login error message not getting displayed -

i trying out tiles2 templating webpages in new spring mvc application. created login page called login.jsp uses j_spring_security_check form post action.

i able login , validate authentication using authenticationprovider. however, stuck on how display error message in case of unsuccessful login attempt. created controller check if there query parameter error. login controller never getting called on normal login effort or on unsuccessful login attempt. controller class in context:component-scan in applicationcontext.xml.

i tried adding break points on controller never getting invoked. endpoint utilize accessing login page.

it seems me controller not getting used , login.jsp displayed, how can create sure passes through controller?

can please tell me missing here, looked @ lot of illustration configurations , answers here, cannot find out doing wrong.

spring version: 3.1.0 tiles version: 2.2.2

controller:

@controller public class logincontroller { @requestmapping(value = "/login.company", method = requestmethod.get) public modelandview login(@requestparam(value = "error", required = false) string error, @requestparam(value = "logout", required = false) string logout) { modelandview model = new modelandview(); if(error !=null && !stringutils.isblank(error)){ model.addobject("error", "incorrect username or password."); }else if(logout !=null && !stringutils.isblank(logout)){ model.addobject("msg", "you have been logged out."); } model.setviewname("login"); homecoming model; } }

tiles.xml

<tiles-definitions> <definition name="mainlayout" template="/web-inf/tiles/mainlayout.jsp"> <put-attribute name="includes" value="/web-inf/tiles/includes.jsp"/> <put-attribute name="content" value="/web-inf/tiles/blank.jsp"/> <put-attribute name="footer" value="/web-inf/tiles/footer.jsp"/> </definition> <definition name="*" extends="mainlayout"> <put-attribute name="content" value="/web-inf/views/{1}.jsp"/> </definition> </tiles-definitions>

security.xml

<beans:bean id="loginservice" class="com.loginservice"/> <authentication-manager> <authentication-provider ref="loginservice"> </authentication-provider> </authentication-manager> <http use-expressions="true"> <intercept-url pattern="/resources/**" access="permitall"/> <intercept-url pattern="/login.company" access="permitall"/> <intercept-url pattern="/**" access="hasrole('role_user')" /> <form-login login-page="/login.company" authentication-failure-url="/login.company?error=1" /> <logout logout-success-url="/login.company?logout" /> </http>

applicationcontext.xml

<bean id="viewresolver" class="org.springframework.web.servlet.view.urlbasedviewresolver"> <property name="viewclass" value="org.springframework.web.servlet.view.tiles2.tilesview" /> </bean> <bean id="tilesconfigurer" class="org.springframework.web.servlet.view.tiles2.tilesconfigurer"/>

web.xml

<?xml version="1.0" encoding="utf-8"?> <web-app metadata-complete="false" 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"> <context-param> <param-name>contextconfiglocation</param-name> <param-value> /web-inf/applicationcontext.xml /web-inf/spring/security.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> <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> <servlet> <servlet-name>mvc-dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name>contextconfiglocation</param-name> <param-value> /web-inf/applicationcontext.xml </param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>mvc-dispatcher</servlet-name> <url-pattern>*.company</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>mvc-dispatcher</servlet-name> <url-pattern>/index.html</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app>

just found problem after few frustrating hours, missed annotation-driven tag in applicationcontext.xml.

<mvc:annotation-driven/>

so failed recognize annotation driven controllers.

spring-mvc spring-security tiles tiles2 apache-tiles

No comments:

Post a Comment