mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-12 16:38:48 +00:00
35 lines
1.1 KiB
Java
35 lines
1.1 KiB
Java
package com.imprimelibros.erp.users;
|
|
|
|
import org.springframework.security.core.userdetails.UserDetails;
|
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
|
|
|
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
@Service
|
|
public class UserServiceImpl implements UserService {
|
|
|
|
private UserDao userDao;
|
|
|
|
public UserServiceImpl(UserDao userDao) {
|
|
this.userDao = userDao;
|
|
}
|
|
|
|
@Override
|
|
public UserDetails loadUserByUsername(String username) {
|
|
User user = userDao.findByUserNameIgnoreCaseAndEnabledTrueAndDeletedFalse(username)
|
|
.orElseThrow(() -> new UsernameNotFoundException("No existe usuario activo: " + username));
|
|
return new UserDetailsImpl(user);
|
|
}
|
|
|
|
// ===== Búsqueda para Select2 =====
|
|
@Override
|
|
public Page<User> findByRoleAndSearch(String role, String query, Pageable pageable) {
|
|
|
|
if (query == null || query.isBlank()) query = null;
|
|
return userDao.searchUsers(role, query, pageable);
|
|
}
|
|
}
|