1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.waarp.ftp.simpleimpl.file;
19
20 import org.waarp.common.logging.WaarpLogger;
21 import org.waarp.common.logging.WaarpLoggerFactory;
22
23
24
25
26
27
28
29 public class SimpleAuth {
30
31
32
33 private static final WaarpLogger logger = WaarpLoggerFactory
34 .getLogger(SimpleAuth.class);
35
36
37
38
39 private String user = null;
40
41
42
43
44 private String password = null;
45
46
47
48
49 private String[] accounts = null;
50
51
52
53
54 private boolean isAdmin = false;
55
56
57
58
59
60
61 public SimpleAuth(String user, String password, String[] accounts) {
62 this.user = user;
63 this.password = password;
64 this.accounts = accounts;
65 }
66
67
68
69
70
71
72
73 public boolean isPasswordValid(String newpassword) {
74 if (password == null) {
75 return true;
76 }
77 if (newpassword == null) {
78 return false;
79 }
80 return password.equals(newpassword);
81 }
82
83
84
85
86
87
88
89 public boolean isAccountValid(String account) {
90 if (accounts == null) {
91 logger.debug("No account needed");
92 return true;
93 }
94 if (account == null) {
95 logger.debug("No account given");
96 return false;
97 }
98 for (String acct : accounts) {
99 if (acct.equals(account)) {
100 logger.debug("Account found");
101 return true;
102 }
103 }
104 logger.debug("No account found");
105 return false;
106 }
107
108
109
110
111
112
113 public void setAdmin(boolean isAdmin) {
114 this.isAdmin = isAdmin;
115 }
116
117
118
119
120 public boolean isAdmin() {
121 return isAdmin;
122 }
123
124
125
126
127 public String getUser() {
128 return user;
129 }
130 }