Advertisement
Guest User

LOR-5817442-sample-in-java

a guest
Feb 1st, 2011
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.76 KB | None | 0 0
  1. public class Login
  2. {
  3.   public void login(Request request,
  4.     String login,
  5.     String password)
  6.   {
  7.     if( login == null || password == null ) respond(UNAUTHORIZED, "You should provide login and password");
  8.     else
  9.     {
  10.       UserInfo user = AccountsStorage.find(login);
  11.       if(user == null)
  12.         respond(UNAUTHORIZED, "User not found");
  13.       else if(user != null && user.inactive)
  14.         respond(UNAUTHORIZED, "Account is inactive");
  15.       else if(user != null && user.authScheme.equals("PETRIVKA"))
  16.       {
  17.         if( user.passwordMatches(password) ) request.storeInSession("user", user);
  18.         else respond(UNAUTHORIZED, "Authentication failed");
  19.       }
  20.       else if(user != null)
  21.       {
  22.         AuthScheme scheme = AccessStorage.find(user.authScheme);
  23.         if(scheme == null)
  24.           respond(FORBIDDEN, "Unknown authentication scheme: " + user.authScheme);
  25.         else
  26.           {
  27.             int waitFor = 0;
  28.             if( waitFor == 0 ) request.storeInSession("user", user );
  29.             else respond(UNAUTHORIZED, "Authentication within " + scheme.key + " failed");
  30.           }
  31.       }
  32.       else
  33.         respond(UNAUTHORIZED, "Authentication failed");
  34.     }
  35.   }
  36.  
  37.   private final void respond(int code, String description) {}
  38.  
  39.   private static final int UNAUTHORIZED = 1;
  40.   private static final int FORBIDDEN = 2;
  41. }
  42.  
  43. class Request
  44. {
  45.   final void storeInSession(String key, Object what) {}
  46. }
  47.  
  48. class AccountsStorage
  49. {
  50.    static UserInfo find(String name) { return null; }
  51. }
  52.  
  53. class UserInfo
  54. {
  55.   boolean inactive;
  56.   String authScheme;
  57.  
  58.   final boolean passwordMatches(String psw) { return false; }
  59. }
  60.  
  61. class AccessStorage
  62. {
  63.   static AuthScheme find(String name) { return null; }
  64. }
  65.  
  66. class AuthScheme
  67. {
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement