use of com.laurentiuspilca.springsecurityc2.entities.User in project tapestry-5 by apache.
the class PersistAll method onCreateUser.
@CommitAfter
void onCreateUser() {
final User user = new User();
user.setFirstName("Foo User");
entityManager.persist(user);
this.user = user;
}
use of com.laurentiuspilca.springsecurityc2.entities.User in project youtubechannel by lspil.
the class JpaUserDetailsService method loadUserByUsername.
@Override
public UserDetails loadUserByUsername(String username) {
var o = userRepository.findUserByUsername(username);
User u = o.orElseThrow(() -> new UsernameNotFoundException(":("));
return new SecurityUser(u);
}
use of com.laurentiuspilca.springsecurityc2.entities.User in project youtubechannel by lspil.
the class JPAUserDetailsService method loadUserByUsername.
@Override
public UserDetails loadUserByUsername(String username) {
Optional<User> user = userRepository.findUserByUsername(username);
User u = user.orElseThrow(() -> new UsernameNotFoundException("Error!"));
return new SecurityUser(u);
}
use of com.laurentiuspilca.springsecurityc2.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class UserDetailsServiceImpl method loadUserByUsername.
// TODO: add courier repo for finding user by phoneNumber
@Override
public UserDetails loadUserByUsername(String login) throws UsernameNotFoundException {
User user = userRepo.findByEmail(login);
// if user not found by Email try find client/courier by phoneNumber
if (user == null) {
Client client = clientRepo.findByPhoneNumber(login);
if (client == null) {
throw new NotFoundEx(login);
}
user = client.getUser();
}
return user;
}
use of com.laurentiuspilca.springsecurityc2.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class FileServiceTest method deleteImgNotAdminNotOwner.
@Test
public void deleteImgNotAdminNotOwner() throws IOException {
// prepare
Long ownerId = 1L;
User howardOwner = UserUtils.courierHowardWolowitz(ownerId);
Long notOwnerId = 2L;
User leonardNotOwner = UserUtils.moderatorLeonardHofstadter(notOwnerId);
String imgName = "test.jpeg";
Path pathTestPng = UPLOAD_PATH.resolve(imgName);
// file name, where we locate our test.png
final String fileUuid = "55420882-1e23-4559-b84e-03c3f4d597af";
Path fileUuidPath = createFileUuidPath(fileUuid);
Files.copy(pathTestPng, fileUuidPath, StandardCopyOption.REPLACE_EXISTING);
File fileEntity = new File(UUID.fromString(fileUuid), FileType.JPEG, imgName, Files.size(fileUuidPath), Timestamp.valueOf(LocalDateTime.now()), howardOwner);
doNothing().when(fileRepoMock).delete(fileEntity);
Exception exception = assertThrows(CustomAccessDeniedException.class, () -> {
fileService.delete(fileEntity, leonardNotOwner);
});
String perfectMessage = new CustomAccessDeniedException().getMessage();
String resultMessage = exception.getMessage();
assertEquals(perfectMessage, resultMessage);
verify(fileRepoMock, never()).delete(fileEntity);
}
Aggregations