April 2018
Intermediate to advanced
202 pages
4h 48m
English
Following this approach, we can store the username in the HTTP session when a user is successfully authenticated. We can also check whether the user has been authenticated by checking whether a value exists in the HTTP session. This can be implemented as follows:
public class AuthService {
private static final String USERNAME_ATTRIBUTE = "username";
public static boolean authenticate(
String username, String password) {
boolean authentic = "admin".equals(username) &&
"admin".equals(password);
if (authentic) {
VaadinSession.getCurrent().setAttribute(
USERNAME_ATTRIBUTE, username);
}
return authentic;
}
public static boolean isAuthenticated() {
return VaadinSession.getCurrent().getAttribute( USERNAME_ATTRIBUTE) ...Read now
Unlock full access