小编Chr*_*kis的帖子

成功登录后,Spring Security会重定向到上一页

我知道之前已经问过这个问题,但是我在这里遇到了一个特殊的问题.

我使用spring security 3.1.3.

我的Web应用程序中有3个可能的登录案例:

  1. 通过登录页面登录:好的.
  2. 通过限制页面登录:也可以.
  3. 通过非限制页面登录:不行......每个人都可以访问"产品"页面,如果用户登录,用户可以发表评论.因此,登录表单包含在同一页面中,以便允许用户连接.

案例3)的问题是我无法将用户重定向到"产品"页面.无论如何,他们会在成功登录后重定向到主页.

请注意,对于案例2),成功登录后,重定向到受限页面的工作开箱即用.

这是我的security.xml文件的相关部分:

<!-- Authentication policy for the restricted page  -->
<http use-expressions="true" auto-config="true" pattern="/restrictedPage/**">
    <form-login login-page="/login/restrictedLogin" authentication-failure-handler-ref="authenticationFailureHandler" />
    <intercept-url pattern="/**" access="isAuthenticated()" />
</http>

<!-- Authentication policy for every page -->
<http use-expressions="true" auto-config="true">
    <form-login login-page="/login" authentication-failure-handler-ref="authenticationFailureHandler" />
    <logout logout-url="/logout" logout-success-url="/" />
</http>
Run Code Online (Sandbox Code Playgroud)

我怀疑"每个页面的身份验证策略"都要对此问题负责.但是,如果我将其删除,我将无法再登录... j_spring_security_check发送404错误.


编辑:

感谢拉尔夫,我找到了解决方案.所以这就是事情:我使用了这个属性

<property name="useReferer" value="true"/>
Run Code Online (Sandbox Code Playgroud)

拉尔夫给我看了.之后我遇到了我的案例问题1):当通过登录页面登录时,用户停留在同一页面(并没有重定向到主页,就像以前一样).直到此阶段的代码如下:

<!-- Authentication policy for login page -->
<http use-expressions="true" auto-config="true" pattern="/login/**">
    <form-login login-page="/login" authentication-success-handler-ref="authenticationSuccessHandlerWithoutReferer" />
</http>

<!-- Authentication policy for every …
Run Code Online (Sandbox Code Playgroud)

redirect spring login spring-security

53
推荐指数
3
解决办法
10万
查看次数

SpringMVC,jquery,tiles和部分重新渲染

我正在尝试使用spring mvc 3.1,tiles 2和jquery对我的网站进行部分渲染.

这是我的春天:

<beans:bean class="org.springframework.js.ajax.AjaxUrlBasedViewResolver">
   <beans:property name="viewClass" value="org.springframework.js.ajax.tiles2.AjaxTilesView"/>
</beans:bean>
Run Code Online (Sandbox Code Playgroud)

我的瓷砖conf:

<definition name="productSearch" extends="baseLayout">
    <put-attribute name="mainSection">
        <definition template="/WEB-INF/views/productSearch.jsp">
            <put-attribute name="productSearchResults" value="/WEB-INF/views/productSearchResults.jsp" />
        </definition>
    </put-attribute>
</definition>
Run Code Online (Sandbox Code Playgroud)

如您所见,有一个名为"productSearchResults"的嵌套属性.这是结果页面,我希望通过ajax重新呈现此页面.

我的控制器:

@RequestMapping(params = "search=true", value = "/", method = RequestMethod.POST)
public String searchHandler(@Valid final SearchFormBean searchformBean, final Model model) {
    model.addAttribute("productsList", productsService.findProducts(searchformBean.getSearchCriteria()));
    return "productsSearch";
}
Run Code Online (Sandbox Code Playgroud)

我的jsps:

productsSearch.jsp:

<form:form id="product-search-form" method="post" modelAttribute="productSearchFormBean">
    <input type="hidden" name="search" value="" />
    <form:input path="searchCriteria.name" />
    // AND SOME OTHER FIELDS...
    <button type="submit" onclick="this.form.search.value='true';">Search</button>
</form>
Run Code Online (Sandbox Code Playgroud)

productSearchResults.jsp:

<div id="products-result">
    <div id="search-results-info" …
Run Code Online (Sandbox Code Playgroud)

ajax jquery tiles spring-mvc partial

5
推荐指数
1
解决办法
7483
查看次数

Spring MVC填充@RequestParam Map &lt;String,String&gt;

我的Spring MVC @Controller中有以下方法:

@RequestMapping(method = RequestMethod.GET)
public String testUrl(@RequestParam(value="test") Map<String, String> test) {   
    (...)
}
Run Code Online (Sandbox Code Playgroud)

我这样称呼它:

http://myUrl?test[A]=ABC&test[B]=DEF
Run Code Online (Sandbox Code Playgroud)

但是,“ test” RequestParam变量始终为null

为了填充“测试”变量,我必须做什么?

data-binding parameters spring populate spring-boot

5
推荐指数
1
解决办法
1万
查看次数

Spring MVC自定义错误和国际化

在我的Web应用程序中,我使用注释处理错误.一切正常,我可以通过"message"参数使用自定义消息.

@Digits(fraction = 0, integer = 3, message="my custom error message...")
private String price;
Run Code Online (Sandbox Code Playgroud)

现在,我正在尝试使用.properties文件将此消息国际化,但我肯定会错过一些内容而无法使其工作.

我的春天配置:

<beans:bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <beans:property name="basenames" value="classpath:i18n/messages, classpath:i18n/errors" />
    <beans:property name="defaultEncoding" value="UTF-8" />
</beans:bean>

<beans:bean name="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
    <beans:property name="validationMessageSource">
        <beans:ref bean="messageSource" />
    </beans:property>
</beans:bean>

<beans:bean id="localeResolver" class="org.springframework.web.servlet.i18n.FixedLocaleResolver">
    <beans:property name="defaultLocale" value="fr" />
</beans:bean>
Run Code Online (Sandbox Code Playgroud)

我的新豆子:

@Digits(fraction = 0, integer = 3)
private String price;
Run Code Online (Sandbox Code Playgroud)

我的"errors_fr.properties"文件.我已经尝试了一切:

Digits.myBean.myNestedBean.price = my custom error message...
Digits.myNestedBean.price = my custom error message...
javax.validation.constraints.Digits.myNestedBean.price = my custom error message...
Run Code Online (Sandbox Code Playgroud)

我总是从spring获得相同的通用消息,就像spring没有检测到我的.properties文件一样.顺便说一下,调试时可以在BindingResult对象中找到上面的消息键.

我在这里错过了什么?

请注意,我已经在我的jsp(在"messages_fr.properties"文件中)中有国际化的消息,它们工作正常.

validation spring-mvc internationalization custom-errors

1
推荐指数
1
解决办法
1万
查看次数