使用@PreAuthorize自定义bean

时间:2017-08-01 13:09:09

标签: java spring spring-security

我有方法:

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
public class MyTest {

    private MockMvc mockMvc;

    @Autowired
    private MyController myController;

    @Before
    public void setUp() {
        mockMvc = MockMvcBuilders
                    .standaloneSetup(myController)
                    .apply(SecurityMockMvcConfigurers.springSecurity())
                    .build();
    }

    @Test
    public void test() {
          // Here some code with mvc mock
    }

    @Configuration
    @EnableWebSecurity
    @EnableGlobalMethodSecurity(prePostEnabled = true)
    static class Config {
        @Bean
        MyController myController() {
            return new MyController();
        }
    }
}

它没有问题,但我无法测试它,因为得到错误:

  

org.springframework.web.util.NestedServletException:Request   处理失败;嵌套异常是   java.lang.IllegalArgumentException:无法计算表达式   ' @ securityManager.check(#uuid)'

我的测试班:

{{1}}

我想念什么?

1 个答案:

答案 0 :(得分:0)

问题与指定陈述" uuid"在PreAuthorize方法中。 它应该改写为

@PreAuthorize("@securityManager.check(#submissionId)")