Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | None | 0 0
  1. package com.jw.lab3.data;
  2.  
  3. import com.jw.lab3.data.model.LoggedInUser;
  4.  
  5. import java.io.IOException;
  6. import java.lang.reflect.Array;
  7. import java.util.ArrayList;
  8. import java.util.Arrays;
  9. import java.util.List;
  10.  
  11. /**
  12.  * Class that handles authentication w/ login credentials and retrieves user information.
  13.  */
  14. public class LoginDataSource {
  15.  
  16.     private List<String> DUMMY_CREDENTIALS = new ArrayList<>();
  17.  
  18.     public LoginDataSource() {
  19.         DUMMY_CREDENTIALS.add("admin");
  20.         DUMMY_CREDENTIALS.add("admin");
  21.     }
  22.  
  23.     public Result<LoggedInUser> login(String username, String password) {
  24.  
  25.         try {
  26.             // TODO: handle loggedInUser authentication
  27.  
  28.             if (DUMMY_CREDENTIALS.contains(username) && DUMMY_CREDENTIALS.contains(password)) {
  29.                 LoggedInUser fakeUser =
  30.                         new LoggedInUser(
  31.                                 java.util.UUID.randomUUID().toString(),
  32.                                 username);
  33.                 return new Result.Success<>(fakeUser);
  34.             } else {
  35.                 DUMMY_CREDENTIALS.addAll(Arrays.asList(username, password));
  36.                 return new Result.Error(new IOException("Could not log"));
  37.             }
  38.         } catch (Exception e) {
  39.             return new Result.Error(new IOException("Error logging in", e));
  40.         }
  41.     }
  42.  
  43.     public void logout() {
  44.         // TODO: revoke authentication
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement