2017-06-03 429 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/