截取REST url的url模式
我正在设计一套用于访问URL的RESTAPI。根据我的要求,有两个URL:截取REST url的url模式,rest,spring-security,Rest,Spring Security,我正在设计一套用于访问URL的RESTAPI。根据我的要求,有两个URL: http://localhost:3126/securitydemo/webapi/db/students 要查看所有学生,无需访问,并且 http://localhost:3126/securitydemo/webapi/db/students/1 只允许角色用户 我的Spring安全配置: 如果我使用模式**/students/*则不会出现基本的安全弹出窗口。如果我使用/**它工作正常 如何截取两个具有不
http://localhost:3126/securitydemo/webapi/db/students
要查看所有学生,无需访问,并且
http://localhost:3126/securitydemo/webapi/db/students/1
只允许角色用户
我的Spring安全配置:
如果我使用模式**/students/*
则不会出现基本的安全弹出窗口。如果我使用/**
它工作正常
如何截取两个具有不同安全级别的URL
我的休息服务课:
@Path(“/db”)
@产生(MediaType.APPLICATION_JSON)
公共班级学生服务{
静态StudentDao data=newstudentdaoimpl();
@路径(“/学生”)
@得到
公众回应(学生){
GenericeEntity实体=新的GenericeEntity(data.getAllStudents()){};
返回Response.ok(entity.build();
}
@路径(“/students/{id}”)
@得到
公共响应getStudent(@PathParam(“id”)int-id){
返回Response.ok(data.getStudent(id)).build();
}
}
试试这个
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/securitydemo/webapi/db/students/1/**" access="hasRole('ROLE_USER')" />
<http-basic/>
</http>
/Students/1这里1是一个路径变量,它没有被修复。您不能使用spring security尝试方法级别的注释@PreAuthorize(“permitAll()”)和@PreAuthorize(“hasRole('ROLE_USER')”)。您的可能副本缺少一个/
。试试/**/students/*
。