Class AdminService
java.lang.Object
fr.utc.miage.sporttrack.service.user.AdminService
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
ConstructorsConstructorDescriptionAdminService(AdminRepository adminRepository, org.springframework.security.crypto.password.PasswordEncoder passwordEncoder, String defaultPassword) Constructs a newAdminService, seeding a default admin account if the database contains no administrators. -
Method Summary
Modifier and TypeMethodDescriptionbooleancheckAdminLoggedIn(org.springframework.security.core.Authentication auth) Checks whether the given authentication object represents a logged-in admin.findByEmail(String email) Finds an administrator by their email address.
-
Constructor Details
-
AdminService
public AdminService(AdminRepository adminRepository, org.springframework.security.crypto.password.PasswordEncoder passwordEncoder, @Value("${admin.default.password}") String defaultPassword) Constructs a newAdminService, seeding a default admin account if the database contains no administrators.- Parameters:
adminRepository- the repository for admin data accesspasswordEncoder- the encoder used to hash the default passworddefaultPassword- the plaintext default password injected from configuration
-
-
Method Details
-
findByEmail
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 benull- Returns:
trueif the authentication corresponds to a valid admin,falseotherwise
-