- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我可以在注释上使用 @PreAuthorize
吗?
在 Spring 中,我可以在注释中使用像 Component
和 DependsOn
这样的注释,如下所示:
@Target(ElementType.TYPE)
@Component
@DependsOn(CoreInitializerConfig.ROLE_INITIALIZER_ID)
public @interface WebComponent
{
}
而且效果很好。但是当我尝试以同样的方式使用 PreAuthorize
时:
@Target(
{
ElementType.TYPE, ElementType.METHOD
})
@Component
@PreAuthorize("hasAuthority('PERM_READ_SETTINGS')")
public @interface SettingsAuthorized
{
}
不工作,我在 MVC Controller pojo 和 Bean 的方法中尝试过但没有工作,我必须明确指出:
@Controller
@PreAuthorize("hasAuthority('PERM_READ_SETTINGS')")
public class SettingsController
{
...
}
最佳答案
我通过添加 @Retention(RetentionPolicy.RUNTIME)
解决了这个问题还建议在最后的注解中加上@Documented
和@Inherited
,所以结果是:
@Target(
{
ElementType.TYPE, ElementType.METHOD
})
@Component
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
@PreAuthorize("hasAuthority('PERM_READ_SETTINGS')")
public @interface SettingsAuthorized
{
}
关于java - 我可以在自己的注释上使用 Spring Security @PreAuthorize 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31388677/
关闭。这个问题需要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')") 我的
我是一名优秀的程序员,十分优秀!