我在这里遇到了问题。我正在使用带有primefaces的spring boot用于我的应用程序。我正在使用spring security进行身份验证。不知怎的,我被拒绝访问。除此之外,用户已经在mongodb中建立了,如果我使用spring重定向,一切都很好。
http.csrf().csrfTokenRepository(csrfTokenRepository()).and().authorizeRequests().antMatchers("/login**").access("permitAll")
.antMatchers("/logout**").access("permitAll")
.antMatchers("/secure/homePage.xhtml").access("hasRole('ADMIN') or hasRole('USER')")
.anyRequest().authenticated().and().formLogin().loginPage("/login").defaultSuccessUrl("/secure/homePage.xhtml")
.failureUrl("/login.xhtml?error").usernameParameter("email").and().logout().logoutUrl("/logout.xhtml")
.logoutSuccessUrl("/login.xhtml").invalidateHttpSession(true).clearAuthentication(true).and()
.exceptionHandling().accessDeniedPage("/accessDenied.xhtml");
顺便说一下,我的登录页面中有以下内容:
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
答案 0 :(得分:0)
你的终点有些可疑。
他们是/secure/homePage.xhtml
。这些通常指向控制器方法,并在控制器中提供视图的路径。然后一个特定的视图解析器将转到并传递页面。
@Bean
ViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setViewClass(org.springframework.faces.mvc.JsfView.class);
resolver.setPrefix("/WEB-INF");
resolver.setSuffix(".xhtml");
return resolver;
}
@Controller
public class HelloWorldController {
@RequestMapping("/helloWorld")
public String helloWorld(Model model) {
model.addAttribute("message", "Hello World!");
return "helloWorld";
}
}
在此示例中,helloWorld.xhtml
/WEB-INF/