它向我抛出 500 Failed tovaluate expression 'ROLE_USER' in spring security

2023-12-09

SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/SecuritySpring] threw exception
java.lang.IllegalArgumentException: Failed to evaluate expression 'ROLE_USER'
    at org.springframework.security.access.expression.ExpressionUtils.evaluateAsBoolean(ExpressionUtils.java:14)
    at org.springframework.security.web.access.expression.WebExpressionVoter.vote(WebExpressionVoter.java:36)
    at org.springframework.security.web.access.expression.WebExpressionVoter.vote(WebExpressionVoter.java:18)
    at org.springframework.security.access.vote.AffirmativeBased.decide(AffirmativeBased.java:62)
    at org.springframework.security.access.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:232)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:123)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:90)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:122)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:168)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:48)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilterInternal(BasicAuthenticationFilter.java:158)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter.doFilter(DefaultLoginPageGeneratingFilter.java:162)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:205)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:120)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:96)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:53)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:91)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:213)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:176)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2430)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2419)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'ROLE_USER' cannot be found on object of type 'org.springframework.security.web.access.expression.WebSecurityExpressionRoot'
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:217)
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:85)
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:78)
    at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:113)
    at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:105)
    at org.springframework.security.access.expression.ExpressionUtils.evaluateAsBoolean(ExpressionUtils.java:11)
    ... 58 more

spring-security.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->


    <beans:beans xmlns="http://www.springframework.org/schema/security"
        xmlns:beans="http://www.springframework.org/schema/beans" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security-4.0.xsd">

        <http auto-config="true">
            <intercept-url pattern="/admin**" access="ROLE_USER" />
        </http>

        <authentication-manager>
          <authentication-provider>
            <user-service>
            <user name="mkyong" password="123456" authorities="ROLE_USER" />
            </user-service>
          </authentication-provider>
        </authentication-manager>

    </beans:beans>

我正在使用弹簧安全..

我有两页 1) 欢迎 - 访问所有 2) 管理员 - 仅由管理员访问

当我尝试访问管理页面时,它抛出 500 错误。

我该如何解决该错误?

(是否需要附上任何文件?)


如果您正在使用弹簧安全4.0你应该使用hasRole('ROLE_ADMIN')。并且还使用"use-expressions=true"

所以改为

<http auto-config="true" use-expressions="true">
    <intercept-url pattern="/admin**" access="hasRole('ROLE_ADMIN')" />
</http>

它会很好地解决这个问题。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

它向我抛出 500 Failed tovaluate expression 'ROLE_USER' in spring security 的相关文章

  • HSQL - 识别打开连接的数量

    我正在使用嵌入式 HSQL 数据库服务器 有什么方法可以识别活动打开连接的数量吗 Yes SELECT COUNT FROM INFORMATION SCHEMA SYSTEM SESSIONS
  • jQuery AJAX 调用 Java 方法

    使用 jQuery AJAX 我们可以调用特定的 JAVA 方法 例如从 Action 类 该 Java 方法返回的数据将用于填充一些 HTML 代码 请告诉我是否可以使用 jQuery 轻松完成此操作 就像在 DWR 中一样 此外 对于
  • 来自 dll 的 Java 调用函数

    我有这个 python 脚本导入zkemkeeperdll 并连接到考勤设备 ZKTeco 这是我正在使用的脚本 from win32com client import Dispatch zk Dispatch zkemkeeper ZKE
  • java.lang.IllegalStateException:应用程序 PagerAdapter 更改了适配器的内容,而没有调用 PagerAdapter#notifyDataSetChanged android

    我正在尝试使用静态类将值传递给视图 而不是使用意图 因为我必须传递大量数据 有时我会收到此错误 但无法找出主要原因是什么 Error java lang IllegalStateException The application s Pag
  • 没有 Spring 的自定义 Prometheus 指标

    我需要为 Web 应用程序提供自定义指标 问题是我不能使用 Spring 但我必须使用 jax rs 端点 要求非常简单 想象一下 您有一个包含键值对的映射 其中键是指标名称 值是一个简单的整数 它是一个计数器 代码会是这样的 public
  • 内部类的构造函数引用在运行时失败并出现VerifyError

    我正在使用 lambda 为内部类构造函数创建供应商ctx gt new SpectatorSwitcher ctx IntelliJ建议我将其更改为SpectatorSwitcher new反而 SpectatorSwitcher 是我正
  • Spring Boot Data JPA 从存储过程接收多个输出参数

    我尝试通过 Spring Boot Data JPA v2 2 6 调用具有多个输出参数的存储过程 但收到错误 DEBUG http nio 8080 exec 1 org hibernate engine jdbc spi SqlStat
  • tomcat 中受密码保护的应用程序

    我正在使用 JSP Servlet 开发一个Web应用程序 并且我使用了Tomcat 7 0 33 as a web container 所以我的要求是tomcat中的每个应用程序都会password像受保护的manager applica
  • 使用 AsyncTask 传递值

    我一直在努力解决这个问题 但我已经到了不知道该怎么办的地步 我想做的是使用一个类下载文件并将其解析为字符串 然后将该字符串发送到另一个类来解析 JSON 内容 所有部件都可以单独工作 并且我已经单独测试了所有部件 我只是不知道如何将值发送到
  • 不接受任何内容也不返回任何内容的函数接口[重复]

    这个问题在这里已经有答案了 JDK中是否有一个标准的函数式接口 不接受也不返回任何内容 我找不到一个 像下面这样 FunctionalInterface interface Action void execute 可运行怎么样 Functi
  • java.io.Serialized 在 C/C++ 中的等价物是什么?

    C C 的等价物是什么java io Serialized https docs oracle com javase 7 docs api java io Serializable html 有对序列化库的引用 用 C 序列化数据结构 ht
  • Android:无法使用 DbHelper 和 Contract 类将数据插入 SQLite

    public class Main2Activity extends AppCompatActivity private EditText editText1 editText2 editText3 editText4 private Bu
  • 我如何在java中读取二进制数据文件

    因此 我正在为学校做一个项目 我需要读取二进制数据文件并使用它来生成角色的统计数据 例如力量和智慧 它的设置是让前 8 位组成一个统计数据 我想知道执行此操作的实际语法是什么 是不是就像读文本文件一样 这样 File file new Fi
  • 干净构建 Java 命令行

    我正在使用命令行编译使用 eclipse 编写的项目 如下所示 javac file java 然后运行 java file args here 我将如何运行干净的构建或编译 每当我重新编译时 除非删除所有内容 否则更改不会受到影响 cla
  • 使用反射覆盖最终静态字段是否有限制?

    在我的一些单元测试中 我在最终静态字段上的反射中遇到了奇怪的行为 下面是说明我的问题的示例 我有一个基本的 Singleton 类 其中包含一个 Integer public class BasicHolder private static
  • 在java中为组合框分配键

    我想添加一个JComboBox在 Swing 中这很简单 但我想为组合中的每个项目分配值 我有以下代码 JComboBox jc1 new JComboBox jc1 addItem a jc1 addItem b jc1 addItem
  • 长轮询会冻结浏览器并阻止其他 ajax 请求

    我正在尝试在我的中实现长轮询Spring MVC Web 应用程序 http static springsource org spring docs 2 0 x reference mvc html但在 4 5 个连续 AJAX 请求后它会
  • 如果没有抽象成员,基类是否应该标记为抽象?

    如果一个类没有抽象成员 可以将其标记为抽象吗 即使没有实际理由直接实例化它 除了单元测试 是的 将不应该实例化的基类显式标记为抽象是合理且有益的 即使在没有抽象方法的情况下也是如此 它强制执行通用准则来使非叶类抽象 它阻止其他程序员创建该类
  • 双枢轴快速排序和快速排序有什么区别?

    我以前从未见过双枢轴快速排序 是快速排序的升级版吗 双枢轴快速排序和快速排序有什么区别 我在 Java 文档中找到了这个 排序算法是双枢轴快速排序 作者 弗拉基米尔 雅罗斯拉夫斯基 乔恩 本特利和约书亚 布洛赫 这个算法 在许多数据集上提供
  • Java中super关键字的范围和使用

    为什么无法使用 super 关键字访问父类变量 使用以下代码 输出为 feline cougar c c class Feline public String type f public Feline System out print fe

随机推荐

  • 对组合框中的项目进行分组

    我有一个 ListView 其中包含两种类型的对象 单个对象和多个对象 单个是普通的 TextBlock 而多个是包含项目的 ComboBox 我试图对组合框中的项目进行分组 但没有成功 是否可以 或者我应该采取不同的方法 我想要实现的目标
  • Python 3.5 + PyQt5 到独立 exe

    我是编码新手 我需要将 py 文件转换为 exe 我尝试了 py2exe 但它不适用于 python 3 5 然后我尝试了pyinstaller 它起作用了 但是当我将PyQt5添加到程序中时 pyinstaller也失败了 我尝试了 nu
  • Ipython Notebook 和 Matplotlib:如何在 html div 中包装绘图?

    我想添加一些css到我的情节的一部分 具体来说 我想设置float left 我怎样才能在div中生成绘图 这样我就可以使用css控制它的布局 例如 对于代码 def simple plot ax None if ax is None fi
  • 用于多行标题的 JTable 标题文本换行(自定义 TableCellRenderer)

    如何获取多行 JTable 标题 其中标题列正确放大以适合某些文本 然后换行到新行 如下所示 目前搜索上述需求返回了很多解决方案 但没有一个真正解决问题 http www javarichclient com multiline colum
  • 为什么我要在 C 中按值传递函数参数?

    我正在通过我的一些 C 库来磨练我的 C 技能 在完成第一个工作实现之后 我现在正在检查代码以使其更加高效 目前我正在讨论通过引用或值传递函数参数的主题 我的问题是 为什么我要在 C 中按值传递任何函数参数 代码可能看起来更干净 但它不是总
  • Visual Studio 的 Eclipse 按键绑定

    有人有类似 VS 2005 的可用于 Eclipse 的键绑定方案吗 如何将其导入 Eclipse 的首选项 我只看到导出按钮 如何在 Eclipse 中安装 Visual Studio 键绑定 Helios 及以上版本 对于找到这篇文章的
  • 由于 ExtensionlessUrlHandler,WebAPI 重写规则失败

    我正在尝试使用 IIS 将请求从 ASP net MVC 4 应用程序重写到 ASP net MVC 4 WebApi 从客户端 我使用 ajax 回调服务器 然后我希望服务器重写请求以指向 webapi 站点 如果我能让它工作 这应该可以
  • Java中的同步方法和同步块有什么区别? [复制]

    这个问题在这里已经有答案了 Java 中的同步方法和同步块有什么区别 我一直在网上寻找答案 人们似乎对此很不确定 我的看法是 两者之间没有区别 除了同步块的范围可能更本地化 因此锁定的时间会更短 如果对静态方法加锁 那么加锁的对象是什么 类
  • Java 转换/类加载器问题

    这是问题的简化版本 SomeClass c SomeClass obj getSomeClassParent 并非总是如此 但有时会触发异常 org somepackage SomeClass can t be cast to org so
  • 在已编译的 Java 类中重写方法调用

    我想在解析编译的类文件时将对给定类的调用替换为对方法体内另一个类的调用 或者换句话说 是否有一种方法可以检测方法中给定类的使用情况 并使用类似的方法替换该方法的该部分javassist 例如 如果我有编译版本 class A public
  • Django loaddata 如何知道哪些字段构成自然键?

    我使用 Django 的 dumpdata 来保存数据并使用 loaddata 来重新加载它 我也在使用自然键 我的模型看起来与此类似 class LinkManager models Manager def get by natural
  • jQuery - Raphael - SVG - 基于自定义数据的选择器

    我已将自定义数据属性分配给添加到 Raphael 画布的一些圆圈 如下所示each loop marker data transaction transaction 如何在画布上找到具有相同交易数据值的元素 目前我有代码 var found
  • 如何在Python中实现接口?

    public interface IInterface void show public class MyClass IInterface region IInterface Members public void show Console
  • 为什么这个 constexpr 静态成员函数在调用时不被视为 constexpr? [复制]

    这个问题在这里已经有答案了 为什么是这样constexpr static成员函数 由 Nah评论 不被视为constexpr什么时候打电话 struct Item id enum Enum size position attributes
  • 树 - 拖放节点 - 刷新?

    我有一个与 smartgwt 树结构相关的问题 我正在创建一棵树 称为nodesTree 具有来自数据库的值 并且每个节点都设置了一个名称 例如 我有 4 个节点 数字是节点的名称 1 2 3 4 for TreeNode node nod
  • 在 PHP 中包含文件时注释会产生影响吗? [复制]

    这个问题在这里已经有答案了 可能的重复 评论解释的代码和性能 当您在 PHP 中包含文件时include 或者任何其他函数 其性能是否受到包含文件的注释量的影响 我并不是说我要牺牲易读性 不 解析文件所需的时间节省是无法衡量的 太小 根本不
  • 正则表达式用原始字符替换“转义”字符

    NOTE 我不会使用正则表达式解析大量 html 或通用 html 我知道那很糟糕 TL DR 我有像这样的字符串 A sentence with an exclamation Next is a character 原始标记中存在 转义
  • 当“function”是中缀运算符时,如何在包内使用“package::function()”?

    根据 H Wickham 的书R 包在 包元数据 一章中 关于如何添加包依赖项 Hadley 指出了使用语法显式引用外部函数的充分理由package function 在此处添加包依赖项可确保安装它 但是 这并不意味着它将与您的包 即库 x
  • 提取 MSER 检测到的区域(Python、OpenCV)

    我无法在此图像中通过 MSER 提取检测到的区域 我想做的是拯救绿色边界区域 我的实际代码是这样的 import cv2 import numpy as np mser cv2 MSER create img cv2 imread C Us
  • 它向我抛出 500 Failed tovaluate expression 'ROLE_USER' in spring security

    SEVERE Servlet service for servlet dispatcher in context with path SecuritySpring threw exception java lang IllegalArgum