Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Usage of User.get2(Authentication a) in OicSecurityRealm #484

Open
eva-mueller-coremedia opened this issue Dec 20, 2024 · 0 comments

Comments

@eva-mueller-coremedia
Copy link
Contributor

eva-mueller-coremedia commented Dec 20, 2024

OicSecurityRealm uses User.get2 at several places:

  • OicSecurityRealm#loginAndSetUserData
  • OicSecurityRealm#doLogout
  • OicSecurityRealm#handleTokenExpiration
  • OicSecurityRealm#refreshExpiredToken

Question

User.get2(Authentication a) will create a new user if the user does not exist. I wonder if the user creation should only happen in OicSecurityRealm#loginAndSetUserData?

Background

The implementation of User.get2(Authentication a)

public static @CheckForNull User get2(@CheckForNull Authentication a) {
    if (a == null || a instanceof AnonymousAuthenticationToken)
        return null;

    // Since we already know this is a name, we can just call getOrCreateById with the name directly.
    return getById(a.getName(), true);
}

will create a new user if a.getName() is null:

/**
 * Retrieve a user by its ID, and create a new one if requested.
 *
 * @return An existing or created user. May be {@code null} if a user does not exist and
 * {@code create} is false.
 */
private static @Nullable User getOrCreateById(@NonNull String id, @NonNull String fullName, boolean create) {
    User u = AllUsers.get(id);
    if (u == null && (create || UserIdMapper.getInstance().isMapped(id))) {
        u = new User(id, fullName);
        AllUsers.put(id, u);
        if (!id.equals(fullName) && !UserIdMapper.getInstance().isMapped(id)) {
            try {
                u.save();
            } catch (IOException x) {
                LOGGER.log(Level.WARNING, "Failed to save user configuration for " + id, x);
            }
        }
    }
    return u;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant