- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我的安全配置类(继承自WebSecurityConfigurerAdapter
)具有如下方法。
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/restaurant/**").access("hasRole('ROLE_USER')")
.and()
.formLogin();
}
但是我宁愿在我的 Controller 上使用@PreAuthorize
。如果我删除该方法,则一切都需要身份验证。我的方法应该是什么样子,以便一切都可用并且访问仅由 PreAuthorize 确定?
最佳答案
正如已经指出的,使用方法级安全性来保护 Controller 方法并不常见,而是使用业务逻辑来保护方法。即使您需要根据请求属性执行授权,也应该可以通过基于 URL 的安全性和 Web 安全表达式来实现这一点。
Available expressions are defined by
WebSecurityExpressionRoot
class, an instance of which is used as the expression root object when evaluation web-access expressions. This object also directly exposed theHttpServletRequest
object under the namerequest
so you can invoke the request directly in an expression.
Here您可以找到有关何时使用基于 URL 的安全性以及何时使用方法级别安全性的更多详细信息。
关于java - 使用@PreAuthorize时的安全配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26329564/
关闭。这个问题需要details or clarity .它目前不接受答案。 想改善这个问题吗?通过 editing this post 添加详细信息并澄清问题. 4年前关闭。 Improve thi
我有以下类(class) public abstract class BaseCotroller { @RequestMapping("/m") public String m() {
我正在尝试了解 Spring Security。我使用 java-config 而不是 xml。我尝试创建一个 Controller ,然后测试 @PreAuthorize 表示法。但在我给定的代码中
更新(2012 年 4 月 17 日):结果是这样的。 根上下文.xml: 权限管理器.java package com.grsnet.qvs.auth; import com.grsnet
我们正在使用 RestController,并且我们总是在每个方法上收到警告,告诉我们 @PreAuthorize 注释中的变量无法解析: @GetMapping @PreAuthorize(
我的 Controller : @RequestMapping("/createchar") @PreAuthorize("hasRole('ROLE_USER')") public String c
在我的 spring 配置文件中我有 在我的 spring @Controller 中,我有一个 @RequestMapping,上面有一个 @PreAuthorize,如下所示: @PreAuth
我正在尝试理解一些 Spring 安全代码。我也是 Spring Security 的新手,我想我在这里缺少一些基本的东西。 我在其中一个类上有注释: @Controller @RequestMapp
我正在将 Spring Security 添加到一个 Spring 项目中。系统架构为REST,用户可以访问不同的资源。 我愿意将个人信息的访问权限授予作为此信息所有者的管理员和用户。我从简单开始:像
我有一个设置了 spring 安全性的 spring 应用程序。我已经使用@PreAuthorize(...) 注释了我的服务方法。因此网络上的每个人都需要一些特定的权限来访问这些方法,这很好。 但现
我有一个关于 Spring Security 和 Spring Caching 的问题。假设我有一个方法,并且我已经用 @PreAuthorize("condition") 和 @Cacheable(
我正在实现一个应用程序,该应用程序具有一些访问完全基于权限的方法。权限是使用 Spring 实现的。使用 添加权限@PreAuthorize 方法顶部的注释。问题是我希望在注释中有完全自定义的方法 (
SPEL 有什么技巧吗,所以我可以在 application.yml 中定义我的管理员角色,然后将它们直接加载到类似的东西中: @PreAuthorize("hasAnyRole(${my.secur
在我的test.properties文件我有一个名为 devmode 的 key 。做${devmode}里面@PreAuthorize失败。 @PreAuthorize("${devmode}")
我们正在尝试使用 Spring 的 @preAuthorize 标记来设置方法级别的安全性。一切都编译并运行良好,但限制不会发生。这是一种仅限管理员的方法,但即使是非管理员也可以访问。以下是我们如何在
SPEL 有什么技巧吗,所以我可以在 application.yml 中定义我的管理员角色,然后将它们直接加载到类似的东西中: @PreAuthorize("hasAnyRole(${my.secur
我正在使用 GWT 编写我的应用程序。我的应用程序中有两个角色(ROLE_USER 和 ROLE_ADMIN)。 ROLE_ADMIN 有权访问某些处理程序 @Service @PreAuthoriz
@PreAuthorize public void methodA() { methodB(); } @PreAuthorize public void methodB() { } 这里m
我希望为我的 REST 服务实现基于角色的安全性。我正在使用 spring-data-rest 并配置了一个 JpaRepository像这样: @Repository @RestResource(p
我正在使用 RestAssured 测试 API。 我调用的方法正在使用下一个注释: @PreAuthorize("hasAnyRole('ROLE1', 'ROLE2', 'ROLE3')") 我的
我是一名优秀的程序员,十分优秀!