我正在使用apache shiro对用户进行身份验证,我想简单地将用户名打印到我的控制台以检查我的finder功能是否正常工作,这似乎就像我向用户添加记录一样(使用sql语句)而不是eclipseLink,在运行应用程序时删除记录?)
以下是我尝试按用户名检索单个用户的方法:
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 :(得分:0)
我停用了此属性<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
这是删除我的测试记录并解决了我的问题。