我有一个我的web应用程序的一部分,它是一个RESTfull api,并且是更标准的web页面的一部分。Spring Security多个filterChainProxy映射/过滤器,自定义过滤器Json输出
我希望有一些自定义过滤器,如入口点,SuccessHandler和FailureHandler剩余部分。这部分位于/ rest/**映射中。
在另一方面,其他的一切都需要有更多的共同的过滤器和映射与/ **。
的问题是要找到一种简单的方法有不同的对应过滤器定义的FilterChainProxy。
眼下这个解决方案不起作用:
<!-- Normal web app -->
<http auto-config="true" use-expressions="true" authentication-manager-ref="authenticationManager">
<form-login/>
<logout/>
<intercept-url pattern="/**" access="hasRole('ROLE_USER')" />
</http>
<!-- Configure RESTfull services -->
<http use-expressions="true" authentication-manager-ref="authenticationManager" entry-point-ref="restAuthenticationEntryPoint" >
<form-login authentication-success-handler-ref="restAuthenticationSuccessHandler" login-page="/rest/login" username-parameter="username" password-parameter="password" />
<logout logout-url="/rest/logout" />
<intercept-url pattern="/rest/**" method="GET" access="hasRole('ROLE_USER')" />
<intercept-url pattern="/rest/**" method="POST" access="hasRole('ROLE_ADMIN')" />
<intercept-url pattern="/rest/**" method="PUT" access="hasRole('ROLE_ADMIN')" />
<intercept-url pattern="/rest/**" method="DELETE" access="hasRole('ROLE_ADMIN')" />
</http>
它抱怨附:univseral比赛是先于其他模式。
有没有一种方法来定义这样的事情,而不诉诸与定义界定的FilterChainProxy? http版本的确帮助了很多,以减少配置的数量,因为我将不得不手动设置一个UsernamePasswordAuthenticationFilter等。
下一个问题更简单:我必须在使用表单登录身份验证JSON对象。
到目前为止,我已经实现了SuccessHandler(实际上是一个版本SimpleUrlAuthenticationSuccessHandler没有重定向的部分)。
如何编写我的JSON输出?
我必须有这样的事情:
HTTP 200 OK
有:
{"success":true,"customer {"email":"[email protected]","session_id":"b83a41dfaca6785399f00837888886e646ff9088"}}
,并与FailureHandler类似的事情。它一定很简单,它肯定是一些非常基本的东西,但你怎么做?重定向到自定义控制器不是解决方案,因为我将拥有301重定向状态,这是一个非常简单的REST客户端可能无法理解的状态。
至少,我希望只有http头和没有身体。
谢谢!
将2个driffrent接口(WWW和REST)放在一个ApplicationContext中的原因是什么?两者之间是否有一些背景/会话共享?是否登录到WWW也意味着登录到REST?如果是这样,那么为什么分开登录操作?如果不是,那为什么把它们放在一起?难道这些不是单独的应用程序为单个底层服务层提供不同的接口吗? – Roadrunner 2011-12-29 19:50:46
这就像在正常的Web应用程序内部有一个REST部分。我不想要另一个身份验证过程,我只想要其他过滤器。 REST部分只是在没有身份验证时显示错误,但另一方面,在网页上我必须将用户重定向到登录页面。 – adreide 2011-12-30 07:35:50