package com.pollex.pam.service; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; import com.pollex.pam.security.jwt.TokenProvider; import com.pollex.pam.security.token.OtpAuthenticationToken; import com.pollex.pam.web.rest.vm.OtpAccount; @Service public class CustomerAuthService { @Autowired AuthenticationManagerBuilder authenticationManagerBuilder; @Autowired TokenProvider tokenProvider; public String authorize(String account, String indexKey, String otpCode) { OtpAccount otpAccount = new OtpAccount(account, indexKey); OtpAuthenticationToken authenticationToken = new OtpAuthenticationToken( otpAccount, otpCode ); Authentication authentication = authenticationManagerBuilder.getObject().authenticate(authenticationToken); SecurityContextHolder.getContext().setAuthentication(authenticationToken); String jwt = tokenProvider.createToken(authentication, false); return jwt; } }