source: trunk/src/org/expeditee/io/ProxyAuth.java@ 1102

Last change on this file since 1102 was 1102, checked in by davidb, 6 years ago

Reworking of the code-base to separate logic from graphics. This version of Expeditee now supports a JFX graphics as an alternative to SWING

File size: 2.0 KB
Line 
1/**
2 * ProxyAuth.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.io;
20
21import java.net.Authenticator;
22import java.net.PasswordAuthentication;
23
24public class ProxyAuth extends Authenticator {
25
26 public static final int MAX_ATTEMPTS = 5;
27
28 private String httpUser = null, httpPass = null, httpsUser = null, httpsPass = null;
29 private int attempts = 0;
30
31 public ProxyAuth() {
32 }
33
34 @Override
35 public PasswordAuthentication getPasswordAuthentication() {
36 // TODO: differentiate between HTTP and HTTPS proxies somehow
37 // currently just chooses whichever one is set, preferentially http
38 System.out.println("Authenticating");
39 // stop it from breaking from a redirect loop
40 attempts++;
41 if(attempts > MAX_ATTEMPTS) {
42 return null;
43 }
44 String user = httpUser != null ? httpUser : httpsUser;
45 char[] pass = httpPass != null ? httpPass.toCharArray() : (httpsPass != null ? httpsPass.toCharArray() : null);
46 if(user == null || user.length() == 0 || pass == null || pass.length == 0) {
47 return null;
48 }
49 return new PasswordAuthentication(user, pass);
50 }
51
52 public void setup(String user, String pass) {
53 // System.out.println("setup proxy");
54 this.httpUser = user;
55 this.httpPass = pass;
56 this.httpsUser = user;
57 this.httpsPass = pass;
58 attempts = 0;
59 }
60}
Note: See TracBrowser for help on using the repository browser.