Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Login
- {
- public void login(Request request,
- String login,
- String password)
- {
- if( login == null || password == null ) respond(UNAUTHORIZED, "You should provide login and password");
- else
- {
- UserInfo user = AccountsStorage.find(login);
- if(user == null)
- respond(UNAUTHORIZED, "User not found");
- else if(user != null && user.inactive)
- respond(UNAUTHORIZED, "Account is inactive");
- else if(user != null && user.authScheme.equals("PETRIVKA"))
- {
- if( user.passwordMatches(password) ) request.storeInSession("user", user);
- else respond(UNAUTHORIZED, "Authentication failed");
- }
- else if(user != null)
- {
- AuthScheme scheme = AccessStorage.find(user.authScheme);
- if(scheme == null)
- respond(FORBIDDEN, "Unknown authentication scheme: " + user.authScheme);
- else
- {
- int waitFor = 0;
- if( waitFor == 0 ) request.storeInSession("user", user );
- else respond(UNAUTHORIZED, "Authentication within " + scheme.key + " failed");
- }
- }
- else
- respond(UNAUTHORIZED, "Authentication failed");
- }
- }
- private final void respond(int code, String description) {}
- private static final int UNAUTHORIZED = 1;
- private static final int FORBIDDEN = 2;
- }
- class Request
- {
- final void storeInSession(String key, Object what) {}
- }
- class AccountsStorage
- {
- static UserInfo find(String name) { return null; }
- }
- class UserInfo
- {
- boolean inactive;
- String authScheme;
- final boolean passwordMatches(String psw) { return false; }
- }
- class AccessStorage
- {
- static AuthScheme find(String name) { return null; }
- }
- class AuthScheme
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement