Я борюсь со своей конфигурацией Spring Security, которую я до сих пор не смог заставить работать. нужна твоя помощь.
Это моя конфигурация:
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class MethodSecurityConfig extends GlobalMethodSecurityConfiguration {
@Override
protected MethodSecurityExpressionHandler createExpressionHandler() {
DefaultMethodSecurityExpressionHandler expressionHandler =
new DefaultMethodSecurityExpressionHandler();
expressionHandler.setPermissionEvaluator(new CustomPermissionEvaluator());
return expressionHandler;
}
}
Это CustomPermissionEvaluator
:
public class CustomPermissionEvaluator implements PermissionEvaluator {
@Override
public boolean hasPermission(Authentication auth, Object targetDomainObject, Object permission) {
return true;
}
@Override
public boolean hasPermission(Authentication auth, Serializable targetId, String targetType, Object permission) {
return true;
}
}
Это контроллер:
@PreAuthorize("hasPermission(#test, 'write')")
@PostMapping("/test")
public Result saveTest(@RequestBody Test test) {
return Result.build();
}
Все выглядит хорошо и просто, но когда я запрашиваю остальные API, получаю следующее исключение:
.m.m.a.ExceptionHandlerExceptionResolver : Resolved exception caused by Handler execution: org.springframework.security.authentication.AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext
Кто-нибудь может дать мне подсказку, что делать? Благодаря ~