1 package org.oxerr.spring.security.otp.samples.helloworld.web; 2 3 import static org.springframework.web.bind.annotation.RequestMethod.GET; 4 5 import java.io.IOException; 6 7 import javax.annotation.security.RolesAllowed; 8 9 import org.oxerr.spring.security.otp.samples.helloworld.service.impl.OTPAuthenticationServiceImpl; 10 import org.springframework.beans.factory.annotation.Autowired; 11 import org.springframework.security.core.Authentication; 12 import org.springframework.stereotype.Controller; 13 import org.springframework.web.bind.annotation.RequestMapping; 14 import org.springframework.web.servlet.ModelAndView; 15 16 @Controller 17 @RolesAllowed("ROLE_USER") 18 public class GenerateOTPController { 19 20 private final OTPAuthenticationServiceImpl otpAuthenticationServiceImpl; 21 22 @Autowired 23 public GenerateOTPController(OTPAuthenticationServiceImpl otpAuthenticationServiceImpl) { 24 this.otpAuthenticationServiceImpl = otpAuthenticationServiceImpl; 25 } 26 27 @RequestMapping(method = GET, path = "/generate-otp") 28 public ModelAndView getOtp(final Authentication authentication) throws IOException { 29 String otp = this.otpAuthenticationServiceImpl.generateOneTimePassword(authentication); 30 return new ModelAndView("generate-otp", "otp", otp); 31 } 32 33 }