Spring Boot(1.2.7.RELEASE)とVaadin(7.6.3)に基づいてアプリケーションを構築しようとしています。私の問題は、Spring SecurityをVaadinと統合できないことです。カスタムのVaadinが構築したLoginScreenおよびSpring Securityコントロールが必要です。私のプロジェクトのセットアップは次のとおりです:
@Configuration
@EnableWebSecurity
public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable().
exceptionHandling().authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/login")).accessDeniedPage("/accessDenied")
.and().authorizeRequests()
.antMatchers("/VAADIN/**", "/Push/**", "/UIDL/**", "/login", "/login/**", "/error/**", "/accessDenied/**", "/vaadinServlet/**").permitAll()
.antMatchers("/authorized", "/**").fullyAuthenticated();
}
}
そして、これが私のVaadinログインUIです
@SpringUI(path = "/login")
@Title("LoginPage")
@Theme("valo")
public class LoginUI extends UI {
TextField user;
PasswordField password;
Button loginButton = new Button("Login", this::loginButtonClick);
private static final String username = "username";
private static final String passwordValue = "test123";
@Override
protected void init(VaadinRequest request) {
setSizeFull();
user = new TextField("User:");
user.setWidth("300px");
user.setRequired(true);
user.setInputPrompt("Your username");
password = new PasswordField("Password:");
password.setWidth("300px");
password.setRequired(true);
password.setValue("");
password.setNullRepresentation("");
VerticalLayout fields = new VerticalLayout(user, password, loginButton);
fields.setCaption("Please login to access the application");
fields.setSpacing(true);
fields.setMargin(new MarginInfo(true, true, true, false));
fields.setSizeUndefined();
VerticalLayout uiLayout = new VerticalLayout(fields);
uiLayout.setSizeFull();
uiLayout.setComponentAlignment(fields, Alignment.MIDDLE_CENTER);
setStyleName(Reindeer.LAYOUT_BLUE);
setFocusedComponent(user);
setContent(uiLayout);
}
public void loginButtonClick(Button.ClickEvent e) {
//authorize/authenticate user
//tell spring that my user is authenticated and dispatch to my mainUI
}
}
アプリケーションを起動すると、SpringからログインUIにリダイレクトされますが、問題ありません。
しかし、春のセキュリティメカニズムに対してユーザーを認証し、mainUIにディスパッチする方法がわかりません。
また、csrfトークンの問題にも直面しています。csrfを無効にしないと、crfsトークンがnull例外になります。これらの問題を処理する多くの例を見つけましたが、Vaadinで提供される解決策はありません。
手伝ってくれてありがとう。
与えられたアプローチの代わりとして、あなたは vaadin4spring
、VaadinとSpringをさらに統合するための「非公式」拡張セット 。
現在、Spring Securityを統合するために 2つの方法 を提供していますが、正常に機能しているように見えます(機能しない場合でも、コードサンプルでカスタム統合コードを作成するための十分な洞察が得られます)。