java - Spring安全检查用户是否可以访问提到的url

标签 java spring spring-mvc spring-security

我已经开始使用 Spring Security,但经过大量研究后,我无法找到答案:

如果我明确想要检查用户 A 是否可以访问 B 的内容。我可以使用 JSP 标签支持来检查 Spring Security - check if web url is secure / protected喜欢

<sec:authorize url="stuff/B">

但是如果我想在 Controller (java 类)中检查同样的事情怎么办。我在这里没有找到任何 Spring 功能来检查登录用户是否可以访问提到的 url(https://docs.spring.io/spring-security/site/docs/3.0.x/reference/el-access.html)

最佳答案

来自 javadoc 的提示:

to use this tag there must also be an instance of WebInvocationPrivilegeEvaluator in your application context. If you are using the namespace, one will automatically be registered. This is an instance of DefaultWebInvocationPrivilegeEvaluator,"

DefaultWebInvocationPrivilegeEvaluator 的 javadoc 中,我们可以看到一个isAllowed应该完成这项工作的方法:

// privilegeEvaluator is a WebInvocationPrivilegeEvaluator "autowired"
boolean allowed = privilegeEvaluator.isAllowed("/stuff/B", yourAuthentication);

关于java - Spring安全检查用户是否可以访问提到的url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45276701/

相关文章:

java - 等效查询的 QueryDSL 谓词

java.lang.NoClassDefFoundError : Could not initialize class org. springframework.web.servlet.tags.form.FormTag

java - 强制 Jackson 将 LocalDate 序列化为数组

java - 如何捕获 Spring/Spring Boot 2.x 的所有异常?

java - 在 spring 中通过登录用户持久化实体

java - Spring 启动: Can we have seperate thread pool for each request?

java - Spring Boot mongo审核@version问题

java - 我可以在fixedThreadPool中使用静态LOGGER对象吗?

java - 使用文本数据保存表情符号时收到错误消息

java - 通过单击菜单项来调用java中的函数