提供登录凭据时如何重定向到特定页面 [英] How to redirect to particular page when provided login credentials

查看:81
本文介绍了提供登录凭据时如何重定向到特定页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的spring security xml文件由以下行组成。



My spring security xml file consist this lines.

<http auto-config="true" use-expressions="true">
<intercept-url pattern='/welcome*' access="hasAnyRole('User', 'Admin')" />
<intercept-url pattern='/createmail*' access="hasAnyRole('User', 'Admin')" />
		<intercept-url pattern='/createdate*' access="hasAnyRole('User', 'Admin')" />
<intercept-url pattern="/runApp*" access="hasAnyRole('User', 'Admin','ROLE_ANONYMOUS')" />
<form-login login-page="/login" authentication-failure-url="/login.jsp?login_error=true" default-target-url="/welcome" />
<logout logout-success-url="/login" invalidate-session="true" />





我使用此链接http:// localhost:8080 / myproject / runApp?dataid = 123。这是匿名用户可以使用的链接。但是注册用户有权使用数据ID来保护页面。注册用户可以提供可以保护此特定页面的用户名。因此,当有权访问此安全页面的其他注册用户使用此链接时,他将通过控制器重定向到登录页面以获取其凭据。以下是代码。



I am using this link "http://localhost:8080/myproject/runApp?dataid=123". This is the link which can be used by anonymous user. But the registered user has a privilege to secure the page with the help of data id. The registered user can provide the username who can secure this particular page. So when other registered user who has access to this secure page uses this link he is redirected to login page for his credentials through the controller following is the code.

if (security.equalsIgnoreCase("Secured")) {
			Authentication auth = SecurityContextHolder.getContext()
					.getAuthentication();
			if ((auth instanceof AnonymousAuthenticationToken)) {
				return "login";
			}}



当他提供凭证时,会将其指向欢迎页面。而我希望它重定向到他用过的链接。当他直接使用登录页面时,他应该被重定向到欢迎。



谢谢。


When he provides his credential it directing it to welcome page. whereas i want it to redirect to the link he had used. And when he directly using login page he should be redirected to welcome.

Thanks.

推荐答案

你好Shrikanth,



对于Spring Security 2.0.x,这可以完成

Hello Shrikanth,

For Spring Security 2.0.x this can be done either


  1. 通过http标签

  1. via http tag
<http ...>
    ...
    <form-login ...

      always-use-default-target='false' />
</http>

  • 或通过bean配置

  • or via the bean configuration

    <bean id="authenticationProcessingFilter" class="org.springframework.security.ui.webapp.AuthenticationProcessingFilter">
         <property name="alwaysUseDefaultTargetUrl" value="false" />
         </bean>



  • Spring Security 3.0.x提供了这个开箱即用的功能。请查看上课程的文档SavedRequestAwareAuthenticationSuccessHandler



    问候,


    Spring Security 3.0.x offer''s this out-of-box. Please checkout the documentation for class SavedRequestAwareAuthenticationSuccessHandler

    Regards,


    我自己解决了这个问题。

    重定向时登录页面以获取我在会话中保存数据的凭据。当注册用户登录时,它会进入控制器,我从会话中获取数据并将其重定向到所需的页面。
    I solved this by myself.
    When redirecting to login page for the credentials i am saving the data in the session. And when the registered user logins it goes to the controller where i get the data from the session and redirect it to the desired page.


    这篇关于提供登录凭据时如何重定向到特定页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆