model/api/src/main/java/org/keycloak/models/utils/KeycloakModelUtils.java
/**
     * Try to find user by given username. If it fails, then fallback to find him by email
     *
     * @param realm realm
     * @param username username or email of user
     * @return found user
     */
Try to find user by given username. If it fails, then fallback to find him by email
@param realm realm
@param username username or email of user
@return found user
Try to find user by given username . If it fails then fallback to find him by email @param realm realm @param username username or email of user @return found user
public static UserModel findUserByNameOrEmail(KeycloakSession session, RealmModel realm, String username) {
        UserModel user = session.users().getUserByUsername(username, realm);
        if (user == null && username.contains("@")) {
            user =  session.users().getUserByEmail(username, realm);
        }
        return user;
    }
public static UserModel findUserByNameOrEmail ( KeycloakSession session , RealmModel realm , String username ) { UserModel user = session . users ( ) . getUserByUsername ( username , realm ) ; if ( user == null && username . contains ( "@" ) ) { user = session . users ( ) . getUserByEmail ( username , realm ) ; } return user ; }
Try to find user by given username.
Try to find user by given username .