我使用apache shiro來認證用戶,我想簡單地打印用戶名到我的控制檯來檢查我的finder功能是否正常工作,它似乎是什麼時候我將記錄添加到用戶(使用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語句?
不知道你的問題是什麼。也許可以解釋更好的情況,幷包括最好的日誌。 – James 2011-12-21 14:39:29
我最終這樣做,發現事情正常工作,但設置了一個屬性,不斷丟棄表並在每次運行時創建它們。 – Warz 2011-12-21 17:42:09