/
Application.java
1394 lines (1312 loc) · 48.6 KB
/
Application.java
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package org.jenkinsci.account;
import com.captcha.botdetect.web.servlet.Captcha;
import com.google.common.net.InetAddresses;
import jakarta.mail.Authenticator;
import jakarta.mail.Message;
import jakarta.mail.MessagingException;
import jakarta.mail.PasswordAuthentication;
import jakarta.mail.Session;
import jakarta.mail.Transport;
import jakarta.mail.internet.InternetAddress;
import jakarta.mail.internet.MimeMessage;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import javax.annotation.CheckForNull;
import javax.naming.AuthenticationException;
import javax.naming.Context;
import javax.naming.NameAlreadyBoundException;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.AttributeInUseException;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
import javax.servlet.http.Cookie;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.account.openid.JenkinsOpenIDServer;
import org.kohsuke.stapler.Header;
import org.kohsuke.stapler.HttpRedirect;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.HttpResponses;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import static javax.naming.directory.DirContext.ADD_ATTRIBUTE;
import static javax.naming.directory.DirContext.REMOVE_ATTRIBUTE;
import static javax.naming.directory.DirContext.REPLACE_ATTRIBUTE;
import static javax.naming.directory.SearchControls.SUBTREE_SCOPE;
import static org.apache.commons.lang.StringUtils.isEmpty;
import static org.jenkinsci.account.LdapAbuse.REGISTRATION_DATE;
import static org.jenkinsci.account.LdapAbuse.SENIOR_STATUS;
/**
* Root of the account application.
*
* @author Kohsuke Kawaguchi
*/
public class Application {
/**
* Configuration parameter.
*/
private final Parameters params;
/**
* For bringing the OpenID server into the URL space.
*/
public final JenkinsOpenIDServer openid;
// not exposing this to UI
/*package*/ final CircuitBreaker circuitBreaker;
public Application(Parameters params) throws Exception {
this.params = params;
this.openid = new JenkinsOpenIDServer(this);
this.circuitBreaker = new CircuitBreaker(params);
}
public String getUrl() {
return params.url();
}
public String showCaptcha(String name){
Captcha captcha = Captcha.load(Stapler.getCurrentRequest(), name);
captcha.setUserInputID("captchaCode");
return captcha.getHtml();
}
/**
* Receives the sign-up form submission.
*/
public HttpResponse doDoSignup(
StaplerRequest request,
StaplerResponse response,
@QueryParameter String userid,
@QueryParameter String firstName,
@QueryParameter String lastName,
@QueryParameter String email,
@QueryParameter String emailconfirm,
@QueryParameter String hp,
@QueryParameter String captchaCode,
@Header("X-Forwarded-For") String ip // client IP
) throws Exception {
ip = extractFirst(ip);
Captcha captcha = Captcha.load(request, "signUpCaptcha");
boolean isHuman = captcha.validate(request.getParameter("captchaCode"));
// Check if userid and email are available before going further
final DirContext con = connect();
try {
if (userid == null || isEmpty(userid))
throw new UserError("UserId is required");
userid = userid.toLowerCase();
Iterator<User> a = searchByWord(userid, con);
if (a.hasNext())
throw new UserError("account "+ getUserById(userid,con).id + " already exist");
a = searchByWord(email, con);
if (a.hasNext())
throw new UserError("email: "+ email + " already exist");
} finally {
con.close();
}
if (!VALID_ID.matcher(userid).matches())
throw new UserError("Invalid user name: "+userid);
if (isEmpty(firstName))
throw new UserError("First name is required");
if (isEmpty(lastName))
throw new UserError("Last name is required");
if (isEmpty(email))
throw new UserError("email is required");
if (!email.equals(emailconfirm))
throw new UserError(String.format("Following emails are not matching: %s - %s", email, emailconfirm));
if(!email.contains("@"))
throw new UserError("Need a valid email address.");
if (!isHuman)
throw new UserError("Captcha mismatch. Please try again and retry a captcha to prove that you are a human");
List<String> blockReasons = new ArrayList<String>();
if(!isEmpty(hp))
blockReasons.add("Honeypot: " + hp);
if(Pattern.matches("(?:^jb\\d+@gmail.com|seo\\d+@)", email)) {
blockReasons.add("BL: email (custom)");
}
if(
(firstName.equalsIgnoreCase("help") && lastName.equalsIgnoreCase("desk")) ||
(firstName.contains("quickbook") || lastName.contains("quickbook"))
) {
blockReasons.add("BL: name (custom)");
}
for (String fragment : USERID_BLACKLIST) {
if(userid.toLowerCase().contains(fragment.toLowerCase())) {
blockReasons.add("BL: userid");
}
}
for (String fragment : IP_BLACKLIST) {
if(ip.startsWith(fragment)) {
blockReasons.add("BL: IP");
}
}
// domain black list
String lm = email.toLowerCase(Locale.ENGLISH);
for (String fragment : EMAIL_BLACKLIST) {
if (lm.contains(fragment.toLowerCase()))
blockReasons.add("BL: email");
}
for(String fragment : NAUGHTY_BLACKLIST) {
if(userid.toLowerCase().contains(fragment.toLowerCase())
|| firstName.toLowerCase().contains(fragment.toLowerCase())
|| lastName.toLowerCase().contains(fragment.toLowerCase())
) {
blockReasons.add("BL: naughty");
}
}
if(checkCookie(request, ALREADY_SIGNED_UP)) {
blockReasons.add("Cookie");
}
if(circuitBreaker.check()) {
blockReasons.add("circuit breaker");
}
String userDetails = userDetails(userid, firstName, lastName, email, ip);
if(!blockReasons.isEmpty()) {
String body = "Rejecting, likely spam:\n\n" + userDetails + "\n\nHTTP Headers\n" +
dumpHeaders(request) + "\n\n" +
"===Block Reasons===\n"
+ String.join("\n", blockReasons) + "\n===================" + "\n\n" +
"IP Void link: http://ipvoid.com/scan/" + ip + "\n\n" +
"To allow this account to be created, click the following link:\n" +
getUrl() + "/admin/signup?userId=" + enc(userid) + "&firstName=" + enc(firstName) + "&lastName=" + enc(lastName) + "&email=" + enc(email) + "\n";
LOGGER.warning(userDetails.replaceAll("\\R", " ") + " signup rejected, likely spam: " + String.join(" / ", blockReasons));
mail("jenkinsci-account-admins@googlegroups.com", "Rejection of a new account creation for " + firstName + " " + lastName, body, "text/plain");
throw new SystemError(SPAM_MESSAGE);
}
String password = createRecord(userid, firstName, lastName, email);
LOGGER.info("User "+userid+" is from "+ip);
mail("jenkinsci-account-admins@googlegroups.com", "New user created for " + userid,
userDetails + "\n\nHTTP Headers\n" +
dumpHeaders(request) + "\n\n" + "Account page: " + getUrl() + "/admin/search?word=" + userid + "\n\nIP Void link: http://ipvoid.com/scan/" + ip + "/\n", "text/plain");
new User(userid,email).mailPassword(password);
Cookie cookie = new Cookie(ALREADY_SIGNED_UP, "1");
cookie.setDomain("accounts.jenkins.io");
cookie.setPath("/");
cookie.setMaxAge(24 * 60 * 60);
response.addCookie(cookie);
return new HttpRedirect("doneMail");
}
private String dumpHeaders(StaplerRequest request) {
Enumeration headerNames = request.getHeaderNames();
StringBuffer buffer = new StringBuffer();
while(headerNames.hasMoreElements()) {
String headerName = (String)headerNames.nextElement();
buffer.append(headerName).append("=").append(request.getHeader(headerName)).append("\n");
}
return buffer.toString();
}
private boolean checkCookie(StaplerRequest request, String x) {
for (Cookie cookie: request.getCookies()) {
if(cookie.getName().equals(ALREADY_SIGNED_UP)) {
return "1".equals(cookie.getValue());
}
}
return false;
}
private void mail(String to, String subject, String body, String encoding) throws MessagingException {
Session s = createJavaMailSession();
MimeMessage msg = new MimeMessage(s);
msg.setSubject(subject);
msg.setFrom(new InternetAddress(String.format("Jenkins Accounts <%s>", params.smtpSender())));
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
msg.setContent(body, encoding);
Transport.send(msg);
}
private String userDetails(String userid, String firstName, String lastName, String email, String ip) {
return String.format(
"ip=%s\nemail=%s\nuserId=%s\nlastName=%s\nfirstName=%s",
ip, email, userid, lastName, firstName);
}
/**
* If IP consists of multiple tokens, like "1.2.3.4, 5.6.7.8" then just extract the first one.
*/
private String extractFirst(String ip) {
if (ip==null) return "127.0.0.1";
int idx = ip.indexOf(",");
if(idx>0) {
for (String xForwardedFor : ip.split(",")) {
if (StringUtils.isNotBlank(xForwardedFor) && !InetAddresses.forString(xForwardedFor).isSiteLocalAddress()) {
return ip;
}
}
}
return ip;
}
private static String enc(String s) throws UnsupportedEncodingException {
return URLEncoder.encode(s,"UTF-8");
}
/**
* Adds the new user entry to LDAP.
*/
public String createRecord(String userid, String firstName, String lastName, String email) throws NamingException {
Attributes attrs = new BasicAttributes();
attrs.put("objectClass", "inetOrgPerson");
attrs.put("givenName", firstName);
attrs.put("sn", lastName);
attrs.put("mail", email);
String password = PasswordUtil.generateRandomPassword();
attrs.put("userPassword", PasswordUtil.hashPassword(password));
attrs.put(REGISTRATION_DATE, new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date()));
attrs.put(SENIOR_STATUS, "N");
final DirContext con = connect();
try {
String fullDN = "cn=" + userid + "," + params.newUserBaseDN();
con.createSubcontext(fullDN, attrs).close();
// add to the right group
try {
con.modifyAttributes("cn=all,ou=groups,dc=jenkins-ci,dc=org",ADD_ATTRIBUTE,new BasicAttributes("member",fullDN));
} catch (AttributeInUseException e) {
// deletes and re-add it to make the case match
con.modifyAttributes("cn=all,ou=groups,dc=jenkins-ci,dc=org",REMOVE_ATTRIBUTE,new BasicAttributes("member",fullDN));
con.modifyAttributes("cn=all,ou=groups,dc=jenkins-ci,dc=org",ADD_ATTRIBUTE,new BasicAttributes("member",fullDN));
}
} catch (NameAlreadyBoundException e) {
throw new UserError("ID "+userid+" is already taken. Perhaps you already have an account imported from legacy java.net? You may try resetting the password.");
} finally {
con.close();
}
LOGGER.info("User "+userid+" signed up: "+email);
return password;
}
/**
* Handles the password reset form submission.
*/
public HttpResponse doDoPasswordReset(@QueryParameter String id, @QueryParameter String reason) throws Exception {
final DirContext con = connect();
if (id.isEmpty())
throw new UserError("No email or user account provided");
try {
Iterator<User> a = searchByWord(id, con);
if (a.hasNext()) {
User u = a.next();
String p = PasswordUtil.generateRandomPassword();
u.modifyPassword(con, p);
u.mailPasswordReset(p, Stapler.getCurrentRequest().getRemoteUser(),
StringUtils.isBlank(reason) ? "request in the account management app" : reason );
}
} finally {
con.close();
}
return new HttpRedirect("resetMail");
}
public User getUserById(String id, DirContext con) throws NamingException {
String dn = "cn=" + id + "," + params.newUserBaseDN();
return new User(con.getAttributes(dn));
}
/**
* Object that represents some user in LDAP.
*/
public class User {
/**
* User ID, such as 'kohsuke'
*/
public final String id;
/**
* Email address.
*/
public final String mail;
public User(String id, String mail) {
this.id = id;
this.mail = mail;
}
public User(Attributes att) throws NamingException {
id = (String) att.get("cn").get();
mail = (String) att.get("mail").get();
}
public String getDn() {
return String.format("cn=%s,%s", id, params.newUserBaseDN());
}
public void modifyPassword(DirContext con, String password) throws NamingException {
con.modifyAttributes(getDn(),REPLACE_ATTRIBUTE,new BasicAttributes("userPassword",PasswordUtil.hashPassword(password)));
LOGGER.info("User "+id+" reset the password: "+mail);
}
public void modifyEmail(DirContext con, String email) throws NamingException {
con.modifyAttributes(getDn(),REPLACE_ATTRIBUTE,new BasicAttributes("mail",email));
LOGGER.info("User "+id+" reset the email address to: "+email);
}
/**
* Sends a new password to this user.
*/
public void mailPassword(String password) throws MessagingException {
mail(mail, "Your access to Jenkins resources", "Your userid is " + id + "\n" +
"Your temporary password is " + password + "\n" +
"\n" +
"Please visit " + getUrl() + " and update your password and profile\n", "text/plain");
}
/**
* Sends a new password to this user.
*/
public void mailAccountCreated(boolean sendPassword, String password, @CheckForNull String message) throws MessagingException {
mail(mail, "New account on the Jenkins project infrastructure",
"Dear recipient, \n\n" +
"We have created a new Jenkins project account for you. Your new user ID is " + id + "\n" +
( sendPassword ? "Your temporary password is " + password + "\n" : "" ) +
( StringUtils.isNotBlank(message) ? message + "\n" : "" ) +
"\n" +
( sendPassword ? "Please visit " + getUrl() + " and update your password and profile\n" : "" ),
"text/plain");
}
/**
* Sends a new password and a password reset notification to this user.
*/
public void mailPasswordReset(String password, @CheckForNull String requestedByUser, @CheckForNull String reason) throws MessagingException {
mail(mail, "Password reset on the Jenkins project infrastructure",
"Your Jenkins account password was reset. " +
(requestedByUser != null ? String.format("It was requested by user %s. ", requestedByUser) : "") +
(StringUtils.isNotBlank(reason) ? String.format("Reason: %s. ", reason) : "") +
"Your userid is " + id + "\n" +
"Your temporary password is " + password + "\n" +
"\n" +
"Please visit " + getUrl() + " and update your password and profile\n", "text/plain");
}
public void delete(DirContext con) throws NamingException {
con.destroySubcontext(getDn());
LOGGER.info("User " + id + " deleted");
}
}
private Session createJavaMailSession() {
Session session;
Properties props = new Properties(System.getProperties());
props.put("mail.smtp.host",params.smtpServer());
props.put("mail.smtp.port", params.smtpPort());
if(params.smtpAuth()) {
props.put("mail.smtp.auth", params.smtpAuth());
props.put("mail.smtp.starttls.enable", true);
session = Session.getInstance(props,
new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(params.smtpUser(), params.smtpPassword());
}
});
} else {
session = Session.getInstance(props);
}
return session;
}
/**
* Search LDAP with the given keyword, returning matching users.
*/
public Iterator<User> searchByWord(String idOrMail, DirContext con) throws NamingException {
final NamingEnumeration<SearchResult> e = con.search(params.newUserBaseDN(), "(|(mail={0})(cn={0}))", new Object[]{idOrMail}, new SearchControls());
return new Iterator<User>() {
public boolean hasNext() {
return e.hasMoreElements();
}
public User next() {
try {
return new User(e.nextElement().getAttributes());
} catch (NamingException x) {
throw new RuntimeException(x);
}
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
public LdapContext connect() throws NamingException {
return connect(params.managerDN(), params.managerPassword());
}
public LdapContext connect(String dn, String password) throws NamingException {
Hashtable<String,String> env = new Hashtable<String,String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, params.server());
env.put(Context.SECURITY_PRINCIPAL, dn);
env.put(Context.SECURITY_CREDENTIALS, password);
return new InitialLdapContext(env, null);
}
/**
* Handles the login form submission.
*/
public HttpResponse doDoLogin(
@QueryParameter String userid,
@QueryParameter String password,
@QueryParameter String from
) {
login(userid, password);
// to limit the redirect to this application, require that the from URL starts from '/'
if (from==null || !from.startsWith("/")) from="/";
return HttpResponses.redirectTo(from);
}
private Myself login(String userid, String password) throws UserError {
if (StringUtils.isBlank(userid)) {
throw new UserError("Missing username");
}
if (StringUtils.isBlank(password)) {
throw new UserError("Missing password");
}
String dn = "cn=" + userid + "," + params.newUserBaseDN();
try {
LdapContext context = connect(dn, password); // make sure the password is valid
try {
Myself myself = new Myself(this, dn, context.getAttributes(dn), getGroups(dn,context));
Stapler.getCurrentRequest().getSession().setAttribute(Myself.class.getName(), myself);
return myself;
} finally {
context.close();
}
} catch (AuthenticationException e) {
throw new UserError(String.format("User \"%s\" not found or password incorrect %n", userid) );
} catch (Exception e) {
String errorId = String.valueOf(Math.round(Math.random() * 1e8));
LOGGER.log(Level.SEVERE, "Login error " + errorId, e);
throw new UserError("Something went wrong. Please try again later.", errorId);
}
}
/**
* Obtains the group of the user specified by the given DN.
*/
Set<String> getGroups(String dn, LdapContext context) throws NamingException {
Set<String> groups = new HashSet<String>();
SearchControls c = new SearchControls();
c.setReturningAttributes(new String[]{"cn"});
c.setSearchScope(SUBTREE_SCOPE);
NamingEnumeration<SearchResult> e = context.search("dc=jenkins-ci,dc=org", "(& (objectClass=groupOfNames) (member={0}))", new Object[]{dn}, c);
while (e.hasMore()) {
groups.add(e.nextElement().getAttributes().get("cn").get().toString());
}
return groups;
}
public HttpResponse doLogout(StaplerRequest req) {
req.getSession().invalidate();
return HttpResponses.redirectToDot();
}
public boolean isLoggedIn() {
return Myself.current() !=null;
}
public boolean isAdmin() {
Myself myself = Myself.current();
return myself !=null && myself.isAdmin();
}
/**
* If the user has already logged in, retrieve the current user, otherwise
* send the user to the login page.
*/
public Myself getMyself() {
Myself myself = Myself.current();
if (myself == null) {
return needToLogin();
}
return myself;
}
private Myself needToLogin() {
// needs to login
StaplerRequest req = Stapler.getCurrentRequest();
String authHeader = req.getHeader("Authorization");
if (authHeader != null) { // Basic auth
if (!authHeader.startsWith("Basic")) {
throw HttpResponses.error(403, "Only Basic authentication is supported");
}
byte[] userPasswordBytes = Base64.getDecoder().decode(authHeader.trim().substring(6));
String[] res = new String(userPasswordBytes).split(":");
String user = res[0];
String password = res[1];
return login(user, password).withRESTAuthentication(true);
}
StringBuilder from = new StringBuilder(req.getRequestURI());
if (req.getQueryString()!=null)
from.append('?').append(req.getQueryString());
try {
throw HttpResponses.redirectViaContextPath("login?from="+ URLEncoder.encode(from.toString(),"UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
}
/**
* This is a test endpoint to make sure the reverse proxy forwarding is working.
*/
public HttpResponse doForwardTest(@Header("X-Forwarded-For") String header) {
return HttpResponses.plainText(header);
}
public AdminUI getAdmin() {
if (!getMyself().isAdmin()) {
throw HttpResponses.forbidden();
}
return new AdminUI(this);
}
private static final Logger LOGGER = Logger.getLogger(Application.class.getName());
private static final Pattern VALID_ID = Pattern.compile("[a-z0-9_]+");
public static final List<String> EMAIL_BLACKLIST = Arrays.asList(
// TODO: Integrate with https://github.com/wesbos/burner-email-providers
// Also can use this to check if disposable service: http://www.block-disposable-email.com/cms/try/
"@akglsgroup.com",
"@anappthat.com",
"@boximail.com",
"@clrmail.com",
"@dodsi.com",
"@eelmail.com",
"@getairmail.com",
"@grandmamail.com",
"@grandmasmail.com",
"@guerrillamail.com",
"@imgof.com",
"@mailcatch.com",
"@maildx.com",
"@mailinator.com",
"@mailnesia.com",
"@my10minutemail.com",
"@rediffmail.com",
"@sharklasers.com",
"@thrma.com",
"@tryalert.com",
"@vomoto.com",
"@webtrackker.com",
"@yahoo.co.id",
"@yeslifecyclemarketing.com",
"@yopmail.com",
"@zetmail.com",
"abdhesh090@gmail.com",
"abdheshnir.vipra@gmail.com",
"adnanishami28",
"adreahilton@gmail.com",
"airtelshopstore",
"ajayrudelee@gmail.com",
"ajit86153@gmail.com",
"ajymaansingh@gmail.com",
"ak384304@gmail.com",
"akleshnirala@gmail.com",
"alamsarfaraz791@gmail.com",
"albertthomas",
"aliskimis@gmail.com",
"allymptedpokdebraj@gmail.com",
"amarniket4@codehot.co.uk",
"ambikaku12@gmail.com",
"amiteshku12@gmail.com",
"andentspourita@gmail.com",
"andorclifs@gmail.com",
"andrewd@ghostmail.com",
"andrusmith",
"angthpofphilip@gmail.com",
"anilkandpal0@gmail.com",
"anilsingh7885945@gmail.com",
"anjilojilo@gmail.com",
"anshikaescorts@gmail.com",
"april.caword1589@gmail.com",
"apwebs7012@yahoo.com",
"apwebs70@gmail.com",
"arena.wilson91@gmail.com",
"arth.smith@yandex.com",
"asadk7856",
"asadkiller2@gmail.com",
"asadwoz",
"ashwanikumar",
"avanrajput5@gmail.com",
"avanrajput5@gmail.com",
"baalzebub12021996@gmail.com",
"balramchoudhary.ballu@gmail.com",
"baueierjose@gmail.com",
"bcmdsbncskj@yandex.com",
"besto.sty@yandex.com",
"bidupan12@gmail.com",
"bill.cardy1366@gmail.com",
"billydoch021@gmail.com",
"biodotlab",
"boleshahuja88@gmail.com",
"boymorpoupamm@gmail.com",
"caulnurearkporjohnh@gmail.com",
"choutpoyjenniferm@gmail.com",
"ciodsjiocxjosa@yandex.com",
"clarencepatterson570@gmail.com",
"coatseardeaspozwilliamb",
"cooktimseo@gmail.com",
"cooperdavidd@gmail.com",
"crsgroupindia@gmail.com",
"daduajiggy@gmail.com",
"dasdasdsas32@gmail.com",
"davidtech46@gmail.com",
"deal4udeal4me@gmail.com",
"deepak19795up@gmail.com",
"deepakkumar02singh@gmail.com",
"dersttycert101@gmail.com",
"devilr724",
"doetpouernestp@gmail.com",
"donallakarpissaa@gmail.com",
"dr74402@gmail.com",
"drruytuyj@gmail.com",
"dutchess.meethi@gmail.com",
"dwari.hdyr528@gmail.com",
"emaxico",
"estherj@ghostmail.com",
"ethanluna635@gmail.com",
"evagreen277@gmail.com",
"fievepowgeorgeg@gmail.com",
"fifixtpoqpatrickh@gmail.com",
"fishepoemary@gmail.com",
"flustpozwilliamp@gmail.com",
"folk.zin87@gmail.com",
"fragendpotmauriciok@gmail.com",
"gallifingspoyjoannel@gmail.com",
"gamblerbhaijaan@gmail.com",
"georgegallego.com@gmail.com",
"georgiaaby@gmail.com",
"gladyskempf427@gmail.com",
"hatteroublepocmartha@gmail.com",
"hauptnuo214@gmail.com",
"hcjxdbschjbdsj",
"hcuiodsciodso@yandex.com",
"henrymullins",
"herstpopenriqued@gmail.com",
"himeshsinghiq@gmail.com",
"hipearspodarthurd@gmail.com",
"hontpojpatricia",
"hounchpowjohn@gmail.com",
"howerpofharold@gmail.com",
"hpprinter",
"hrrbanga",
"hsharish",
"huin.lisko097@gmail.com",
"hwayne2812",
"ik96550@gmail.com",
"inchestoacres@gmail.com",
"intelomedia02@gmail.com",
"intuitphonenumber",
"iqinfotech",
"iscopedigital11@gmail.com",
"italygroupspecialist@gmail.com",
"jacobshown1@gmail.com",
"jamersonnvy309@gmail.com",
"jamesdelvin2@gmail.com",
"janes6521@gmail.com",
"janessmith",
"jayshown81@gmail.com",
"jecksonmike1512@gmail.com",
"jeevikasraj@gmail.com",
"jhonsinha",
"jiloanjilo",
"jim.cook2681@gmail.com",
"jksadnhk@gmail.com",
"jmike7162@gmail.com",
"jmtechnosolve@gmail.com",
"johngarry227@gmail.com",
"johnmaclan1@gmail.com",
"johnmatty55@gmail.com",
"johnmcclan009@gmail.com",
"johnmclean278@gmail.com",
"johnmikulis8",
"johnnycolvin428@gmail.com",
"johnprashar1@gmail.com",
"johnsinha",
"johnydeep0712@gmail.com",
"joshuahurst928@gmail.com",
"jusbabyespowbobby@gmail.com",
"kalidass34212@gmail.com",
"karansinghrawat15@gmail.com",
"kashyap.kashyap07@yahoo.in",
"kaveribhardwaj@outlook.com",
"kevin24by7@gmail.com",
"kisamar7@gmail.com",
"kk+spamtest@kohsuke.org",
"kripalsingh446@gmail.com",
"krishgail30@yahoo.com",
"ks0449452@gmail.com",
"kukurkutta9@gmail.com",
"kumar.raghavendra84@gmail.com",
"kumar.uma420@gmail.com",
"kumar0121@yahoo.com",
"kumarprem",
"kumarsujit899@gmail.com",
"laknerickman@gmail.com",
"laptoprepair",
"larrysilva",
"leonard.freddie@yandex.com",
"litagray931@gmail.com",
"litawilliam36@gmail.com",
"loefflerpay462@gmail.com",
"loksabha100@gmail.com",
"lovebhaiseo@gmail.com",
"lutherorea2807@gmail.com",
"mac2help@outlook.com",
"mac2help@outlook.com",
"macden",
"madeleineforsyth290@gmail.com",
"maineeru@gnail.com",
"makbaldwin1@gmail.com",
"manasfirdose",
"maohinseeeeeee@outlook.com",
"mariavitory1212@gmail.com",
"marklewis0903@gmail.com",
"masmartin71@gmail.com",
"mehrabharat137@gmail.com",
"michelbavan@gmail.com",
"mk2434990@gmail.com",
"mmmarsh12@gmail.com",
"mohandaerer",
"mohankeeded",
"monubhardwaj12451@gmail.com",
"monurobert",
"morrisonjohn293@gmail.com",
"msofficeservices13@gmail.com",
"mujafer@yandex.com",
"nalspoibarbarab@gmail.com",
"ncrpoo",
"ncrraanisapna@gmail.com",
"ncrradha@gmail.com",
"ncrrohit",
"ncrsona",
"nelsonnelsen11021992@gmail.com",
"newellnewallne56@gmail.com",
"nextgenwebstore@gmail.com",
"nirajsinghrawat12@gmail.com",
"nishanoor32",
"nishuyadav257@gmail.com",
"obat@",
"ollouretypotida@gmail.com",
"outlookhelpline",
"pala41667@gmail.com",
"paroccepoytamarac@gmail.com",
"paulseanseo91@gmail.com",
"pawankundu99@gmail.com",
"petersenk509@gmail.com",
"petersmith2331@gmail.com",
"pintu",
"pk76997246@gmail.com",
"pogogames483@gmail.com",
"poonamkamalpatel@gmail.com",
"porterquines@gmail.com",
"poweltpowwilliamm@gmail.com",
"pranay4job@gmail.com",
"pratik.vipra@gmail.com",
"premk258@gmail.com",
"printerhelplinenumber@gmail.com",
"priturpocdickr@gmail.com",
"quickbook",
"qukenservicess",
"r.onysokha@gmail.com",
"rahul4cool2003@gmail.com",
"rahuldheere@gmail.com",
"rajdsky7@gmail.com",
"rajkumarskbd@gmail.com",
"rajuk0838@gmail.com",
"ramlakhaann@gmail.com",
"randyortam68@gmail.com",
"ransonfreeman@gmail.com",
"rasidegingpoflaceyz@gmail.com",
"ravi1991allahabaduniversity@gmail.com",
"ravirknayak@gmail.com",
"ravis70291@gmail.com",
"rawatmeenakshi12123s",
"rawatsonam",
"rehel55rk@gmail.com",
"righttechnical",
"rikybhel23@gmail.com",
"rodriquesnuv728@gmail.com",
"rohitsharma7294@outlook.com",
"rohitsona121090@gmail.com",
"sajankaur5@gmail.com",
"samit8974@gmail.com",
"sandy@voip4callcenters.com",
"sandysharmja121@gmail.com",
"saundraclogston@gmail.com",
"sawanjha17@gmail.com",
"sbabita149@gmail.com",
"sellikepovscotta@gmail.com",
"seo@gmail.com",
"seosupport",
"seoxpertchandan@gmail.com",
"service.thepc@yandex.com",
"shashisemraha@gmail.com",
"shichpodlakeisha@gmail.com",
"shilpikispotta2508@gmail.com",
"shobha.kachhap23@gmail.com",
"shyamtengo91@gmail.com",
"simon.ken7@gmail.com",
"singhavan31@gmail.com",
"singhmukul",
"skprajapaty@gmail.com",
"sman33935@gmail.com",
"smartsolution3000@gmail.com",
"smithlora912@gmail.com",
"smithmartin919@gmail.com",
"smithmaxseo@gmail.com",
"sneharajput931@gmail.com",
"snjbisth8@gmail.com",
"sonu70251",
"sorianonvy291@gmail.com",
"spyindia",
"spyvikash",
"stephanflorian1@gmail.com",
"stuartbinny12021996@gmail.com",
"sty.besto",
"stybesto13",
"sujatakumari8236@gmail.com",
"sujitkumarthakur8@gmail.com",
"sundeepsa123@gmail.com",
"sunflowerrosy@outlook.com",
"sunilkundujat@gmail.com",
"sunjara10@gmail.com",
"sweenypar210@gmail.com",
"telemarket3004",
"teresarothschild198@gmail.com",
"therewpoxjamix",
"thjyt@yandex.com",
"thornestedpokrodneyn@gmail.com",
"tinku8384@gmail.com",
"tomcopper6@gmail.com",
"tomhanks1121@gmail.com",
"toren55rk@gmail.com",
"uma.shank122451ddsds@gmail.com",
"updateursoftware2016@gmail.com",
"useenpofchristopherc@gmail.com",
"vcb@gmail.com",
"viz.michel@gmail.com",
"vr4vikasrastogi@gmail.com",
"vvicky4001@gmail.com",
"vvicky4003@gmail.com",
"watpad",
"webdevelopera@gmail.com",
"webtracker",
"webtrackker",
"win.tech",
"winstond@tutanota.com",
"wittepepobjustina@gmail.com",
"yadavqs@gmail.com",
"yadavshalini501@gmail.com",
"yashraj_one",
"yetwallpoudonnal@gmail.com",
"youltaspocdonald@gmail.com",
"youmint.lav@gmail.com",
"ytdeqwduqwy@yandex.com",
"zebakhan.ssit@gmail.com",
"zozojams11@gmail.com"
);
public static final List<String> IP_BLACKLIST = Arrays.asList(
"1.186.172.",
"1.187.114.172",
"1.187.118.175",
"1.187.123.123",
"1.187.126.76",
"1.187.162.39",
"1.22.130.142",
"1.22.131.140",
"1.22.164.211",
"1.22.164.227",
"1.22.212.209",
"1.22.38.186",
"1.22.39.244",
"1.23.110.86",
"1.39.101.93",
"1.39.32.",
"1.39.33.",
"1.39.34.",
"1.39.35.",
"1.39.40.",
"1.39.50.144",
"1.39.51.63",
"101.212.67.25",
"101.212.69.213",
"101.212.71.120",
"101.222.175.13",
"101.56.169.183",
"101.56.181.69",
"101.56.2.232",
"101.57.173.94",
"101.57.198.190",
"101.57.198.201",
"101.57.198.22",