All Downloads are FREE. Search and download functionalities are using the official Maven repository.

am.ik.home.member.MemberUserDetailsService Maven / Gradle / Ivy

Go to download

Single tenant simple OAuth 2 Server a.k.a. Maki UAA (User Account and Authentication)

The newest version!
package am.ik.home.member;

import java.util.Optional;

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.Component;

@Component
public class MemberUserDetailsService implements UserDetailsService {
	private final MemberRepository memberRepository;

	public MemberUserDetailsService(MemberRepository memberRepository) {
		this.memberRepository = memberRepository;
	}

	@Override
	public UserDetails loadUserByUsername(String username)
			throws UsernameNotFoundException {
		Optional member = username.contains("@")
				? memberRepository.findByEmail(username)
				: memberRepository.findOne(username);
		return member.map(MemberUserDetails::new)
				.orElseThrow(() -> new UsernameNotFoundException("not found"));
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy