Search in sources :

Example 51 with User

use of com.laurentiuspilca.ssc6.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;
}
Also used : User(org.example.app1.entities.User) CommitAfter(org.apache.tapestry5.jpa.annotations.CommitAfter)

Example 52 with User

use of com.laurentiuspilca.ssc6.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);
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) SecurityUser(com.laurentiuspilca.ssc6.security.model.SecurityUser) User(com.laurentiuspilca.ssc6.entities.User) SecurityUser(com.laurentiuspilca.ssc6.security.model.SecurityUser)

Example 53 with User

use of com.laurentiuspilca.ssc6.entities.User in project youtubechannel by lspil.

the class UsernamePasswordAuthProvider method authenticate.

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    String username = authentication.getName();
    String password = (String) authentication.getCredentials();
    UserDetails user = userDetailsService.loadUserByUsername(username);
    if (passwordEncoder.matches(password, user.getPassword())) {
        return new UsernamePasswordAuthentication(username, password, user.getAuthorities());
    }
    throw new BadCredentialsException(":(");
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) UsernamePasswordAuthentication(com.laurentiuspilca.ssc6.security.authentications.UsernamePasswordAuthentication) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException)

Example 54 with User

use of com.laurentiuspilca.ssc6.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);
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) User(com.laurentiuspilca.springsecurityc2.entities.User)

Example 55 with User

use of com.laurentiuspilca.ssc6.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;
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) NotFoundEx(com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx) Client(com.ncedu.fooddelivery.api.v1.entities.Client)

Aggregations

User (com.ncedu.fooddelivery.api.v1.entities.User)58 Test (org.junit.jupiter.api.Test)49 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)49 File (com.ncedu.fooddelivery.api.v1.entities.File)18 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)18 MultipartFile (org.springframework.web.multipart.MultipartFile)18 Path (java.nio.file.Path)16 FileLinkDTO (com.ncedu.fooddelivery.api.v1.dto.file.FileLinkDTO)12 UserInfoDTO (com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO)9 BufferedImage (java.awt.image.BufferedImage)8 CommitAfter (org.apache.tapestry5.jpa.annotations.CommitAfter)7 AlreadyExistsException (com.ncedu.fooddelivery.api.v1.errors.badrequest.AlreadyExistsException)6 PasswordsMismatchException (com.ncedu.fooddelivery.api.v1.errors.badrequest.PasswordsMismatchException)6 PersistenceContext (javax.persistence.PersistenceContext)6 User (org.example.app0.entities.User)6 User (org.example.app1.entities.User)6 User (org.example.app6.entities.User)5 EmailChangeDTO (com.ncedu.fooddelivery.api.v1.dto.user.EmailChangeDTO)4 PasswordChangeDTO (com.ncedu.fooddelivery.api.v1.dto.user.PasswordChangeDTO)4 IOException (java.io.IOException)4