Я новичок весной.
Я пытался добавить новую цель в свою базу данных. Прежде чем добавить Spring Security, она работает, но теперь, если я нажму, чтобы добавить новую цель, у меня возникла проблема: < /p>
Была неожиданная ошибка (type = forbiden, status = 403).
forbidden < /p>
my Goat-add.html: < /p>
Goals
Your goals
Add goal
< /code>
websecurityconfig class: < /p>
package com.evgzabozhan.GoatGoal.config;
import com.evgzabozhan.GoatGoal.service.UserService;
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;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserService userService;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/login","/registration").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userService)
.passwordEncoder(NoOpPasswordEncoder.getInstance());
}
}
< /code>
Мой контроллер: < /p>
package com.evgzabozhan.GoatGoal.controller;
import com.evgzabozhan.GoatGoal.model.Goal;
import com.evgzabozhan.GoatGoal.model.User;
import com.evgzabozhan.GoatGoal.repository.GoalRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.*;
@Controller
public class GoalController {
@Autowired
private GoalRepository goalRepository;
@GetMapping("/goal")
public String goal(Model model){
Iterable goals = goalRepository.findAll();
model.addAttribute("goals",goals);
return "goal/goal-main";
}
@GetMapping("/goal/add")
public String getGoalAdd(Model model){
return "goal/goal-add";
}
@PostMapping("/goal/add")
public String postGoalAdd(@AuthenticationPrincipal User user,
@RequestParam String name,
@RequestParam String description, Model model){
Goal goal = new Goal(name,description,user);
goalRepository.save(goal);
model.addAttribute("message",user.getUsername());
return "redirect:/goal";
}
@GetMapping("/goal/{id}")
public String goalInfo(@PathVariable(value = "id") long id, Model model) {
if (!goalRepository.existsById(id)) {
return "redirect:/goal";
}
Optional goal = goalRepository.findById(id);
ArrayList result = new ArrayList();
goal.ifPresent(result::add);
model.addAttribute("goal", result);
return "goal/goal-info";
}
@GetMapping("/goal/{id}/edit")
public String goalEdit(@PathVariable(value = "id") long id, Model model){
if (!goalRepository.existsById(id)) {
return "redirect:/goal";
}
Optional goal = goalRepository.findById(id);
ArrayList result = new ArrayList();
goal.ifPresent(result::add);
model.addAttribute("goal", result);
return "goal/goal-edit";
}
@PostMapping("/goal/{id}/edit")
public String postGoalUpdate(@PathVariable(value = "id") long id,
@RequestParam String name,
@RequestParam String description,
Model model){
Goal goal = goalRepository.findById(id).orElseThrow();
goal.setName(name);
goal.setDescription(description);
goalRepository.save(goal);
return "redirect:/goal";
}
@PostMapping("/goal/{id}/remove")
public String postGoalRemove(@PathVariable(value = "id") long id, Model model){
Goal goal = goalRepository.findById(id).orElseThrow();
goalRepository.delete(goal);
return "redirect:/goal";
}
}
< /code>
Я прочитаю эту проблему, если не используйте CSRF, но я не понимаю, как я могу ее исправить. < /p>
Все код там там : https://github.com/evgzabozhan/goatgoal
Спасибо за вашу помощь!
Подробнее здесь: https://stackoverflow.com/questions/649 ... 3-forbiden
Была неожиданная ошибка (type = forbidden, status = 403). ⇐ JAVA
Программисты JAVA общаются здесь
-
Anonymous
1738015514
Anonymous
Я новичок весной.
Я пытался добавить новую цель в свою базу данных. Прежде чем добавить Spring Security, она работает, но теперь, если я нажму, чтобы добавить новую цель, у меня возникла проблема: < /p>
Была неожиданная ошибка (type = forbiden, status = 403).
forbidden < /p>
my Goat-add.html: < /p>
Goals
Your goals
Add goal
< /code>
websecurityconfig class: < /p>
package com.evgzabozhan.GoatGoal.config;
import com.evgzabozhan.GoatGoal.service.UserService;
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;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserService userService;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/login","/registration").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userService)
.passwordEncoder(NoOpPasswordEncoder.getInstance());
}
}
< /code>
Мой контроллер: < /p>
package com.evgzabozhan.GoatGoal.controller;
import com.evgzabozhan.GoatGoal.model.Goal;
import com.evgzabozhan.GoatGoal.model.User;
import com.evgzabozhan.GoatGoal.repository.GoalRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.*;
@Controller
public class GoalController {
@Autowired
private GoalRepository goalRepository;
@GetMapping("/goal")
public String goal(Model model){
Iterable goals = goalRepository.findAll();
model.addAttribute("goals",goals);
return "goal/goal-main";
}
@GetMapping("/goal/add")
public String getGoalAdd(Model model){
return "goal/goal-add";
}
@PostMapping("/goal/add")
public String postGoalAdd(@AuthenticationPrincipal User user,
@RequestParam String name,
@RequestParam String description, Model model){
Goal goal = new Goal(name,description,user);
goalRepository.save(goal);
model.addAttribute("message",user.getUsername());
return "redirect:/goal";
}
@GetMapping("/goal/{id}")
public String goalInfo(@PathVariable(value = "id") long id, Model model) {
if (!goalRepository.existsById(id)) {
return "redirect:/goal";
}
Optional goal = goalRepository.findById(id);
ArrayList result = new ArrayList();
goal.ifPresent(result::add);
model.addAttribute("goal", result);
return "goal/goal-info";
}
@GetMapping("/goal/{id}/edit")
public String goalEdit(@PathVariable(value = "id") long id, Model model){
if (!goalRepository.existsById(id)) {
return "redirect:/goal";
}
Optional goal = goalRepository.findById(id);
ArrayList result = new ArrayList();
goal.ifPresent(result::add);
model.addAttribute("goal", result);
return "goal/goal-edit";
}
@PostMapping("/goal/{id}/edit")
public String postGoalUpdate(@PathVariable(value = "id") long id,
@RequestParam String name,
@RequestParam String description,
Model model){
Goal goal = goalRepository.findById(id).orElseThrow();
goal.setName(name);
goal.setDescription(description);
goalRepository.save(goal);
return "redirect:/goal";
}
@PostMapping("/goal/{id}/remove")
public String postGoalRemove(@PathVariable(value = "id") long id, Model model){
Goal goal = goalRepository.findById(id).orElseThrow();
goalRepository.delete(goal);
return "redirect:/goal";
}
}
< /code>
Я прочитаю эту проблему, если не используйте CSRF, но я не понимаю, как я могу ее исправить. < /p>
Все код там там : https://github.com/evgzabozhan/goatgoal
Спасибо за вашу помощь!
Подробнее здесь: [url]https://stackoverflow.com/questions/64940922/there-was-an-unexpected-error-type-forbidden-status-403-forbiden[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия