1 package org.oxerr.spring.security.otp.samples.helloworld.service.impl;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import org.apache.commons.lang3.RandomStringUtils;
7 import org.oxerr.spring.security.otp.core.OTPAuthenticationService;
8 import org.springframework.security.core.Authentication;
9 import org.springframework.security.core.AuthenticationException;
10
11 public class OTPAuthenticationServiceImpl implements OTPAuthenticationService {
12
13 private final Map<String, Authentication> store = new HashMap<>();
14
15 @Override
16 public Authentication loadAuthenticationByOneTimePassword(String oneTimePassword) throws AuthenticationException {
17 return store.get(oneTimePassword);
18 }
19
20 public String generateOneTimePassword(Authentication authentication) {
21 String oneTimePassword = RandomStringUtils.randomAlphabetic(8);
22 store.put(oneTimePassword, authentication);
23 return oneTimePassword;
24 }
25
26 }