我想在Spring工具的帮助下配置Spring Securita for API。
我所有的拳头都是Spring安全配置类:
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter{
private Logger log = Logger.getLogger(SecurityConfiguration.class);
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
//...gets all the users from DB with their authorities
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("**/Observation/**").hasAuthority("apiAllowed");
}
}
然后我使用以下控制器。用户名应作为页面标题传输:
@Controller
@RequestMapping("/resource")
public class ObservationController {
private static Logger log = Logger.getLogger(ObservationController.class);
@RequestMapping(value="/Observation/{id}", method=RequestMethod.GET, produces={"text/html", "application/json", "application/ld+json"})
public @ResponseBody Observation<?> getObservation(@PathVariable long id) {
return getObservation(id);
}
}
第三,我创建了一个SpringSecurityInitializer类,它不需要任何额外的代码,正如我所读到的那样。
public class SpringSecurityInitializer extends AbstractSecurityWebApplicationInitializer
{
}
所以最后:
我认为缺少显示用户名位置的页面标题的组件。 我对吗?