1 回答

TA贡献1871条经验 获得超8个赞
您可以在PreAuthorize表达式中引用 bean 。首先这个bean/组件:
@Component("authorityChecker")
public class AuthorityChecker {
public boolean canShowSuppliers(Authentication authentication) {
for (Authority authority : authentication.getAuthorites()) {
Role role = (Role)authority; // may want to check type before to avoid ClassCastException
if (role.isShowSuppliers()) {
return true;
}
}
return false;
}
}
对此的注释将是:
@PreAuthorize("@authorityChecker.canShowSuppliers(authentication)")
public Page<Supplier> getSuppliers();
它将当前用户的 Authentication 对象传递给上面的 bean/component。
添加回答
举报