【发布时间】:2016-02-20 07:09:55
【问题描述】:
以下是我的 web.xml 文件,其中包含 Web 服务的身份验证。
<sec:authentication-manager>
<sec:authentication-provider>
<sec:user-service id="userService">
<sec:user name="admin" password="admin" authorities="admin" />
<sec:user name="report" password="report" authorities="customer" />
<sec:user name="johndoe" password="password" authorities="customer, admin" />
</sec:user-service>
</sec:authentication-provider>
</sec:authentication-manager>
<sec:http create-session="stateless" use-expressions="true" path-type="regex">
<sec:intercept-url pattern="/services.*" access="permitAll" />
<sec:intercept-url pattern="/services/fichier.*" access="hasRole('customer')" />
<sec:intercept-url pattern="/services.*" access="hasRole('admin')" />
<sec:http-basic />
</sec:http>
现在我指定了一个用户 - report,它有一个角色 - customer。该用户只能访问 fichier 下的服务。所以patter是/services/fichier.*。
下面是具体方法:-
@PreAuthorize("hasRole('customer')")
@GET
@Path("/downloadFile/{fileName}/")
public String downloadFile(@PathParam("fileName") String fileName, @QueryParam("fileId") Integer fileId)
{
return "blah blah blah"
}
现在我的网址是 - http://localhost:8080/AutoFIE2Web/services/fichier/downloadFile/ffffff.jpg?fileId=5
我使用了report 用户,这给了我访问被拒绝的异常,但它确实适用于其他两个用户 - admin、johndoe。
此身份验证有什么问题?
谢谢
【问题讨论】:
-
试着用
@PreAuthorize("hasAuthority('customer')")替换@PreAuthorize("hasRole('customer')") -
然后尝试将
<sec:intercept-url pattern="/services.*" access="hasRole('admin')" />行移到<sec:intercept-url pattern="/services.*" access="hasRole('admin')" />行上方
标签: java web-services jax-rs restful-authentication