Мое приложение имеет Spring boot 1.3.2, и я пытаюсь использовать Spring MVC с Spring Security.Spring Security blocking Rest Controller
У меня есть панель управления при http://localhost:8080/admin и мое содержание страницы для обычных пользователей под http://localhost:8080/
Если Вы пытаетесь открыть панель администратора (http://localhost:8080/admin) Вы должны войти в систему, если Вы обычны просто введите http://localhost:8080/ и имеют забава не требуется.
My Security конфиг класс:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("admin")
.password("password")
.roles("ADMIN");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/admin/**").hasRole("ADMIN")
.antMatchers("/**").permitAll()
.anyRequest().permitAll()
.and()
.formLogin()
.loginPage("/login");
}
}
Config выше, дайте мне требовать от входа/администратора Но у меня есть некоторые проблемы с функциями панели администратора.
Это контроллер Я пытаюсь запросить с POST из панели администратора:
@RestController
@RequestMapping("/admin/v1")
public class AdminController {
@RequestMapping(value = "/logout", method = RequestMethod.POST)
public String logout(HttpServletRequest request, HttpServletResponse response) {
String hello = "hi!";
return hello;
}
}
Так что я могу войти, браузер рендеринга панели администратора для меня, но когда я нажав кнопку выхода из системы, которая запрос POST выхода из системы метод от контроллера выше. Приложение говорит мне 403 Запрещено
Может ли кто-нибудь сказать мне, что я делаю неправильно?
Не могли бы вы проверить, если ваш пост-запрос содержит маркер CSRF? – fateddy