Created
December 13, 2018 15:10
-
-
Save eldermoraes/084fcf6de06f4b17ffb078fa10018b5c to your computer and use it in GitHub Desktop.
This file contains 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
@ApplicationScoped | |
public class AuthSession { | |
private Map<String, Auth> authenticated; | |
private Map<String, Auth> dataSource; | |
@PostConstruct | |
public void init() { | |
authenticated = new HashMap<>(); | |
dataSource = new HashMap<>(); | |
for (int i = 1; i <= 50; i++) { | |
dataSource.put("login" + i, new Auth("login" + i, "123456")); | |
} | |
} | |
public AuthSession putAuthenticated(String key, Auth auth) { | |
authenticated.put(key, auth); | |
return this; | |
} | |
public AuthSession removeAuthenticated(String key, Auth auth) { | |
authenticated.remove(key, auth); | |
return this; | |
} | |
public Map<String, Auth> getAuthenticated() { | |
return authenticated; | |
} | |
public Map<String, Auth> getDataSource() { | |
return dataSource; | |
} | |
public Optional<String> getToken(String login, String password) { | |
for (String key : authenticated.keySet()) { | |
Auth auth = authenticated.get(key); | |
if (auth.getLogin().equals(login) | |
&& auth.getPassword().equals(password)) { | |
return Optional.of(key); | |
} | |
} | |
return Optional.empty(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment