我正在使用Spring Security 3.1,並且我想在用戶登錄之前獲取來自URL的參數。所以,我期待着訪問我的登錄頁面的用戶向我發送一個redir參數(包含URL他想在他認證之後去)。當我請求的頁面,當我嘗試不提交登錄表單如何在Spring Security中獲取GET參數?
例如:?本地主機/對myApp導向= my.app.com /定製
如何從獲得再導向PARAM網址是什麼?我試過幾件事,包括重寫SimpleUrlAuthenticationSuccessHandler和調用request.getParameter(「redir」),但它返回null。我也嘗試實現我自己的過濾器UsernamePasswordAuthenticationFilter並在attemptAuthentication上調用getParameter(),但返回null。
UPDATE更多信息: 我的登錄頁面相當簡單,基本上是:通過POST方法調用/ j_spring_security_check的表單(使用j_username和j_password參數)。
我的身份驗證提供程序實現AuthenticationManager,因此在用戶通過身份驗證後,身份驗證對象將與授權列表,用戶,密碼一起返回。
我還實現了SimpleUrlAuthenticationSuccessHandler,並且方法onAuthenticationSuccess()將檢查他的權限,如果通過身份驗證並獲得許可,用戶將被重定向到他在URL上通知的頁面(現在,當我嘗試調用request.getParemeter(「redir」 )這種方法,我得到空。
public class GetURLFilter extends UsernamePasswordAuthenticationFilter{
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
throws AuthenticationException {
String paginaRedirecionar = request.getParameter("redir");
request.getSession().setAttribute("redirecionamento", paginaRedirecionar);
return super.attemptAuthentication(request, response);
}
}
<bean id="authenticationFilter"
class="com.uolinc.adm.security.GetURLFilter"
p:authenticationManager-ref="radiusAuthenticationManager"
p:authenticationFailureHandler-ref="radiusAuthenticationFailureHandler"
p:authenticationSuccessHandler-ref="radiusAuthenticationSuccessHandler" />
<security:http auto-config="false"
use-expressions="true"
access-denied-page="/auth/denied" entry-point-ref="authenticationEntryPoint"
disable-url-rewriting="true"
access-decision-manager-ref="accessDecisionManager">
<security:logout logout-url="/auth/logout" logout-success-url="/auth/login" />
<security:custom-filter position="FORM_LOGIN_FILTER" ref="authenticationFilter" />
</security:http>
謝謝
你所描述的是適當的方式來做到這一點,所以無論你嘗試過你做錯了什麼。如果你爲你的問題添加了一些信息(比如你的彈簧安全配置和你的登錄頁面/控制器),也許我可以幫你弄明白。 – pap 2012-08-08 12:44:35
在請求登錄頁面或提交期間發送參數嗎? – 2012-08-08 13:37:45
感謝回答pap,我添加了一些信息(這是很多,所以我嘗試了什麼是最重要的) – thevoyager 2012-08-08 13:46:53