Search in sources :

Example 1 with EmailValidator

use of org.hibernate.validator.internal.constraintvalidators.hv.EmailValidator in project jhipster-sample-app-dto by jhipster.

the class DomainUserDetailsService method loadUserByUsername.

@Override
@Transactional
public UserDetails loadUserByUsername(final String login) {
    log.debug("Authenticating {}", login);
    if (new EmailValidator().isValid(login, null)) {
        Optional<User> userByEmailFromDatabase = userRepository.findOneWithAuthoritiesByEmail(login);
        return userByEmailFromDatabase.map(user -> createSpringSecurityUser(login, user)).orElseThrow(() -> new UsernameNotFoundException("User with email " + login + " was not found in the database"));
    }
    String lowercaseLogin = login.toLowerCase(Locale.ENGLISH);
    Optional<User> userByLoginFromDatabase = userRepository.findOneWithAuthoritiesByLogin(lowercaseLogin);
    return userByLoginFromDatabase.map(user -> createSpringSecurityUser(lowercaseLogin, user)).orElseThrow(() -> new UsernameNotFoundException("User " + lowercaseLogin + " was not found in the database"));
}
Also used : EmailValidator(org.hibernate.validator.internal.constraintvalidators.hv.EmailValidator) java.util(java.util) UserRepository(io.github.jhipster.sample.repository.UserRepository) Logger(org.slf4j.Logger) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) LoggerFactory(org.slf4j.LoggerFactory) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) Collectors(java.util.stream.Collectors) GrantedAuthority(org.springframework.security.core.GrantedAuthority) User(io.github.jhipster.sample.domain.User) Component(org.springframework.stereotype.Component) UserDetails(org.springframework.security.core.userdetails.UserDetails) Transactional(org.springframework.transaction.annotation.Transactional) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) EmailValidator(org.hibernate.validator.internal.constraintvalidators.hv.EmailValidator) User(io.github.jhipster.sample.domain.User) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with EmailValidator

use of org.hibernate.validator.internal.constraintvalidators.hv.EmailValidator in project jhipster-sample-app-websocket by jhipster.

the class DomainUserDetailsService method loadUserByUsername.

@Override
@Transactional
public UserDetails loadUserByUsername(final String login) {
    log.debug("Authenticating {}", login);
    if (new EmailValidator().isValid(login, null)) {
        Optional<User> userByEmailFromDatabase = userRepository.findOneWithAuthoritiesByEmail(login);
        return userByEmailFromDatabase.map(user -> createSpringSecurityUser(login, user)).orElseThrow(() -> new UsernameNotFoundException("User with email " + login + " was not found in the database"));
    }
    String lowercaseLogin = login.toLowerCase(Locale.ENGLISH);
    Optional<User> userByLoginFromDatabase = userRepository.findOneWithAuthoritiesByLogin(lowercaseLogin);
    return userByLoginFromDatabase.map(user -> createSpringSecurityUser(lowercaseLogin, user)).orElseThrow(() -> new UsernameNotFoundException("User " + lowercaseLogin + " was not found in the database"));
}
Also used : EmailValidator(org.hibernate.validator.internal.constraintvalidators.hv.EmailValidator) java.util(java.util) UserRepository(io.github.jhipster.sample.repository.UserRepository) Logger(org.slf4j.Logger) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) LoggerFactory(org.slf4j.LoggerFactory) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) Collectors(java.util.stream.Collectors) GrantedAuthority(org.springframework.security.core.GrantedAuthority) User(io.github.jhipster.sample.domain.User) Component(org.springframework.stereotype.Component) UserDetails(org.springframework.security.core.userdetails.UserDetails) Transactional(org.springframework.transaction.annotation.Transactional) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) EmailValidator(org.hibernate.validator.internal.constraintvalidators.hv.EmailValidator) User(io.github.jhipster.sample.domain.User) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with EmailValidator

use of org.hibernate.validator.internal.constraintvalidators.hv.EmailValidator in project jhipster-sample-app-elasticsearch by jhipster.

the class DomainUserDetailsService method loadUserByUsername.

@Override
@Transactional
public UserDetails loadUserByUsername(final String login) {
    log.debug("Authenticating {}", login);
    if (new EmailValidator().isValid(login, null)) {
        Optional<User> userByEmailFromDatabase = userRepository.findOneWithAuthoritiesByEmail(login);
        return userByEmailFromDatabase.map(user -> createSpringSecurityUser(login, user)).orElseThrow(() -> new UsernameNotFoundException("User with email " + login + " was not found in the database"));
    }
    String lowercaseLogin = login.toLowerCase(Locale.ENGLISH);
    Optional<User> userByLoginFromDatabase = userRepository.findOneWithAuthoritiesByLogin(lowercaseLogin);
    return userByLoginFromDatabase.map(user -> createSpringSecurityUser(lowercaseLogin, user)).orElseThrow(() -> new UsernameNotFoundException("User " + lowercaseLogin + " was not found in the database"));
}
Also used : EmailValidator(org.hibernate.validator.internal.constraintvalidators.hv.EmailValidator) java.util(java.util) UserRepository(io.github.jhipster.sample.repository.UserRepository) Logger(org.slf4j.Logger) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) LoggerFactory(org.slf4j.LoggerFactory) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) Collectors(java.util.stream.Collectors) GrantedAuthority(org.springframework.security.core.GrantedAuthority) User(io.github.jhipster.sample.domain.User) Component(org.springframework.stereotype.Component) UserDetails(org.springframework.security.core.userdetails.UserDetails) Transactional(org.springframework.transaction.annotation.Transactional) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) EmailValidator(org.hibernate.validator.internal.constraintvalidators.hv.EmailValidator) User(io.github.jhipster.sample.domain.User) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with EmailValidator

use of org.hibernate.validator.internal.constraintvalidators.hv.EmailValidator in project jhipster-sample-app-mongodb by jhipster.

the class DomainUserDetailsService method loadUserByUsername.

@Override
public UserDetails loadUserByUsername(final String login) {
    log.debug("Authenticating {}", login);
    if (new EmailValidator().isValid(login, null)) {
        Optional<User> userByEmailFromDatabase = userRepository.findOneByEmailIgnoreCase(login);
        return userByEmailFromDatabase.map(user -> createSpringSecurityUser(login, user)).orElseThrow(() -> new UsernameNotFoundException("User with email " + login + " was not found in the database"));
    }
    String lowercaseLogin = login.toLowerCase(Locale.ENGLISH);
    Optional<User> userByLoginFromDatabase = userRepository.findOneByLogin(lowercaseLogin);
    return userByLoginFromDatabase.map(user -> createSpringSecurityUser(lowercaseLogin, user)).orElseThrow(() -> new UsernameNotFoundException("User " + lowercaseLogin + " was not found in the database"));
}
Also used : EmailValidator(org.hibernate.validator.internal.constraintvalidators.hv.EmailValidator) java.util(java.util) UserRepository(io.github.jhipster.sample.repository.UserRepository) Logger(org.slf4j.Logger) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) LoggerFactory(org.slf4j.LoggerFactory) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) Collectors(java.util.stream.Collectors) GrantedAuthority(org.springframework.security.core.GrantedAuthority) User(io.github.jhipster.sample.domain.User) Component(org.springframework.stereotype.Component) UserDetails(org.springframework.security.core.userdetails.UserDetails) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) EmailValidator(org.hibernate.validator.internal.constraintvalidators.hv.EmailValidator) User(io.github.jhipster.sample.domain.User)

Example 5 with EmailValidator

use of org.hibernate.validator.internal.constraintvalidators.hv.EmailValidator in project jhipster-sample-app-hazelcast by jhipster.

the class DomainUserDetailsService method loadUserByUsername.

@Override
@Transactional
public UserDetails loadUserByUsername(final String login) {
    log.debug("Authenticating {}", login);
    if (new EmailValidator().isValid(login, null)) {
        Optional<User> userByEmailFromDatabase = userRepository.findOneWithAuthoritiesByEmail(login);
        return userByEmailFromDatabase.map(user -> createSpringSecurityUser(login, user)).orElseThrow(() -> new UsernameNotFoundException("User with email " + login + " was not found in the database"));
    }
    String lowercaseLogin = login.toLowerCase(Locale.ENGLISH);
    Optional<User> userByLoginFromDatabase = userRepository.findOneWithAuthoritiesByLogin(lowercaseLogin);
    return userByLoginFromDatabase.map(user -> createSpringSecurityUser(lowercaseLogin, user)).orElseThrow(() -> new UsernameNotFoundException("User " + lowercaseLogin + " was not found in the database"));
}
Also used : EmailValidator(org.hibernate.validator.internal.constraintvalidators.hv.EmailValidator) java.util(java.util) UserRepository(io.github.jhipster.sample.repository.UserRepository) Logger(org.slf4j.Logger) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) LoggerFactory(org.slf4j.LoggerFactory) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) Collectors(java.util.stream.Collectors) GrantedAuthority(org.springframework.security.core.GrantedAuthority) User(io.github.jhipster.sample.domain.User) Component(org.springframework.stereotype.Component) UserDetails(org.springframework.security.core.userdetails.UserDetails) Transactional(org.springframework.transaction.annotation.Transactional) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) EmailValidator(org.hibernate.validator.internal.constraintvalidators.hv.EmailValidator) User(io.github.jhipster.sample.domain.User) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

User (io.github.jhipster.sample.domain.User)6 UserRepository (io.github.jhipster.sample.repository.UserRepository)6 java.util (java.util)6 Collectors (java.util.stream.Collectors)6 EmailValidator (org.hibernate.validator.internal.constraintvalidators.hv.EmailValidator)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 GrantedAuthority (org.springframework.security.core.GrantedAuthority)6 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)6 UserDetails (org.springframework.security.core.userdetails.UserDetails)6 UserDetailsService (org.springframework.security.core.userdetails.UserDetailsService)6 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)6 Component (org.springframework.stereotype.Component)6 Transactional (org.springframework.transaction.annotation.Transactional)4