![](/img/trans.png)
[英]Spring security : Access denied handler doesn't work (xml config + preauthorize annotation on controller method)
[英]PreAuthorize annotation doesn't work with jersey
我正在嘗試使用Spring安全注釋來保護jersey服務,但沒有任何運氣。
我已將本節添加到web.xml:
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.test.proj.ui.web.rest;com.fasterxml.jackson.jaxrs</param-value>
</init-param>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.test.commons.ui.web.jersey.RestApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
還在applicationContext上使用此功能啟用了后期注釋:
<global-method-security secured-annotations="enabled" pre-post-annotations="enabled" />
這是我的服務類別:
@Component
@Path("/user/{uid: .*}")
public class UserResource {
@GET
@Produces(MediaType.APPLICATION_JSON)
@PreAuthorize("hasRole('ROLE_MANAGE_USER')")
public Response getUserDetail(@PathParam("uid") String uid) {
return "Hi, this is a test";
}
}
Spring Security在身份驗證中效果很好,但是授權無法按預期工作,並且會忽略PreAuthorize批注,而不會出現任何錯誤或日志。
我正在使用Spring 3.2.4,Spring Security 3.2.1和Jersy 2.6。
任何想法?
謝謝
我們面臨着完全相同的問題。 在業務層上,@ PreAuthorize注釋有效,但在REST資源上無效。 這種情況的副作用是Spring bean注入也不起作用。 一切都沒有任何錯誤。
100%可行的解決方案是使用RESTEasy代替Jersey。 它們非常相似,因此工作量不大。
彈簧組件掃描未正確配置! 要解決該問題,只需正確添加組件掃描即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.