小编Jak*_*ski的帖子

简单地测试Spring Boot Security

我正在努力测试受Spring Security保护的URL的访问控制.

配置如下所示:

    http
            .authorizeRequests()
            .antMatchers("/api/user/**", "/user").authenticated()
            .antMatchers("/api/admin/**", "/templates/admin/**", "/admin/**").hasAuthority("ADMIN")
            .anyRequest().permitAll();
Run Code Online (Sandbox Code Playgroud)

测试类看起来像这样:

package com.kubukoz.myapp;

import com.kubukoz.myapp.config.WebSecurityConfig;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.security.web.FilterChainProxy;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import javax.transaction.Transactional;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;


@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = {MyApplication.class, WebSecurityConfig.class})
@WebAppConfiguration
@TransactionConfiguration(defaultRollback = true)
@Transactional(rollbackOn = Exception.class)
public class MyApplicationTests {

    @Autowired
    private WebApplicationContext context;
    private MockMvc mockMvc;
    @Autowired
    private FilterChainProxy filterChainProxy;

    @Before
    public void …
Run Code Online (Sandbox Code Playgroud)

java security testing spring spring-boot

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

在Scala中将功能重复N次

我想创建一个函数,该函数将返回一个函数,该函数是参数x上f的n倍的函数,即f(f(f ... f(x)...))。这是我的代码:

def repeated(f: Int => Int, n: Int) = {
   var tek: Int => Int = f

   for (i <- 0 to n) {
     tek = x => f(tek(x))
   }
   tek
}
Run Code Online (Sandbox Code Playgroud)

我知道这不是在Scala中执行此操作的正确方法,我只想了解幕后发生的事情。

调用它repeated(x => x + 1, 5)(1)会导致堆栈溢出。
我在调试器中注意到的是,重复完成后将执行for循环内的行。似乎是惰性启动,也许for循环的主体是按名称传递的lambda?

scala

3
推荐指数
2
解决办法
614
查看次数

标签 统计

java ×1

scala ×1

security ×1

spring ×1

spring-boot ×1

testing ×1