| | |
| | | @Service |
| | | @Transactional |
| | | public class CustomerAuthService { |
| | | |
| | | |
| | | @Autowired |
| | | AuthenticationManagerBuilder authenticationManagerBuilder; |
| | | |
| | | |
| | | @Autowired |
| | | CustomerRepository customerRepository; |
| | | |
| | | @Autowired |
| | | TokenProvider tokenProvider; |
| | | |
| | | |
| | | public String authorize(Customer account, String indexKey, String otpCode) { |
| | | OtpAccount otpAccount = OtpAccount.createOtpAccount(account, indexKey); |
| | | OtpAuthenticationToken authenticationToken = new OtpAuthenticationToken( |
| | |
| | | ); |
| | | |
| | | SecurityContextHolder.getContext().setAuthentication(authenticationToken); |
| | | |
| | | |
| | | Authentication authentication = buildCustomerAuthToken(account, otpCode, indexKey); |
| | | String jwt = tokenProvider.createToken(authentication, false); |
| | | return jwt; |
| | | } |
| | | |
| | | |
| | | public UsernamePasswordAuthenticationToken buildCustomerAuthToken(Customer customer |
| | | , String otpCode, String indexKey) { |
| | | |
| | | |
| | | List<GrantedAuthority> grantedAuths = Arrays.asList(new SimpleGrantedAuthority("ROLE_USER")); |
| | | |
| | | |
| | | final String account = customer.toAccountString(); |
| | | UsernamePasswordAuthenticationToken authenticationToken = |
| | | UsernamePasswordAuthenticationToken authenticationToken = |
| | | new UsernamePasswordAuthenticationToken(account, otpCode, grantedAuths); |
| | | |
| | | Map<String, String> details = new HashMap<>(); |
| | | details.put(CustomerDetailEnum.ID.getValue(), customer.getId().toString()); |
| | | details.put(CustomerDetailEnum.DB_ID.getValue(), customer.getId().toString()); |
| | | details.put(CustomerDetailEnum.NAME.getValue(), customer.getName()); |
| | | details.put(CustomerDetailEnum.ACCOUNT.getValue(), account); |
| | | // details.put(CustomerDetailEnum.CONTACT_TYPE.getValue(), customer.getContactType()); |
| | | |
| | | authenticationToken.setDetails(details); |
| | | |
| | | return authenticationToken; |