// Path: src/main/java/com/jipasoft/domain/User.java
// @Data
// @Entity
// @Document(collection = "account")
// @Table(name = "account")
// @ToString(exclude = { "password", "authorities" })
// @EqualsAndHashCode(callSuper = true)
// public class User extends AbstractAuditEntity implements Serializable {
// 
// 	private static final long serialVersionUID = 1L;
// 
// 	@Id
// 	@org.springframework.data.annotation.Id
// 	@GeneratedValue(generator = "uuid2")
// 	@GenericGenerator(name = "uuid2", strategy = "uuid2")
// 	private String id;
// 
// 	@NotNull
// 	@Pattern(regexp = "^[a-z0-9]*$|(anonymousUser)")
// 	@Size(min = 1, max = 100)
// 	@Column(unique = true)
// 	private String login;
// 
// 	@NotNull
// 	@Size(min = 60, max = 60)
// 	@Column(name = "password_hash")
// 	@JsonIgnore
// 	private String password;
// 
// 	@Size(max = 50)
// 	@Field("first_name")
// 	private String firstName;
// 
// 	@Size(max = 50)
// 	@Field("last_name")
// 	private String lastName;
// 
// 	@NotNull
// 	@Size(min = 1, max = 100)
// 	@Column(unique = true)
// 	private String email;
// 
// 	@NotNull
// 	private boolean activated = false;
// 
// 	@Size(max = 20)
// 	@Field("activation_key")
// 	@JsonIgnore
// 	private String activationKey;
// 
// 	@Size(max = 20)
// 	@Field("reset_key")
// 	@JsonIgnore
// 	private String resetKey;
// 
// 	@Field("reset_date")
// 	private ZonedDateTime resetDate = null;
// 
// 	@ManyToMany
// 	//@formatter:off
// 	@JoinTable(name = "user_role", inverseJoinColumns = {
// 			@JoinColumn(name = "role_name")
// 		}, joinColumns = {
// 			@JoinColumn(name = "account_id")
// 		}
// 	)
// 	//@formatter:on
// 	private Set<Authority> authorities;
// }
// 
// Path: src/main/java/com/jipasoft/exception/AccountNotActivatedException.java
// public class AccountNotActivatedException extends AuthenticationException {
// 
// 	private static final long serialVersionUID = 8415982426813000504L;
// 
// 	public AccountNotActivatedException(String message) {
// 		super(message);
// 	}
// 
// 	public AccountNotActivatedException(String message, Throwable t) {
// 		super(message, t);
// 	}
// }
// 
// Path: src/main/java/com/jipasoft/repository/UserRepository.java
// @NoRepositoryBean
// public interface UserRepository extends BaseRepository<User, String> {
// 
// 	/**
// 	 * Retrieves a {@link User} entity from the underlying datastore by its
// 	 * ResetKey
// 	 * 
// 	 * @param resetKey
// 	 *            the resetKey
// 	 * @return a User entity
// 	 * @see User#getResetKey()
// 	 */
// 	public Optional<User> findOneByResetKey(String resetKey);
// 
// 	/**
// 	 * Retrieves a {@link User} entity from the underlying datastore by its
// 	 * Email
// 	 * 
// 	 * @param email
// 	 *            the User's email
// 	 * @return a User entity
// 	 * @see User#getEmail()
// 	 */
// 	public Optional<User> findOneByEmail(String email);
// 
// 	/**
// 	 * Retrieves a {@link User} entity from the underlying datastore by its
// 	 * login
// 	 * 
// 	 * @param login
// 	 *            the username
// 	 * @return a User entity
// 	 * @see User#getLogin()
// 	 */
// 	public Optional<User> findOneByLogin(String login);
// 
// }


import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.inject.Provider;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jipasoft.domain.User;
import com.jipasoft.exception.AccountNotActivatedException;
import com.jipasoft.repository.UserRepository;
import lombok.extern.slf4j.Slf4j;
package com.jipasoft.service.Impl;






@Slf4j
@Service
@Transactional(readOnly = true)
public class UserDetailsServiceImpl implements UserDetailsService {
	@Inject
	private Provider<UserRepository> userRepositoryProvider;

	@Override
	public UserDetails loadUserByUsername(final String login) throws UsernameNotFoundException, AccountNotActivatedException {
		log.debug("Authenticating {}", login);
		String lowercaseLogin = login.toLowerCase();
		Optional<User> userFromDatabase = userRepositoryProvider.get().findOneByLogin(lowercaseLogin);

		return userFromDatabase.map(user -> {
			if (!user.isActivated()) {
// Path: src/main/java/com/jipasoft/domain/User.java
// @Data
// @Entity
// @Document(collection = "account")
// @Table(name = "account")
// @ToString(exclude = { "password", "authorities" })
// @EqualsAndHashCode(callSuper = true)
// public class User extends AbstractAuditEntity implements Serializable {
// 
// 	private static final long serialVersionUID = 1L;
// 
// 	@Id
// 	@org.springframework.data.annotation.Id
// 	@GeneratedValue(generator = "uuid2")
// 	@GenericGenerator(name = "uuid2", strategy = "uuid2")
// 	private String id;
// 
// 	@NotNull
// 	@Pattern(regexp = "^[a-z0-9]*$|(anonymousUser)")
// 	@Size(min = 1, max = 100)
// 	@Column(unique = true)
// 	private String login;
// 
// 	@NotNull
// 	@Size(min = 60, max = 60)
// 	@Column(name = "password_hash")
// 	@JsonIgnore
// 	private String password;
// 
// 	@Size(max = 50)
// 	@Field("first_name")
// 	private String firstName;
// 
// 	@Size(max = 50)
// 	@Field("last_name")
// 	private String lastName;
// 
// 	@NotNull
// 	@Size(min = 1, max = 100)
// 	@Column(unique = true)
// 	private String email;
// 
// 	@NotNull
// 	private boolean activated = false;
// 
// 	@Size(max = 20)
// 	@Field("activation_key")
// 	@JsonIgnore
// 	private String activationKey;
// 
// 	@Size(max = 20)
// 	@Field("reset_key")
// 	@JsonIgnore
// 	private String resetKey;
// 
// 	@Field("reset_date")
// 	private ZonedDateTime resetDate = null;
// 
// 	@ManyToMany
// 	//@formatter:off
// 	@JoinTable(name = "user_role", inverseJoinColumns = {
// 			@JoinColumn(name = "role_name")
// 		}, joinColumns = {
// 			@JoinColumn(name = "account_id")
// 		}
// 	)
// 	//@formatter:on
// 	private Set<Authority> authorities;
// }
// 
// Path: src/main/java/com/jipasoft/exception/AccountNotActivatedException.java
// public class AccountNotActivatedException extends AuthenticationException {
// 
// 	private static final long serialVersionUID = 8415982426813000504L;
// 
// 	public AccountNotActivatedException(String message) {
// 		super(message);
// 	}
// 
// 	public AccountNotActivatedException(String message, Throwable t) {
// 		super(message, t);
// 	}
// }
// 
// Path: src/main/java/com/jipasoft/repository/UserRepository.java
// @NoRepositoryBean
// public interface UserRepository extends BaseRepository<User, String> {
// 
// 	/**
// 	 * Retrieves a {@link User} entity from the underlying datastore by its
// 	 * ResetKey
// 	 * 
// 	 * @param resetKey
// 	 *            the resetKey
// 	 * @return a User entity
// 	 * @see User#getResetKey()
// 	 */
// 	public Optional<User> findOneByResetKey(String resetKey);
// 
// 	/**
// 	 * Retrieves a {@link User} entity from the underlying datastore by its
// 	 * Email
// 	 * 
// 	 * @param email
// 	 *            the User's email
// 	 * @return a User entity
// 	 * @see User#getEmail()
// 	 */
// 	public Optional<User> findOneByEmail(String email);
// 
// 	/**
// 	 * Retrieves a {@link User} entity from the underlying datastore by its
// 	 * login
// 	 * 
// 	 * @param login
// 	 *            the username
// 	 * @return a User entity
// 	 * @see User#getLogin()
// 	 */
// 	public Optional<User> findOneByLogin(String login);
// 
// }


// Path: src/main/java/com/jipasoft/service/Impl/UserDetailsServiceImpl.java
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.inject.Provider;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jipasoft.domain.User;
import com.jipasoft.exception.AccountNotActivatedException;
import com.jipasoft.repository.UserRepository;
import lombok.extern.slf4j.Slf4j;

package com.jipasoft.service.Impl;






@Slf4j
@Service
@Transactional(readOnly = true)
public class UserDetailsServiceImpl implements UserDetailsService {
	@Inject
	private Provider<UserRepository> userRepositoryProvider;

	@Override
	public UserDetails loadUserByUsername(final String login) throws UsernameNotFoundException, AccountNotActivatedException {
		log.debug("Authenticating {}", login);
		String lowercaseLogin = login.toLowerCase();
		Optional<User> userFromDatabase = userRepositoryProvider.get().findOneByLogin(lowercaseLogin);

		return userFromDatabase.map(user -> {
			if (!user.isActivated()) {
				throw new AccountNotActivatedException(String.format("User %s is not activated", lowercaseLogin));