标签: spelevaluationexception

无法验证Spring Security中的url模式角色

我使用spring security 3.1.7.RELEASE with spring 3.2.13.RELEASE.

我在spring-security.xml中输入如下:

<http auto-config="true" use-expressions="true"> 
    <intercept-url pattern=".*admin.htm" access="hasRole(ROLE_ADMIN)" />
    <intercept-url pattern="/siteadmin/*.htm" access="ROLE_ADMIN" />
    <intercept-url pattern="/siteadmin/cleancache.htm" access="hasRole('ROLE_ADMIN')" />
Run Code Online (Sandbox Code Playgroud)

当我尝试点击url /siteadmin/cleancache.htm时,我得到以下异常:

java.lang.IllegalArgumentException:无法计算表达式'ROLE_ADMIN'org.springframework.security.access.expression.ExpressionUtils.evaluateAsBoolean(ExpressionUtils.java:13)org.springframework.security.web.access.expression.WebExpressionVoter.vote(WebExpressionVoter) .java:34)org.springframework.security.web.access.expression.WebExpressionVoter.vote(WebExpressionVoter.java:18)org.springframework.security.access.vote.AffirmativeBased.decide(AffirmativeBased.java:62)

根本原因:

org.springframework.expression.spel.SpelEvaluationException:EL1008E:(pos 0):在'org.springframework.security.web.access.expression.WebSecurityExpressionRoot'类型的对象上找不到属性或字段'ROLE_ADMIN' - 可能不公开?org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:214)org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:85)org.springframework.expression.spel.ast. PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:78)org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:102)org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:98) org.springframework.security.access.expression.ExpressionUtils.evaluateAsBoolean(ExpressionUtils.java:11)​​org.springframework.security.web.access.expression.WebExpressionVoter.vote(WebExpressionVoter.java:34)

任何指针都高度赞赏.

spring spring-mvc spring-security spelevaluationexception

23
推荐指数
2
解决办法
2万
查看次数

没有参数方法的@Cacheble注释

我希望@Cacheable在没有参数的方法上有注释.在这种情况下,我使用@Cacheable如下

@Cacheable(value="usercache", key = "mykey")
public string sayHello(){
    return "test"
}
Run Code Online (Sandbox Code Playgroud)

但是,当我调用此方法时,它不会被执行,并且如下所示会出现异常

org.springframework.expression.spel.SpelEvaluationException:EL1008E:(pos 0):在'org.springframework.cache.interceptor.CacheExpressionRootObject'类型的对象上找不到属性或字段'mykey' - 可能不公开?

请建议.

spring ehcache spelevaluationexception

16
推荐指数
2
解决办法
1万
查看次数

SpelEvaluationException:EL1007E:(pos 43):在null上找不到字段或属性"group"

我为我的Web应用程序完全配置了SPRING METHOD安全性.(启用了PRE/POST注释).

但最近我遇到了一个奇怪的问题.总结如下:

  1. POJOS摘要

    // User Class
    public class User {
        int id;
        String name;
        // getters and setters
    }
    
    // Group Class
    public class Group {
        int id;
        String name;
        // getters and setters
    }
    
    // GroupMembership class
    public class GroupMembership {
        private int id;
        private User user;
        private Group group;
        // getters and setters
    }
    
    Run Code Online (Sandbox Code Playgroud)
  2. PreAuthorise过滤方法.

    @PreAuthorize("canIEditGroupProfile(#membership.group.id)")
    public int updateGroupMembership(GroupMembership membership)
        throws GroupsServiceException;
    
    Run Code Online (Sandbox Code Playgroud)

传递完全填充的GroupMembership对象(存在适当的用户和组合成)时,安全筛选器将引发以下异常:

errorMessage: "Failed to evaluate expression
    canIEditGroupProfile(#membership.group.id)'"
Run Code Online (Sandbox Code Playgroud)

在挖掘异常时:

原因是:

org.springframework.expression.spel.SpelEvaluationException:
    EL1007E:(pos 33): Field …
Run Code Online (Sandbox Code Playgroud)

java spring spring-security spring-el spelevaluationexception

8
推荐指数
1
解决办法
2万
查看次数

Jhipster-JpaRepository“ principal.username” @Query-org.springframework.expression.spel.SpelEvaluationException

在特定方法上测试我的rest控制器时出现错误。我正在使用@Query注释来进行数据库查询。它使用“ principal.username”来完成。我没有关于如何在应用程序中获取并使用principal.username的全部图片。我目前正在查看有关它的spring-security文档。但是我的问题出在测试部分,当我执行下面的测试时,由于出现错误“ Faillure” @Query

仓库:

public interface MeetingRepository extends JpaRepository<Meeting,Long> {

  @Query("select m from Meeting m where m.visibility = 'PUBLIC' OR m.user.login = ?#{principal.username}")
  List<Meeting> findOpenAndUserMeetings();

}
Run Code Online (Sandbox Code Playgroud)

休息控制器方法:

@RequestMapping(value = "/api/meetings", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Meeting>> getAll()
{
    List<Meeting> meetings = MeetingRepository.findOpenAndUserMeetings();
    return new ResponseEntity<List<Meeting>>(meetings, HttpStatus.OK);
}
Run Code Online (Sandbox Code Playgroud)

一个测试:

@Test
@Transactional
public void getAllMeetings() throws Exception {
    // Initialize the database
    MeetingRepository.saveAndFlush(Meeting);

    // Get all the Meetinges
    restMeetingMockMvc.perform(get("/api/meetings"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON));
}
Run Code Online (Sandbox Code Playgroud)

而这个错误:

getAllMeetings(com.ent.web.rest.MeetingResourceTest)  Time elapsed: …
Run Code Online (Sandbox Code Playgroud)

testing spring-security jhipster spelevaluationexception

5
推荐指数
1
解决办法
3233
查看次数

org.springframework.expression.spel.SpelEvaluationException:EL1027E :(位置4):不支持对'com.test.domain.Employee'类型的索引

我正在开发一个Spring Roo应用程序,并在列表(在list.jspx中)中显示对象时,正在获取所引用对象的所有属性。例如:

@RooJavaBean
@RooToString    
@RooJpaActiveRecord

public class Employee {    
    @NotNull
    private String empName;    
    @ManyToOne
    private Department department;
}
Run Code Online (Sandbox Code Playgroud)

和部门

@RooJavaBean    
@RooToString    
@RooJpaActiveRecord    
public class Department {    
    @NotNull
    private String deptName;

   @NotNull
   private String deptLocation;
}
Run Code Online (Sandbox Code Playgroud)

现在,在roo中构建一个Web项目,并添加部门条目和员工条目之后,我在员工列表中得到了一个难看的表。显示部门实体的所有属性,而我的意图是显示部门名称(deptName)。

试图更改list.jspx,如下所示:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<div xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:page="urn:jsptagdir:/WEB-INF/tags/form" xmlns:table="urn:jsptagdir:/WEB-INF/tags/form/fields" version="2.0">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <jsp:output omit-xml-declaration="yes"/>
    <page:list id="pl_com_test_domain_Employee" items="${employees}" z="user-managed">
        <table:table data="${employees}" id="l_com_test_domain_Employee" path="/employees" z="user-managed">
            <table:column id="c_com_test_domain_Employee_Department" property="department.deptName" z="user-managed"/>
            <table:column id="c_com_test_domain_Employee__DeptLocation" property="deptLocation" z="user-managed"/>
        </table:table>
    </page:list>
Run Code Online (Sandbox Code Playgroud)

错误:

org.springframework.expression.spel.SpelEvaluationException: EL1027E:(pos 4): Indexing into type 'com.test.domain.Employee' is not supported …
Run Code Online (Sandbox Code Playgroud)

jspx jsp-tags spring-mvc spring-roo spelevaluationexception

5
推荐指数
1
解决办法
1万
查看次数

@PreAuthorize with Bean in expression (Spring Boot)

简单的问题,我@Autowired在控制器中设置了一个 @Service 类。

试图在我的控制器中的一种方法上增加一点安全性。所以为了简单起见,我这样做是为了测试

@PreAuthorize("@myService.helloThere()")
public void someControllerMethod() {
    ...
}
Run Code Online (Sandbox Code Playgroud)

但真的没有成功。在方法调用期间出现异常。

java.lang.IllegalArgumentException:无法评估表达式“@myService.helloThere()”

我在这里遗漏了 EL 的东西吗?

更新

只需添加最后一个由异常引起的

引起:org.springframework.expression.spel.SpelEvaluationException: EL1057E:(pos 1): 没有在上下文中注册的 bean 解析器来解析对 bean 'dummyServiceImpl' 的访问

现在我不明白为什么如果我使用 @Autowired 就不能在 StandardEvaluationContext 中访问它?

更新 2

由于我在自定义GlobalMethodSecurityConfiguration扩展类中连接了自己的角色层次结构,因此默认情况下DefaultMethodSecurityExpressionHandler没有applicationContext设置。我不确定为什么这是设计使然,或者我遗漏了一些明显的东西。我搜索了参考页面并找到了另一个帮助我解决问题的SO 线程。我正在发布更新的安全配置。

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class GlobalMethodSecurityConfig extends GlobalMethodSecurityConfiguration {

    @Autowired
    ApplicationContext applicationContext; //added this

    @Override
    protected MethodSecurityExpressionHandler createExpressionHandler() {           
        final DefaultMethodSecurityExpressionHandler handler = new DefaultMethodSecurityExpressionHandler();

        handler.setApplicationContext(applicationContext); //added this
        RoleHierarchyImpl roleHierarchy = new RoleHierarchyImpl(); …
Run Code Online (Sandbox Code Playgroud)

spring spring-security spring-boot spelevaluationexception

5
推荐指数
1
解决办法
3272
查看次数

为Spring定义@Cacheable注释的键的最佳方法是什么?

如果我为没有任何参数的方法定义了一个ehcache.

但在我的用例中,我需要通过它的密钥访问我构建的缓存.

所以请为我提供更好的方法来分配密钥.

关注是我的代码:

@Override
@Cacheable(value = "cacheName", key = "cacheKey")
public List<String> getCacheMethod() throws Exception{
Run Code Online (Sandbox Code Playgroud)

PS当我尝试从其他地方访问此方法时,我收到以下错误.

org.springframework.expression.spel.SpelEvaluationException:EL1008E:(pos 0):在'org.springframework.cache.interceptor.CacheExpressionRootObject'类型的对象上找不到字段或属性'cacheKey'

java spring ehcache spelevaluationexception

4
推荐指数
2
解决办法
9838
查看次数