Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java getFailedLoginAttents()函数没有';在瓦丁的appfoundation里没有任何意义_Java_Authentication_Vaadin - Fatal编程技术网

Java getFailedLoginAttents()函数没有';在瓦丁的appfoundation里没有任何意义

Java getFailedLoginAttents()函数没有';在瓦丁的appfoundation里没有任何意义,java,authentication,vaadin,Java,Authentication,Vaadin,如何使用appfoundation获取失败的登录尝试?它有一个函数getFailedLoginAttents(),但没有任何意义。我正在使用Vaadin 6(6.8.12) 我的代码在这里: NativeButton login = new NativeButton(Lang.getMessage("login"), new ClickListener() { private static final long serialVersionUID = -557742354694

如何使用appfoundation获取失败的登录尝试?它有一个函数getFailedLoginAttents(),但没有任何意义。我正在使用Vaadin 6(6.8.12)

我的代码在这里:

NativeButton login = new NativeButton(Lang.getMessage("login"), new ClickListener() {

         private static final long serialVersionUID = -5577423546946890721L;

         public void buttonClick(ClickEvent event) {

             username = (String) usernameField.getValue();
             String password = (String) passwordField.getValue();
            try {
                AuthenticationUtil.authenticate(username, password);            
                startApp();    
            } catch (InvalidCredentialsException e) {
             /* I need to get failed login attempts here but how can I do that? 
I just can by doing this: AuthenticationUtil.authenticate(username, password).
getFailedLoginAttempts(),  but I need to write try and catch blocks 
(so try and catch blocks in catch block) for authenticate method and this
function will never work, because user won't be authenticated and all 
the time you will go to the other catch block; */
                feedbackLabel.setValue(Lang.getMessage("usernameOrPasswordIncorect"));                    
            } catch (AccountLockedException e) {
                feedbackLabel.setValue(Lang.getMessage("accountBlocked"));
            }
        }
    });

我把所有的问题都写在评论里了。我想打印一些失败的登录尝试,但无法获取此号码。有什么建议吗?

为什么代码
AuthenticationUtil.authenticate(用户名、密码)。
getFailedLoginAttents()
编译的是
authenticate
方法在成功验证后返回用户对象,然后可以访问此方法。但是,如果抛出异常,则您没有用户对象。然后,在单元测试中,使用FactoryFacade检索用户对象并进行检查。我不太了解API,所以我无法告诉您是否可以通过其他方式获得用户


请参见

我编写了一个函数,用于在自己的类中获取用户

private User getUserForUsername(String username) {
    String query = "SELECT u FROM User u WHERE u.username = :username";
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("username", username);
    return (User) FacadeFactory.getFacade().find(query, parameters);
}

一切正常。

您使用的是哪个版本的vaadin我在自己的类中实现了AuthenticationUtil.java中的getUserForUsername(String username)方法,并用这种方式解决了问题。
try {
    AuthenticationUtil.authenticate(username, password);
    startApp();
} catch (InvalidCredentialsException e) {
    User user = getUserForUsername(username);
    feedbackLabel.setValue(Lang.getMessage("usernameOrPasswordIncorect"));
    attemptsLeftLabel.setValue(Lang.getMessage("attemptsLeft", 5 - user.getFailedLoginAttempts()));
} catch (AccountLockedException e) {
    feedbackLabel.setValue(Lang.getMessage("accountBlocked"));
}