PageRenderTime 24ms CodeModel.GetById 10ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/webportal/src/main/java/au/org/emii/portal/net/HttpAuthenticateProxy.java

http://alageospatialportal.googlecode.com/
Java | 37 lines | 30 code | 7 blank | 0 comment | 3 complexity | 2921855e68f75d54e66efebcbe4277b6 MD5 | raw file
 1package au.org.emii.portal.net;
 2
 3import au.org.emii.portal.settings.Settings;
 4import au.org.emii.portal.util.Validate;
 5import java.net.Authenticator;
 6import java.net.PasswordAuthentication;
 7import org.apache.log4j.Logger;
 8
 9public class HttpAuthenticateProxy extends Authenticator {
10
11    private Settings settings = null;
12    private Logger logger = Logger.getLogger(getClass());
13
14    @Override
15    protected PasswordAuthentication getPasswordAuthentication() {
16        String proxyUserName = settings.getProxyUsername();
17        String proxyPassword = settings.getProxyPassword();
18        logger.debug(String.format("proxy username='%s' proxy password='%s'",proxyUserName, proxyPassword));
19        PasswordAuthentication authenticator;
20        if (Validate.empty(proxyUserName) && Validate.empty(proxyPassword)) {
21            logger.debug("no username and password supplied for proxy - will return null authenticator");
22            authenticator = null;
23        } else {
24            authenticator = new PasswordAuthentication(proxyUserName, proxyPassword.toCharArray());
25        }
26        return authenticator;
27    }
28
29    public Settings getSettings() {
30        return settings;
31    }
32
33    public void setSettings(Settings settings) {
34        this.settings = settings;
35    }
36}
37