You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by acec acec <to...@yahoo.ca> on 2011/01/24 19:55:47 UTC

How to redirect to original URL?

I am using spring mvc, so I choose PassThruAuthenticationFilter.

1: when I input /admin/home.html from my browser, it will display my login page.
2: I input right username, password and submit the form, it will go to my login() function. After I called Subject.login(usernamePasswordToken), I want to redirect to /admin/home.html

But I do not know how can I get the original web address, such as "/admin/home.html" ?
====================================================
@Controller
@RequestMapping("/login.html")
public class LoginController {

	@ModelAttribute("loginForm")
	public LoginForm getLoginForm(){
		LoginForm loginForm = new LoginForm();
		return loginForm;
	}

	@RequestMapping(method = RequestMethod.GET)
    public ModelAndView loginForm(HttpServletRequest request){
        ModelAndView modelAndView = new ModelAndView("login");
        return modelAndView;
    }

	@RequestMapping(method = RequestMethod.POST)
    public ModelAndView login(HttpServletRequest request, @ModelAttribute LoginForm loginForm, Errors errors) {

        Subject subject = SecurityUtils.getSubject();
       	UsernamePasswordToken token = new UsernamePasswordToken(loginForm.getUsername(), loginForm.getPassword());

        try {
            subject.login(token);
        } catch (AuthenticationException e) {
        	errors.reject("invalidLogin", "The username or password was not correct.");
        }

        if (errors.hasErrors()) {
        	ModelAndView modelAndView = new ModelAndView("login");
            return modelAndView;
        } else {
          //TODO: how to redirect to user inputing URL?????????
        }
    }
}

=================================================
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean"
		p:securityManager-ref="securityManager"
		p:loginUrl="/login.html">
		<property name="filters">
			<util:map>
				<entry key="authc">
					<bean class="org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter"/>
				</entry>
			</util:map>
		</property>
 		<property name="filterChainDefinitions">
			<value>
				/admin/** = authc, roles[admin]
				/user/** = authc, roles[user]
				/public/** = anon
				/** = authc
			</value>
		</property>
	</bean>