I implemented Spring Security Expression in my Spring controller application:
@Controller @RequestMapping("init") public class InitController { @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/", method = RequestMethod.GET) public @ResponseBody String home(){ return "This is the init page"; } }
With this security configuration:
<http auto-config="true" create-session="stateless" use-expressions="true"> <intercept-url pattern="/_ah*" access="permitAll" /> <intercept-url pattern="/init/*" access="hasRole('ROLE_ADMIN')"/> <intercept-url pattern="/init*" access="hasRole('ROLE_ADMIN')"/> </http>
When accessing this resource, the Spring default login form is displayed ( http://localhost:8888/spring_security_login ), but I do not want this to happen, and I just want the credentials to be inserted into the request header, for example, x-authorization-key "or whatever matches the script.
What is the possible solution for this?
- Is it good to have an x-authorization key in the request.
- If so, how does this relate to Springβs security mechanism, that is, how does it fit with the expression "hasRole"
- It is important that my web service is stateless, and each request receives authentication.
- Finally, how to handle Spring security without having to deal with the Spring login form
heading
source share