2017-06-03 277 views
1

我被困在这里的一个问题。我正在为我的应用程序使用primefaces的弹簧引导。我正在使用spring安全进行身份验证。不知何故,我得到访问被拒绝。除此之外,用户已经在mongodb中建立起来了,如果我使用spring重定向,那么一切都很好。春季安全春季启动4.x

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

假设参考这个[示例](https://github.com/spring-projects/spring-boot/tree/master/spring -boot-samples/spring-boot-sample-web-method-security)在github上的项目。他们可能有一个解决方案。 –

回答

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/