我想问一下如何创建一个安全的登录。
到目前为止,我只有一个登录视图,现在想问一下如何在成功登录后更改视图。通过MySQL数据库进行的登录检查也可以正常运行。我只是不希望有人只是添加“仪表板”的网址,并跳过登录。
@Route("login")
@PageTitle("Login")
public class LoginView extends VerticalLayout {
private final LoginService loginService;
private LoginOverlay loginOverlay = new LoginOverlay();
public LoginView(LoginService loginService) {
this.loginService = loginService;
this.loginOverlay.setOpened(true);
this.loginOverlay.setForgotPasswordButtonVisible(false);
this.loginOverlay.setDescription(null);
this.loginOverlay.setEnabled(true);
this.loginOverlay.addLoginListener(e -> {
if (this.loginService.authenticateUser(e.getUsername(), e.getPassword())) {
?
} else {
this.loginOverlay.setError(true);
}
});
this.add(loginOverlay);
}
}发布于 2019-10-24 15:02:42
有一个关于vaadin + spring安全的系列教程。
https://vaadin.com/tutorials/securing-your-app-with-spring-security
发布于 2019-10-23 23:33:44
如果您正在使用Spring,一种选择是使用Spring Security在登录之前列出可用的urls,如果未经验证的用户试图导航到其他地方,则重定向到登录。你可以在full stack starter app的SecurityConfiguration.java中找到一个这样的例子。
另一种选择是监听BeforeEnter事件,如果用户未登录,则以编程方式将用户重定向至登录屏幕。你可以在BookstoreInitListener.java中找到一个这样的例子。源代码在github中,您也可以通过选择simple app starter的Java tech stack下载该应用程序的副本
https://stackoverflow.com/questions/58525906
复制相似问题