// Path: src/main/java/org/nextrtc/examples/videochat_with_rest/domain/User.java
// @Entity
// @Table(name = "Users")
// public class User {
// 
//     @Id
//     @GeneratedValue(strategy = GenerationType.AUTO)
//     @Column(name = "user_id")
//     private int id;
// 
//     @Column(name = "username")
//     private String username;
// 
//     @Column(name = "password")
//     private String password;
// 
//     @Column(name = "auth_provider_id")
//     private String authProviderId;
// 
//     @Column(name = "confirmation_key")
//     private String confirmationKey;
// 
//     @Column(name = "role")
//     private String role = "USER";
// 
//     @Column(name = "email")
//     private String email;
// 
//     @Column(name = "confirmed")
//     private boolean confirmed = false;
// 
//     @OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
//     private Set<Member> conversationMember;
// 
//     @Deprecated
//     User() {
//     }
// 
//     public User(String username, String password, String email, String confirmationKey) {
//         this.username = username;
//         this.password = password;
//         this.email = email;
//         this.confirmationKey = confirmationKey;
//     }
// 
//     public User(String username, String email, String authProviderId) {
//         this.username = username;
//         this.email = email;
//         this.authProviderId = authProviderId;
//         confirmed = true;
//     }
// 
//     public String getUsername() {
//         return username;
//     }
// 
//     public void confirmEmail() {
//         confirmed = true;
//     }
// 
//     public History prepareHistory() {
//         return new History(conversationMember);
//     }
// }
// 
// Path: src/main/java/org/nextrtc/examples/videochat_with_rest/repo/UserRepository.java
// @org.springframework.stereotype.Repository
// @RepositoryRestResource(exported = false)
// @Transactional
// public interface UserRepository extends JpaRepository<User, Integer> {
// 
//     Optional<User> findByUsername(@Param("username") String username);
// 
//     Optional<User> findByEmail(@Param("email") String email);
// 
//     Optional<User> findByConfirmationKey(@Param("confirmationKey") String key);
// 
//     Optional<User> findByAuthProviderId(@Param("authProviderId") String key);
// 
// 
// }


import org.nextrtc.examples.videochat_with_rest.domain.User;
import org.nextrtc.examples.videochat_with_rest.repo.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.security.Principal;
import java.util.Optional;
package org.nextrtc.examples.videochat_with_rest.auth;



@Service
public class AuthUtils {

    @Autowired
    private UserRepository userRepository;

    public User getAuthenticatedUser(Principal userPrincipal) {
        String name = userPrincipal.getName();
// Path: src/main/java/org/nextrtc/examples/videochat_with_rest/domain/User.java
// @Entity
// @Table(name = "Users")
// public class User {
// 
//     @Id
//     @GeneratedValue(strategy = GenerationType.AUTO)
//     @Column(name = "user_id")
//     private int id;
// 
//     @Column(name = "username")
//     private String username;
// 
//     @Column(name = "password")
//     private String password;
// 
//     @Column(name = "auth_provider_id")
//     private String authProviderId;
// 
//     @Column(name = "confirmation_key")
//     private String confirmationKey;
// 
//     @Column(name = "role")
//     private String role = "USER";
// 
//     @Column(name = "email")
//     private String email;
// 
//     @Column(name = "confirmed")
//     private boolean confirmed = false;
// 
//     @OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
//     private Set<Member> conversationMember;
// 
//     @Deprecated
//     User() {
//     }
// 
//     public User(String username, String password, String email, String confirmationKey) {
//         this.username = username;
//         this.password = password;
//         this.email = email;
//         this.confirmationKey = confirmationKey;
//     }
// 
//     public User(String username, String email, String authProviderId) {
//         this.username = username;
//         this.email = email;
//         this.authProviderId = authProviderId;
//         confirmed = true;
//     }
// 
//     public String getUsername() {
//         return username;
//     }
// 
//     public void confirmEmail() {
//         confirmed = true;
//     }
// 
//     public History prepareHistory() {
//         return new History(conversationMember);
//     }
// }
// 
// Path: src/main/java/org/nextrtc/examples/videochat_with_rest/repo/UserRepository.java
// @org.springframework.stereotype.Repository
// @RepositoryRestResource(exported = false)
// @Transactional
// public interface UserRepository extends JpaRepository<User, Integer> {
// 
//     Optional<User> findByUsername(@Param("username") String username);
// 
//     Optional<User> findByEmail(@Param("email") String email);
// 
//     Optional<User> findByConfirmationKey(@Param("confirmationKey") String key);
// 
//     Optional<User> findByAuthProviderId(@Param("authProviderId") String key);
// 
// 
// }


// Path: src/main/java/org/nextrtc/examples/videochat_with_rest/auth/AuthUtils.java
import org.nextrtc.examples.videochat_with_rest.domain.User;
import org.nextrtc.examples.videochat_with_rest.repo.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.security.Principal;
import java.util.Optional;

package org.nextrtc.examples.videochat_with_rest.auth;



@Service
public class AuthUtils {

    @Autowired
    private UserRepository userRepository;

    public User getAuthenticatedUser(Principal userPrincipal) {
        String name = userPrincipal.getName();
        Optional<User> byUsername = userRepository.findByUsername(name);