2011-12-20 1 views
0

私はapache shiroを使用してユーザーを認証していますが、私のファインダー機能が正常に動作しているかどうかを確認するために私は(アプリケーションの実行時にレコードが削除され、SQL文を使用していないEclipseLinkの?)ユーザーにレコードを追加EclipseLink JPAユーザー名/パスワード検索でアプリを実行するとレコードが削除される

ここで私は、ユーザー名で単一のユーザーを取得しようとしている方法です:

protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { 
    UsernamePasswordToken token = (UsernamePasswordToken) authcToken; 
    Map<String, String> map = new HashMap<String, String>(); 
    String tempUsername = token.getUsername(); 
    String password = ""; 
    Users user; 

    // Null username is invalid 
    if (tempUsername == null) { 
     throw new AccountException("Null usernames are not allowed by this realm."); 
    } 
    AuthenticationInfo info = null; 
    // this will query and find the users by the specified username and then return us the single result 
    user = getAuthorizedUser(Users.findUsersesByUsernameEquals(tempUsername)); 
    System.out.print(user.getUsername()); 
    System.out.println("yea the username = "); 
    password = user.getPassword(); 
    info = buildAuthenticationInfo(tempUsername, password.toCharArray()); 
    return info; 
} 
/*Build the required authentication info; Replace with SaltAuthenticationInfo for salted passwords*/ 
protected AuthenticationInfo buildAuthenticationInfo(String username, char[] password) { 
      return new SimpleAuthenticationInfo(username, password, getName()); 
} 

protected Users getAuthorizedUser(TypedQuery<Users> q){ 
    System.out.println("working authentication"); 

     return q.getSingleResult(); 
} 

これは私がJPAを使用してユーザーを永続化して追加するのではなく、アプリケーションの外部にSQL文を書き込むためですか?

+0

あなたの質問は何も分かりません。おそらく何が起こるかを説明し、最高のログを含めるようにしてください。 – James

+0

私はこれをやり終えると、正常に動作していることがわかりましたが、テーブルを破棄して実行ごとに作成するプロパティが設定されていました。 – Warz

答えて

0

私は<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>

これは私のテストレコードを削除し、私の問題を解決したこのプロパティを無効に。

+0

溶液におめでとう。できれば、あなたの答えを「受け入れられた」とマークして、他の人があなたの成功から学ぶかもしれないことを確認してください。乾杯〜 –

関連する問題