我实际上已经坚持了一段时间,现在不知道如何更进一步。我想拥有多个标签,但据我了解,这在同一个 http 块中是不可能的。这样做的原因是我希望 authentication-failure-url 指向登录尝试来自的页面(并且在成功尝试时还将用户重定向回该站点)。
我有一个文件 header.jsp,其中有我的登录表单。而且我希望将来在我的所有页面上都包含它,以使用户能够从所有页面登录而不会被重定向。
我该怎么做呢?
我的大部分代码都取自 spring 示例。(安全+社交+注册示例)这是我的security.xml的重要部分(没有任何尝试实现这一点)
<http pattern="/resources/**" security="none" />
<http pattern="/project/" security="none" />
<http use-expressions="true">
<!-- Authentication policy -->
<form-login login-page="/signin" login-processing-url="/signin/authenticate" authentication-failure-url="/signin?error=bad_credentials" />
<logout logout-url="/signout" delete-cookies="JSESSIONID" />
<intercept-url pattern="/addcourse" access="isAuthenticated()" />
<!--<intercept-url pattern="/**" access="isAuthenticated()" />-->
</http>
据我了解,我可以使用多个 HTTP 块?像这样的东西:
<!-- Login place 1, sign in page -->
<http pattern="/signin" use-expressions="true">
<form-login login-page="/signin" login-processing-url="/signin/authenticate" authentication-failure-url="/signin?error=bad_credentials" />
<intercept-url pattern="/addcourse" access="isAuthenticated()" />
<logout logout-url="/signout" delete-cookies="JSESSIONID" />
</http>
<!--Login place 2, start page -->
<http pattern="/" use-expressions="true">
<form-login login-page="/" login-processing-url="/signin/authenticate" authentication-failure-url="/?error=bad_credentials" />
<logout logout-url="/signout" delete-cookies="JSESSIONID" />
</http>
这给了我
Sep 26, 2013 11:57:43 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'providerSignInController' defined in class path resource [com/courseportal/project/config/SocialConfig.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.security.web.savedrequest.RequestCache]: : No qualifying bean of type [org.springframework.security.web.savedrequest.RequestCache] is defined: expected single matching bean but found 2: org.springframework.security.web.savedrequest.HttpSessionRequestCache#0,org.springframework.security.web.savedrequest.HttpSessionRequestCache#1; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.security.web.savedrequest.RequestCache] is defined: expected single matching bean but found 2: org.springframework.security.web.savedrequest.HttpSessionRequestCache#0,org.springframework.security.web.savedrequest.HttpSessionRequestCache#1
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:730)
另一种尝试是在 security.xml 中创建一个过滤器,以正确路由流量。我不确定如何做到这一点。
我希望有人可以帮助我,并说什么方法是合适的。
最好的问候,尼尔西