Я новичок в Spring Security, поэтому я, вероятно, пропущу что-то. У меня есть приложение Spring, которое запускает Jetty с помощью WebApplication, которую я хочу защитить с помощью Spring Security. Webapp работает и доступен, но не ограничен. Я пробовал много всего, но ничего не работало, поэтому я разбил его на минимальную настройку, но у меня все еще нет шансов. веб-приложение конфигурируется с помощью следующей конфигурации Java:не может получить весеннюю безопасность для работы
@EnableWebMvc
@Configuration
@Import(SecurityConfiguration.class)
@ComponentScan(useDefaultFilters = false, basePackages = { "myapp.web" }, includeFilters = { @ComponentScan.Filter(Controller.class) })
public class SpringMvcConfiguration extends WebMvcConfigurerAdapter {
/**
* Allow the default servlet to serve static files from the webapp root.
*/
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}
и сконфигурированной Spring Security здесь:
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user")
.password("password")
.roles("ADMIN")
.authorities("ADMIN");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest()
.hasAuthority("ADMIN");
}
}
и некоторые контроллера, как это:
@Controller
public class SecuredController {
@RequestMapping(value = "/secure", method = RequestMethod.GET)
@ResponseBody
public String secured() {
return "you should not see this unless you provide authentication";
}
}
Все начинается на все права, журнал сообщает мне, что контроллер отображается ...
[2014-10-01 20:21:29,538, INFO ] [main] mvc.method.annotation.RequestMappingHandlerMapping:197 - Mapped "{[/secure],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String myapp.web.SecuredController.secured()
... и что безопасность на месте, а также ...
[2014-10-01 20:21:30,298, INFO ] [main] gframework.security.web.DefaultSecurityFilterChain:28 - Creating filter chain: [email protected]1, [org.springframework.secu[email protected]352c308, org.spring[email protected]2af616d3, [email protected]935, [email protected], org.[email protected]bc57b40, org.sp[email protected]3deb2326, org.springframework.[email protected]7889a1ac, org.springfram[email protected]7d373bcf, o[email protected]5922ae77, org[email protected]7e1a1da6, org.springfr[email protected]1051817b]
... но /secure
URL моего контроллера безусловно достижимым. Что я делаю не так?
пс. Я хочу избежать xml config
все еще, без успеха ... – Ole