小编Tho*_*mas的帖子

为什么我不能使用Set:union()而不是Set.union?

我正在学习Lua,我宁愿使用冒号(:)方法.不幸的是,它无处不在.看我的代码:

Set= {}
local mt= {}
function Set:new(m)
    local set= {}
    setmetatable(set,mt)
    for a,b in pairs (m) do
        set[b]=true
    end
    return set
end

function Set.union(a,b)
    local res=Set:new ({})
    for k in pairs (a) do res[k]=true end
    for k in pairs (b) do res[k]=true end
    return res
end
mt.__add=Set.union   -- why Set:union() is not working here ?

s1=Set:new {22,55,77}
s2=Set:new {2,5,3}
s3=s1+s2

我怎样才能Set:union()在上述地方使用或者不能在这里使用?

lua call operation

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

如何在 @WebMvcTest 中模拟自定义 JWT 声明

我正在使用 Spring Boot 2.2.0.RELEASE,我的基于 Spring 的后端充当 OAuth2 资源服务器,在生产中运行良好。

我的所有 REST 端点都受到保护:

public class BookingController {
 @PreAuthorize("hasAuthority('booking:WRITE')")
 @PostMapping(value = "/book")
 public ResponseEntity<Void> createBooking(@RequestBody BookModel bookModel, JwtAuthenticationToken jwt) {..}
Run Code Online (Sandbox Code Playgroud)

我想针对 REST API 编写一个单元测试,并且想模拟 JWT 令牌。

我尝试了以下操作,但总是收到“访问被拒绝的消息”

我的单元测试如下所示:

    @WebMvcTest(controllers = BookingController.class)
    public class BookingControllerTests {

     @Autowired
     private ObjectMapper objectMapper;

     @Autowired
     MockMvc mockMvc;

     @MockBean
     JwtDecoder jwtDecoder;

     @Test
     public void when_valid_booking_then_return_200() {
       BookModel bookModel = new BookModel();
       mockMvc
            .perform(post("/book")
            .with(jwt(jwt ->jwt().authorities(new SimpleGrantedAuthority("booking:WRITE"))))
            .contentType("application/json")
            .content(objectMapper.writeValueAsBytes(bookModel)))
            .andExpect(status().isCreated());
     }
Run Code Online (Sandbox Code Playgroud)

不知何故,mockMvc 中定义的声明被忽略。查看调试输出:

PrePostAnnotationSecurityMetadataSource : @org.springframework.security.access.prepost.PreAuthorize(value=hasAuthority('booking:WRITE')) found on specific method: …
Run Code Online (Sandbox Code Playgroud)

spring-security spring-boot

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

GWT-Button充当超链接

我正在尝试创建一个"打开"按钮,它将打开一个新网站.

不幸的是,我不明白如何创建一个打开新网站的活动.如何将Hyperlink小部件注册到此ClickEvent:

 Button button = new Button("Open");
 button.addClickHandler(new ClickHandler() {
  public void onClick(ClickEvent event) {  
          Hyperlink widget = new Hyperlink("Home Page", "Home");

             }
 });
 rootPanel.add(button, 568, 275);
Run Code Online (Sandbox Code Playgroud)

提前致谢 !

gwt

3
推荐指数
1
解决办法
9519
查看次数

标签 统计

call ×1

gwt ×1

lua ×1

operation ×1

spring-boot ×1

spring-security ×1