Last active
August 29, 2015 14:25
-
-
Save koert/28bfa07cbc5623e1c248 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Repository for authentication. | |
| * @author Koert Zeilstra | |
| */ | |
| @ApplicationScoped | |
| public class AuthenticationRepository { | |
| private Map<String, AuthenticationToken> tokenCache = new HashMap<>(); | |
| public Optional<AuthenticationToken> authenticateUser(String userName, String password) { | |
| Optional<AuthenticationToken> result = Optional.empty(); | |
| if ("test".equals(userName) && "welcome".equals(password)) { | |
| AuthenticationToken token = createAuthenticationToken(userName); | |
| result = Optional.of(token); | |
| } | |
| return result; | |
| } | |
| public AuthenticationToken authenticateUser2(String userName, String password) { | |
| AuthenticationToken result = null; | |
| if ("test".equals(userName) && "welcome".equals(password)) { | |
| result = createAuthenticationToken(userName); | |
| } | |
| return result; | |
| } | |
| /** | |
| * @param userName User name. | |
| * @return New authentication token. | |
| */ | |
| public AuthenticationToken createAuthenticationToken(String userName) { | |
| UUID uuid = UUID.randomUUID(); | |
| LocalDateTime date = LocalDateTime.now().plusHours(8); | |
| Set<String> roles = new HashSet<>(); | |
| User user = new User(userName, "Test", roles); | |
| AuthenticationToken token = new AuthenticationToken(uuid.toString(), date, user); | |
| tokenCache.put(token.getId(), token); | |
| return token; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment