【发布时间】:2017-10-02 01:57:27
【问题描述】:
我正在设计一组用于访问 URL 的 REST API。根据我的要求,有两个网址:
http://localhost:3126/securitydemo/webapi/db/students
查看所有学生无需访问和
http://localhost:3126/securitydemo/webapi/db/students/1
只允许ROLE_USER。
我的 Spring Security 配置:
<http auto-config="true" use-expressions="true">
<intercept-url pattern="**/students/*" access="hasRole('ROLE_USER')" />
<http-basic/>
</http>
如果我使用**/students/* 模式,则不会出现基本的安全弹出窗口。如果我使用/**,它就可以正常工作。
如何拦截两个不同安全级别的网址?
我的 REST 服务类:
@Path("/db")
@Produces(MediaType.APPLICATION_JSON)
public class StudentService {
static StudentDao data = new StudentDaoImpl();
@Path("/students")
@GET
public Response getStudents(){
GenericEntity<List<Student>> entity = new GenericEntity<List<Student>>(data.getAllStudents()){};
return Response.ok(entity).build();
}
@Path("/students/{id}")
@GET
public Response getStudent(@PathParam("id") int id){
return Response.ok(data.getStudent(id)).build();
}
}
【问题讨论】:
-
您缺少
/。试试/**/students/*。
标签: rest spring-security