use of springfive.airline.authservice.domain.data.CredentialData in project Spring-5.0-By-Example by PacktPublishing.
the class AuthenticationService method authenticate.
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String nickname = authentication.getName();
String password = (String) authentication.getCredentials();
CredentialData credentialData = this.credentialUserDetailsService.loadUserByUsername(nickname);
if (Objects.isNull(credentialData) || !credentialData.getEmail().equalsIgnoreCase(nickname)) {
throw new BadCredentialsException("email not found or invalid.");
}
if (!password.equals(credentialData.getPassword())) {
throw new BadCredentialsException("wrong password.");
}
return new UsernamePasswordAuthenticationToken(credentialData, password, credentialData.getAuthorities());
}
Aggregations