| | |
| | | package com.moral.security.auth.login; |
| | | |
| | | import com.moral.entity.Account; |
| | | import com.moral.security.exceptions.AccountExpiredBadCredentialsException; |
| | | import com.moral.security.model.UserContext; |
| | | import com.moral.service.AccountService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.Assert; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | String password = (String) authentication.getCredentials(); |
| | | LoginMode mode = (LoginMode) authentication.getDetails(); |
| | | Account account = accountService.queryAccountByName(accountName).orElseThrow(() -> new UsernameNotFoundException("User not found: " + accountName)); |
| | | Date expireTime = Optional.ofNullable(account.getExpireTime()) |
| | | .orElseThrow( |
| | | ()-> new AccountExpiredBadCredentialsException("Authentication Failed. Account has expired.") |
| | | ); |
| | | Date nowTime = new Date(); |
| | | if(expireTime.getTime()<nowTime.getTime()){ |
| | | throw new AccountExpiredBadCredentialsException("Authentication Failed. Account has expired."); |
| | | } |
| | | if (!encoder.matches(password, account.getPassword())) { |
| | | throw new BadCredentialsException("Authentication Failed. Username or Password not valid."); |
| | | } |