Hi All,
I have a web app which has a login form on all the pages.
I am using spring 2.5 .
After the login happens (whether successs or failure) the user should be redirected back to the same page. Can someone please tell me how to go about implementing this ?
Below are my files:
Spring XML file:
Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:security="http://www.springframework.org/schema/security" 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-2.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.4.xsd"> <security:http auto-config="true" access-denied-page="/HCPHome"> <security:intercept-url pattern="/loginURL*" access="ROLE_USER" /> <security:form-login login-page="/loginURL" login-processing-url="/loginURL" authentication-failure-url="/general/home?login_error=true" default-target-url="/general/home"/> <security:logout logout-url="/signout" logout-success-url="/general/home"/> </security:http> <bean id="customAuthenticationProvider" class="com.myapp.authentication.CustomAuthenticationProvider" > <security:custom-authentication-provider /> <property name="userDetailsService"> <ref bean="userDetailsService" /> </property> </bean> <bean id="userDetailsService" class="com.myapp.authentication.UserDetailsService"> </bean> <bean id="securityContext" class="org.springframework.security.context.SecurityContextHolder" factory-method="getContext">
Authentication class
Code:public class CustomAuthenticationProvider implements AuthenticationProvider { public Authentication authenticate(Authentication authentication) { /* Authentication logic goes here */ return new UsernamePasswordAuthenticationToken(securityUser, username, securityUser.getAuthorities()); } public boolean supports(Class authentication) { return true; } }
Login Form
Code:<form:form action="/myapp/loginURL" commandName="command" name="login_form" method="post"> <input class="UserName" type="text" id="j_username" name="j_username" onClick="clearText(0);" onBlur="fillText(0)" value="Enter User Name"/> </form:form> <input type="password" name="j_password" id="j_password" style="display:none;" type="password" value="" class="last" onblur="onBlurHandler_password(this);" onkeypress="javascript:trapLoginEnter(event);" />




