HTTP 404 Not Found after successful Spring Security authentication -
i trying implement spring security authentication , authorization using database. spring security authentication working good. getting http 404 not found page url /sample_app/j_spring_security_check, instead of default-target-url should goto.
here spring-security file
<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.1.xsd"> <beans:import resource="im-jndi-datasource.xml" /> <http pattern="/inventory/auth/login" security="none"/> <http pattern="/inventory/auth/deny" security="none"/> <http pattern="/images/**" security="none"/> <http pattern="/css/**" security="none"/> <http pattern="/js/**" security="none"/> <http auto-config="true"> <intercept-url pattern="/inventory/**" access="role_admin" /> <form-login login-page="/inventory/auth/login" default-target-url="/inventory/landing/loaddashboardpage" authentication-failure-url="/inventory/auth/login?error" username-parameter="username" password-parameter="password" /> <access-denied-handler error-page="/inventory/auth/deny"/> <logout logout-success-url="/logout" /> <session-management session-authentication-error-url="/inventory/auth/login" invalid-session-url="/inventory/auth/login"> <concurrency-control max-sessions="1" error-if-maximum-exce eded="true"/> </session-management> </http> <authentication-manager> <authentication-provider> <!-- <security:user-service> <security:user name="dineshonjava" password="sweety" authorities="role_user" /> </security:user-service> --> <jdbc-user-service data-source-ref="datasource" users-by-username-query="select username, password, status enabled bbp_user username=?" authorities-by-username-query="select us.username, ur.rolename authority bbp_user us, bbp_users_and_roles bur, bbp_role ur us.user_id = bur.user_id , bur.role_id =ur.role_id , us.username =? " /> </authentication-provider> </authentication-manager> </beans:beans>
here part of spring-servlet.xml file
<context-param> <param-name>contextconfiglocation</param-name> <param-value>web-inf/eimsgo-security.xml</param-value> </context-param> <servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet </servlet-class> <load-on-startup>1</load-on-startup> <init-param> <param-name>contextconfiglocation</param-name> <param-value>web-inf/spring-servlet.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>/inventory/*</url-pattern> </servlet-mapping> <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>
i use tiles2.tilesviewresolver , contentnegotiatingviewresolver
here tiles-context xml
<bean id="tilesconfigurer" class="org.springframework.web.servlet.view.tiles2.tilesconfigurer"> <property name="definitions"> <list> <value>/web-inf/views.xml</value> </list> </property> </bean> <bean class="org.springframework.web.servlet.view.contentnegotiatingviewresolver"> <property name="mediatypes"> <map> <entry key="atom" value="application/atom+xml"/> <entry key="html" value="text/html"/> <entry key="json" value="application/json"/> </map> </property> <property name="defaultviews"> <list> <bean class="org.springframework.web.servlet.view.json.mappingjacksonjsonview" /> </list> </property> </bean> <bean class="org.springframework.web.servlet.view.internalresourceviewresolver"> <property name="prefix"> <value>/jsp/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean>
my welcome file index.jsp hits logincontroller.java url (/inventory/auth/login)
logincontroller.java
@controller @requestmapping("/auth") public class logincontroller { @requestmapping(value = "/login", method = requestmethod.get) public modelandview login(@requestparam(value = "error", required = false) string error, @requestparam(value = "logout", required = false) string logout, @requestparam(value = "invalid", required = false) string invalid) { modelandview model = new modelandview(); if (error != null) { model.addobject("error", "invalid username , password!"); } if (logout != null) { model.addobject("msg", "you've been logged out successfully."); } if(invalid != null) { model.addobject("invalid", "invalid session!!"); } model.setviewname("home_creation"); return model; }
}
after successful login, should goto /inventory/landing/loaddashboardpage per default-target-url defined in security xml file.
where /landing 1 of spring controller, , loaddashboarpage method level mapping. loaddashboardpage interacts database , set map object , retuns view string "dashboardpage". tilesviewresolver should render page.
inventorycontroller.java
@controller @requestmapping("/landing") public class inventorycontroller { @requestmapping(value = { "/loaddashboardpage" }, method = { get, post }) public string loaddashboardpage(map<string, object> model, httpservletrequest request, httpsession session) { list loblist = new arraylist(); inventoryservice inventoryservice = (inventoryservice) inventoryapplicationcontext .getbean("inventoryservice"); loblist = inventoryservice.loadlob(); model.put("lob", loblist); model.put("lefttreee", inventoryservice.loaddatafornavigator()); return "dashboardpage"; }
please find log below
2014-12-05 22:55:27,419 [http-bio-8090-exec-8] debug org.springframework.jdbc.datasource.datasourcetransactionmanager - initiating transaction commit
2014-12-05 22:55:27,420 [http-bio-8090-exec-8] debug org.springframework.jdbc.datasource.datasourcetransactionmanager - committing jdbc transaction on connection [jdbc:oracle:thin:@10.237.31.14:1521:xe, username=admin, oracle jdbc driver]
2014-12-05 22:55:27,422 [http-bio-8090-exec-8] debug org.springframework.jdbc.datasource.datasourcetransactionmanager - releasing jdbc connection [jdbc:oracle:thin:@10.237.31.14:1521:xe, username=admin, oracle jdbc driver] after transaction
2014-12-05 22:55:27,422 [http-bio-8090-exec-8] debug org.springframework.jdbc.datasource.datasourceutils - returning jdbc connection datasource
2014-12-05 22:55:27,425 [http-bio-8090-exec-8] debug org.springframework.web.servlet.view.contentnegotiatingviewresolver - requested media types [image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, /] (based on accept header)
2014-12-05 22:55:27,425 [http-bio-8090-exec-8] debug org.springframework.beans.factory.support.defaultlistablebeanfactory - invoking afterpropertiesset() on bean name 'dashboardpage.atom'
2014-12-05 22:55:27,426 [http-bio-8090-exec-8] debug org.springframework.beans.factory.support.defaultlistablebeanfactory - invoking afterpropertiesset() on bean name 'dashboardpage.json'
2014-12-05 22:55:27,429 [http-bio-8090-exec-8] debug org.springframework.beans.factory.support.defaultlistablebeanfactory - invoking afterpropertiesset() on bean name 'dashboardpage.html'
2014-12-05 22:55:27,430 [http-bio-8090-exec-8] debug org.springframework.web.servlet.view.contentnegotiatingviewresolver - returning [org.springframework.web.servlet.view.tiles2.tilesview: name 'dashboardpage'; url [dashboardpage]] based on requested media type '/'
2014-12-05 22:55:27,430 [http-bio-8090-exec-8] debug org.springframework.web.servlet.dispatcherservlet - rendering view [org.springframework.web.servlet.view.tiles2.tilesview: name 'dashboardpage'; url [dashboardpage]] in dispatcherservlet name 'spring'
2014-12-05 22:55:27,430 [http-bio-8090-exec-8] debug org.springframework.web.servlet.view.tiles2.tilesview - added model object 'lob' of type [java.util.arraylist] request in view name 'dashboardpage'
2014-12-05 22:55:27,431 [http-bio-8090-exec-8] debug org.springframework.web.servlet.view.tiles2.tilesview - added model object 'lefttreee' of type [java.util.hashmap] request in view name 'dashboardpage'
2014-12-05 22:55:27,431 [http-bio-8090-exec-8] debug org.apache.tiles.impl.basictilescontainer - render request recieved definition 'dashboardpage'
2014-12-05 22:55:27,432 [http-bio-8090-exec-8] debug org.springframework.web.servlet.dispatcherservlet - completed request
2014-12-05 22:55:27,432 [http-bio-8090-exec-8] debug org.springframework.security.web.access.exceptiontranslationfilter - chain processed normally
2014-12-05 22:55:27,432 [http-bio-8090-exec-8] debug org.springframework.security.web.context.securitycontextpersistencefilter - securitycontextholder cleared, request processing completed
spring security authenticates successfully here , view resolver not rendering requested page.
instead getting http://abc.xyz.com/sample_app/j_spring_security_check
it should allow user goto url defined in default-target-url
/sample_app/inventory/landing/loaddashboardpage
please advise!!
i resolved issue myself. spring security tightly intercepts urls including css, images, javascripts, jsp files , everything.
the problem here is, using tilesviewresolver
<definition name="logoutpage" template="/jsp/logout.jsp"> <put-attribute name="header" value="/jsp/tiles/logoutheader.jsp" /> <put-attribute name="footer" value="/jsp/tiles/footer.jsp" /> <put-attribute name="content" value="/jsp/logout_creation.jsp" /> </definition>
i forget configure spring security intercept sub-urls these tiles pages use authentication based on roles.
Comments
Post a Comment