Search in sources :

Example 1 with SEPasswordListener

use of com.biglybt.core.security.SEPasswordListener in project BiglyBT by BiglySoftware.

the class SESecurityManagerImpl method getAuthentication.

public PasswordAuthentication getAuthentication(String realm, String protocol, String host, int port) {
    try {
        URL tracker_url = new URL(protocol + "://" + host + ":" + port + "/");
        if (protocol.toLowerCase().startsWith("socks")) {
            // give explicit thread-based listeners a chance to override the hack
            SEPasswordListener thread_listener = (SEPasswordListener) tls.get();
            if (thread_listener != null) {
                PasswordAuthentication temp = thread_listener.getAuthentication(realm, tracker_url);
                if (temp != null) {
                    return (temp);
                }
            }
            String socks_user = COConfigurationManager.getStringParameter("Proxy.Username").trim();
            String socks_pw = COConfigurationManager.getStringParameter("Proxy.Password").trim();
            if (socks_user.equalsIgnoreCase("<none>")) {
                return (new PasswordAuthentication("", "".toCharArray()));
            }
            if (socks_user.length() == 0) {
                Logger.log(new LogAlert(false, LogAlert.AT_WARNING, "Socks server is requesting authentication, please setup user and password in config"));
            }
            return (new PasswordAuthentication(socks_user, socks_pw.toCharArray()));
        }
        return (getPasswordAuthentication(realm, tracker_url));
    } catch (MalformedURLException e) {
        Debug.printStackTrace(e);
        return (null);
    }
}
Also used : SEPasswordListener(com.biglybt.core.security.SEPasswordListener) LogAlert(com.biglybt.core.logging.LogAlert)

Example 2 with SEPasswordListener

use of com.biglybt.core.security.SEPasswordListener in project BiglyBT by BiglySoftware.

the class SESecurityManagerImpl method clearPasswords.

public void clearPasswords() {
    SEPasswordListener thread_listener = (SEPasswordListener) tls.get();
    if (thread_listener != null) {
        thread_listener.clearPasswords();
    }
    Iterator it = password_listeners.iterator();
    while (it.hasNext()) {
        try {
            ((SEPasswordListener) it.next()).clearPasswords();
        } catch (Throwable e) {
            Debug.printStackTrace(e);
        }
    }
}
Also used : SEPasswordListener(com.biglybt.core.security.SEPasswordListener)

Example 3 with SEPasswordListener

use of com.biglybt.core.security.SEPasswordListener in project BiglyBT by BiglySoftware.

the class SESecurityManagerImpl method getPasswordAuthentication.

public PasswordAuthentication getPasswordAuthentication(String realm, URL tracker) {
    SEPasswordListener thread_listener = (SEPasswordListener) tls.get();
    if (thread_listener != null) {
        return (thread_listener.getAuthentication(realm, tracker));
    }
    Object[] handler = (Object[]) password_handlers.get(tracker.toString());
    if (handler != null) {
        try {
            return (((SEPasswordListener) handler[0]).getAuthentication(realm, (URL) handler[1]));
        } catch (Throwable e) {
            Debug.printStackTrace(e);
        }
    }
    Iterator it = password_listeners.iterator();
    while (it.hasNext()) {
        try {
            PasswordAuthentication res = ((SEPasswordListener) it.next()).getAuthentication(realm, tracker);
            if (res != null) {
                return (res);
            }
        } catch (Throwable e) {
            Debug.printStackTrace(e);
        }
    }
    return (null);
}
Also used : SEPasswordListener(com.biglybt.core.security.SEPasswordListener)

Example 4 with SEPasswordListener

use of com.biglybt.core.security.SEPasswordListener in project BiglyBT by BiglySoftware.

the class SESecurityManagerImpl method setPasswordAuthenticationOutcome.

public void setPasswordAuthenticationOutcome(String realm, URL tracker, boolean success) {
    SEPasswordListener thread_listener = (SEPasswordListener) tls.get();
    if (thread_listener != null) {
        thread_listener.setAuthenticationOutcome(realm, tracker, success);
    }
    Iterator it = password_listeners.iterator();
    while (it.hasNext()) {
        ((SEPasswordListener) it.next()).setAuthenticationOutcome(realm, tracker, success);
    }
}
Also used : SEPasswordListener(com.biglybt.core.security.SEPasswordListener)

Example 5 with SEPasswordListener

use of com.biglybt.core.security.SEPasswordListener in project BiglyBT by BiglySoftware.

the class SESecurityManagerImpl method addPasswordListener.

@Override
public void addPasswordListener(final PasswordListener listener) {
    SEPasswordListener sepl = new SEPasswordListener() {

        @Override
        public PasswordAuthentication getAuthentication(String realm, URL tracker) {
            return (listener.getAuthentication(realm, tracker));
        }

        @Override
        public void setAuthenticationOutcome(String realm, URL tracker, boolean success) {
            listener.setAuthenticationOutcome(realm, tracker, success);
        }

        @Override
        public void clearPasswords() {
        }
    };
    password_listeners.put(listener, sepl);
    SESecurityManager.addPasswordListener(sepl);
}
Also used : SEPasswordListener(com.biglybt.core.security.SEPasswordListener) URL(java.net.URL)

Aggregations

SEPasswordListener (com.biglybt.core.security.SEPasswordListener)5 LogAlert (com.biglybt.core.logging.LogAlert)1 URL (java.net.URL)1