Я хочу перенаправить на главную страницу после успешной регистрации.Регистрация успешна, но процесс перенаправления не успешен. Снова он возвращается на страницу входа, а метод post возвращается со статусом 302.
@RequestMapping(value="/bireysel/kaydet" , method = RequestMethod.POST)
public String saveBireyselKullanici(@Valid
@ModelAttribute("kullaniciKayitModel") KullaniciKayitModel kullaniciKayitModel,
Model model,
BindingResult bindingResult,
HttpServletRequest request,
HttpServletResponse response) {
ErrorDetail errorDetail = null;
if (bindingResult.hasErrors()) {
return "yeniKayit";
}
kullaniciKayitModel.setBireyselKurumsal(BireyselKurumsalTypeEnum.BIREYSEL);
errorDetail = registerService.hesapOlustur(kullaniciKayitModel);
if(errorDetail == null) {
registerService.authenticateUserAndSetSession(kullaniciKayitModel, request);
model.addAttribute("welcomeMessage", "Hoş geldiniz");
return "redirect:/anasayfa";
}else {
model.addAttribute("hataMesaj", "Kayıt esnasında hata meydana geldi!");
return "yeniKayit";
}
}
Моя конфигурация безопасности ниже:
@Autowired
private DataSource dataSource;
@Autowired
public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(dataSource).passwordEncoder(passwordEncoder())
.usersByUsernameQuery("SELECT username,password,enabled from toptansepetim.users WHERE username=? ")
.authoritiesByUsernameQuery("SELECT username,role from toptansepetim.user_roles where username=?");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().requireCsrfProtectionMatcher(new RequestMatcher() {
private Pattern allowedMethods = Pattern.compile("^(GET|POST)$");
private RegexRequestMatcher apiMatcher = new RegexRequestMatcher("", null);
@Override
public boolean matches(HttpServletRequest request) {
if (allowedMethods.matcher(request.getMethod()).matches())
return false;
if (apiMatcher.matches(request))
return false;
return true;
}
});
http.authorizeRequests()
.antMatchers("/css/**","/js/**","/fonts/**","/images/**", "/yeniKayit","/anasayfa","/bireysel/kaydet","/rest/kullanici/mevcut","/api/ililce/il/liste","/api/ililce/ilce/liste","/kullanici/bireysel/kaydet","/exceptions/**", "/home", "/anasayfa")
.permitAll().antMatchers()
.access("hasRole('" + RolTypeEnum.NORMAUL_USER.getValue() + "')").anyRequest().authenticated().and()
.formLogin().loginPage("/login").defaultSuccessUrl("/anasayfa").permitAll().usernameParameter("username")
.passwordParameter("password").and().logout().logoutSuccessUrl("/login?logout").permitAll().and()
.exceptionHandling().accessDeniedPage("/exceptions/403").and().csrf().csrfTokenRepository(new HttpSessionCsrfTokenRepository());
}
@Override
@Bean(name = BeanIds.AUTHENTICATION_MANAGER)
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
также мой метод входа в систему при успешной регистрации ниже
public void authenticateUserAndSetSession(KullaniciKayitModel
model,HttpServletRequest request) {
String username = model.getUsername();
String password = model.getPassword();
UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(username, password);
authToken.setDetails(new WebAuthenticationDetails(request));
Authentication authentication = authenticationManager.authenticate(authToken);
SecurityContextHolder.getContext().setAuthentication(authentication);
}
В чем причина перенаправления статуса 302в весенний сапог.