EclipseLink JPA 用户名/密码查找删除运行应用程序时的记录

发布于 2024-12-22 07:43:40 字数 1591 浏览 3 评论 0原文

我正在使用 apache shiro 来验证用户,我想简单地将用户名打印到控制台来检查我的查找器功能是否正常工作,似乎当我向用户添加记录时(使用 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 语句吗?

I am using apache shiro to authenticate a user and i want to simply print the username out to my console to check if my finder function is working properly, it seems as when i add a record to the user (using a sql statement and not eclipseLink, the record is deleted when the application is run ?)

Here is how i am trying to retrieve a single user by username:

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

Is this because i am not using JPA to persist and add the user but rather writing a sql statement outside my application?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷离° 2024-12-29 07:43:40

我禁用了此属性 >

这是删除我的测试记录并解决了我的问题。

I disabled this property <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>

This was deleting my test records and solved my problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文