2015-09-10 45 views
1

我想爲我的Vaadin應用程序創建自定義登錄頁面。Vaadin + Spring Security + Ldap自定義登錄表格

MyUi.class

@Theme("valo") 
@SpringUI 
@Widgetset("pl.warta.AppWidgetSet") 
public class MyUI extends UI { 

@Autowired 
private SpringViewProvider ViewProvider; 

@Override 
protected void init(VaadinRequest request) { 
    final Navigator navigator = new Navigator(this, this); 
    navigator.addProvider(ViewProvider); 
    setNavigator(navigator); 

} 
} 

WebSecurityConfig.class

@Configuration 
@EnableWebMvcSecurity 
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http.csrf().disable(); 
     http.authorizeRequests().anyRequest().authenticated().and().formLogin().loginPage("/login").permitAll(); 
    } 

    @Configuration 
    protected static class AuthenticationConfiguration extends GlobalAuthenticationConfigurerAdapter { 

     @Override 
     public void init(AuthenticationManagerBuilder auth) throws Exception { 
      auth.ldapAuthentication().userDnPatterns("uid={0},ou=people").groupSearchBase("ou=groups").contextSource().ldif("classpath:test-server.ldif"); 
     } 
    } 
} 

SecuredView.class

@SpringView(name = SecuredView.NAME) 
@UIScope 
public class SecuredView extends VerticalLayout implements View { 

    private static final long serialVersionUID = 6937605817612926676L; 

    public static final String NAME = ""; 

    @PostConstruct 
    private void postConstruct() { 

     setSizeFull(); 
     setSpacing(true); 
     setMargin(true); 

     addComponent(new Label("<h3>Secured View</h3>", ContentMode.HTML)); 
    } 
    @Override 
    public void enter(ViewChangeEvent event) { 

    } 
} 

你可以向我展示LoginView.class的示例實現以匹配我的Spring Security配置嗎?當我創建的視圖與NAME = "login"我越來越:

Whitelabel Error Page 

This application has no explicit mapping for /error, so you are seeing this as a fallback. 

Thu Sep 10 09:47:14 CEST 2015 
There was an unexpected error (type=Not Found, status=404). 
No message available 

然而即使頁面將apear,我不知道如何在按鈕點擊注入安全驗證。

我沒有提及 - 使用默認表單登錄工作完美。

回答

0

我設法創建了一個工作解決方案。

對於每個人面臨這個問題,我推薦休耕這個例子:security-sample-managed

唯一的一個變化,你需要做的(OFC除了拋出模型和邏輯)是修改Application.java

@Configuration 
static class AuthenticationConfiguration implements AuthenticationManagerConfigurer { 

    @Override 
    public void configure(AuthenticationManagerBuilder auth) throws Exception { 
     //we need to put here ldap authentication, e.g.: 
     auth.ldapAuthentication().userDnPatterns("CN={0},OU=Users").contextSource().url("ldap://my.ldap.server:port").managerDn("adminDn").managerPassword("adminPassword"); 

    } 
} 

已經爲Vaadin配置了其他一切。請享用。

相關問題