2013-09-02 4 views
1

appfoundation을 사용하여 실패한 로그인 시도 방법은 무엇입니까? 그것은 getFailedLoginAttempts() 함수를 가지고 있지만 아무 의미가 없습니다. 내가 코멘트에있는 모든 문제를 썼다Vaadin에서 getFailedLoginAttempts() 함수가 의미가 없습니다.

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")); 
      } 
     } 
    }); 

: 나는

내 코드는 여기에 만약 angel 6 (6.8.12)를 사용하고 있습니다. 실패한 로그인 시도 횟수를 인쇄하려고하지만이 번호를 얻을 수 없습니다. 어떤 제안?

+0

사용중인 버디의 버전 –

+0

@ user2310289 편집 됨. –

답변

0

AuthenticationUtil.authenticate(username, password). getFailedLoginAttempts() 코드가 컴파일되는 이유는 authenticate 메서드가 성공적인 인증시 User 개체를 반환하고이 메서드에 액세스 할 수있는 이유입니다. 그러나 예외가 발생하면 사용자 개체가 없습니다. 유닛 테스트에서 FactoryFacade를 사용하여 사용자 객체를 검색하고 그런 식으로 검사합니다. API를 잘 모르기 때문에 사용자에게 다른 방법을 제공 할 수 있는지 여부를 알 수 없습니다.

+0

내 자신의 클래스에있는 AuthenticationUtil.java에서 getUserForUsername (String username) 메소드를 구현하고이 방법으로 문제를 해결했습니다. –

+0

멋지다 - 아마도 나만의 답변을 만들 수 있습니다. –

0

https://code.google.com/p/vaadin-appfoundation/source/browse/src/org/vaadin/appfoundation/authentication/util/AuthenticationUtil.java 내가 내 자신의 클래스에서 사용자를 가져 오기위한 함수를 썼다 참조하십시오.

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); 
} 

그리고 catch 블록에서이 메서드를 호출합니다.

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")); 
} 

모두 정상적으로 작동합니다.

관련 문제