Tôi có theo phương pháp trong Spring MVC và sử dụng An Xuân:Làm cách nào để mô phỏng thẻ @PreAutorize trong thử nghiệm tích hợp?
@PreAuthorize("#phoneNumber == authentication.name")
@RequestMapping(value = "/{phoneNumber}/start", method = RequestMethod.POST)
public ModelAndView startUpgrading(@PathVariable("phoneNumber") String phoneNumber,
....
}
tôi quản lý để mô phỏng xác thực một cái gì đó như thế này:
public Authentication tryToAuthenticate(String accountName, String password) {
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(accountName, password);
return authenticationManager.authenticate(token);
}
Nhưng tôi không biết làm thế nào để thiết lập sự cho phép với @ PreAutorize.
Làm cách nào để tôi có thể thiết lập ngữ cảnh thử nghiệm của mình một cách chính xác để tôi không bị truy cập bị từ chối?
org.springframework.security.access.AccessDeniedException: Access is denied
at org.springframework.security.access.vote.AffirmativeBased.decide(AffirmativeBased.java:83)
at org.springframework.security.access.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:205)
Xin lỗi hồi đáp muộn, điều này đã làm say mê! 50 điểm thưởng cho bạn. Cảm ơn bạn đã giúp đỡ ! –
@ThomasVervik ... Tôi rất vui vì câu trả lời của tôi đã giúp bạn. :) –