return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>Spring 6 security - cannot access #root.annotation anymore - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Spring 6 security - cannot access #root.annotation anymore - Stack Overflow

programmeradmin5浏览0评论

My goal is to create such annotation instead of standard way:

@RequiresAnyRole({"UPDATE_DATA"})
@PreAuthorize("hasAnyAuthority('UPDATE_DATA')")

If I succeed, this will open a path to creating business security annotations, which you can eventually override at a method level.

I am using Spring Boot 3.3 at this moment.

My annotation is this:

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@PreAuthorize("@securityHelper.hasAnyListedAuthority(authentication, #root.annotation.value)")
public @interface RequiresAnyRole {
    String[] value() default {};
}

But it failed with:

EL1008E: Property or field 'annotation' cannot be found on object of type '.springframework.security.access.expression.method.MethodSecurityExpressionRoot' - maybe not public or not valid?"}

GitLab Duo proposed an alternative, which failed on using this in the annotation.

@PreAuthorize("@securityHelper.hasAnyListedAuthority(authentication, T(.springframework.security.access.expression.method.MethodSecurityExpressionRoot).this.returnObject.getClass().getMethod(T(.springframework.security.access.expression.method.MethodSecurityExpressionRoot).this.filterObject).getAnnotation(T(com.barclays.spone.loans.security.annotation.RequiresAnyRole)).value())")

Is there a way to retrieve the annotation parameters and pass them to SpEL expression?

For the record:

public boolean hasAnyListedAuthority(Authentication auth, String[] authorities) {
    Set<String> userAuthorities = AuthorityUtils.authorityListToSet(auth.getAuthorities());
    return Arrays.stream(authorities)
            .anyMatch(userAuthorities::contains);
}
发布评论

评论列表(0)

  1. 暂无评论