Class AdminService

java.lang.Object
fr.utc.miage.sporttrack.service.user.AdminService

@Service public class AdminService extends Object
Service layer component responsible for managing Admin entities within the SportTrack application.

Provides business logic for looking up administrators and verifying admin authentication status. A default admin account is automatically seeded on first application startup if no admin exists in the database.

Author:
SportTrack Team
  • Constructor Summary

    Constructors
    Constructor
    Description
    AdminService(AdminRepository adminRepository, org.springframework.security.crypto.password.PasswordEncoder passwordEncoder, String defaultPassword)
    Constructs a new AdminService, seeding a default admin account if the database contains no administrators.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    checkAdminLoggedIn(org.springframework.security.core.Authentication auth)
    Checks whether the given authentication object represents a logged-in admin.
    Finds an administrator by their email address.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AdminService

      public AdminService(AdminRepository adminRepository, org.springframework.security.crypto.password.PasswordEncoder passwordEncoder, @Value("${admin.default.password}") String defaultPassword)
      Constructs a new AdminService, seeding a default admin account if the database contains no administrators.
      Parameters:
      adminRepository - the repository for admin data access
      passwordEncoder - the encoder used to hash the default password
      defaultPassword - the plaintext default password injected from configuration
  • Method Details

    • findByEmail

      public Admin findByEmail(String email)
      Finds an administrator by their email address.
      Parameters:
      email - the email address to search for
      Returns:
      the matching Admin
      Throws:
      IllegalArgumentException - if no admin is found with the given email
    • checkAdminLoggedIn

      public boolean checkAdminLoggedIn(org.springframework.security.core.Authentication auth)
      Checks whether the given authentication object represents a logged-in admin.
      Parameters:
      auth - the Spring Security authentication object, may be null
      Returns:
      true if the authentication corresponds to a valid admin, false otherwise