I have a question about Spring Security. I have several pages - A, B and C - and 4 http methods to manipulate them: GET, PUT, POST, DELETE. For each combination A+GET I would like to have a special authority in form resource-Page-Method
. How can I implement it? The follewing code doesn't work: it allows all the things for all the users event if they do not have any rights.
@Override
protected void configure(HttpSecurity http) throws Exception {
RequestHeaderAuthenticationFilter siteMinderFilter = new RequestHeaderAuthenticationFilter();
siteMinderFilter.setPrincipalRequestHeader("SM_USER");
siteMinderFilter.setAuthenticationManager(authenticationManager());
http.addFilter(siteMinderFilter);
List<HttpMethod> methods = new ArrayList<HttpMethod>();
methods.add(HttpMethod.GET);
methods.add(HttpMethod.POST);
methods.add(HttpMethod.PUT);
methods.add(HttpMethod.DELETE);
List<String> resources = new ArrayList<String>();
resources.add("A");
resources.add("B");
resources.add("C");
ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry = http.authorizeRequests();
for (HttpMethod method:methods){
for (String resource: resources){
String auth = "resource-"+resource+"-"+method.name();
registry.antMatchers(method, "**/"+resource+"/**")
.hasAuthority(auth);
}
}
http = registry.and();
http.formLogin();
}