Search in sources :

Example 1 with CredentialData

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());
}
Also used : CredentialData(springfive.airline.authservice.domain.data.CredentialData) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException)

Aggregations

BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 CredentialData (springfive.airline.authservice.domain.data.CredentialData)1