forked from mastifikator/FantasyJavaPatterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckAuthorization.java
More file actions
29 lines (24 loc) · 956 Bytes
/
Copy pathCheckAuthorization.java
File metadata and controls
29 lines (24 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package ChainOfResponsibility;
import java.util.HashMap;
import java.util.Map;
public class CheckAuthorization implements ICheck {
Map<String, String> authorizations = new HashMap<String, String>();
private User user;
public CheckAuthorization(User user) {
this.user = user;
authorizations.put("admin", "admin");
authorizations.put("user", "123456");
authorizations.put("hacker", "654321");
}
@Override
public User check(){
if(user == null) return null;
if(authorizations.containsKey(user.getName()) && authorizations.get(user.getName()).equals(user.getPass())){
System.out.println("Пользователь " + user.getName() + " авторизован.");
return user;
}else {
System.out.println("Пользователь " + user.getName() + " не прошел авторизацию.");
return null;
}
}
}