U должен реализовать PermissionEvaluator
.
public class CustomPermissionEvaluator implements PermissionEvaluator {
public boolean hasPermission(Authentication authentication, Object target,
Object permission) {
return // you logic;
}
public boolean hasPermission(Authentication authentication, Serializable targetId,String targetType, Object permission) {
return // you logic;
}
}
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class MethodSecurityConfig extends GlobalMethodSecurityConfiguration {
@Override
protected MethodSecurityExpressionHandler createExpressionHandler() {
DefaultMethodSecurityExpressionHandler expressionHandler =
new DefaultMethodSecurityExpressionHandler();
expressionHandler.setPermissionEvaluator(new CustomPermissionEvaluator());
return expressionHandler;
}
@PreAuthorize("hasPermission(#foo, 'YOU_CUSTOM_PARAM')")
@PostMapping(value = "/pay")
public Foo create(Foo foo) {
return foo;
}