I found many similar questions but none has solved my problem my problem is: PreAuthorize("isAuthenticated()") not working on my RestController.
my configuration security is:
<global-method-security pre-post-annotations="enabled"/>
<authentication-manager alias="authenticationManager">
<authentication-provider>
<password-encoder ref="passwordEncoder" />
<jdbc-user-service
data-source-ref="dataSource"
users-by-username-query="
select login,password,1
from test tst where tst.login=?"
authorities-by-username-query="
select login,'ROLE_SAVE' from test tst where tst.login=?"
/>
</authentication-provider>
</authentication-manager>
on my RestController i add this annotation:@PreAuthorize("isAuthenticated()")
@RestController
@PreAuthorize("isAuthenticated()")
@RequestMapping("/api/test")
public class PrinterController{
@RequestMapping(value = "", method = RequestMethod.GET)
public ResponseStatus test() {
System.out.println("test");
}
but not work any user can consume this resource.