Search in sources :

Example 46 with PasswordAuthentication

use of java.net.PasswordAuthentication in project cxf by apache.

the class ReferencingAuthenticator method tryWith.

PasswordAuthentication tryWith(Authenticator a) throws Exception {
    if (a == null) {
        return null;
    }
    for (final Field f : Authenticator.class.getDeclaredFields()) {
        if (!Modifier.isStatic(f.getModifiers())) {
            f.setAccessible(true);
            Object o = f.get(this);
            f.set(a, o);
        }
    }
    final Method m = Authenticator.class.getDeclaredMethod("getPasswordAuthentication");
    m.setAccessible(true);
    return (PasswordAuthentication) m.invoke(a);
}
Also used : Field(java.lang.reflect.Field) Method(java.lang.reflect.Method) PasswordAuthentication(java.net.PasswordAuthentication)

Example 47 with PasswordAuthentication

use of java.net.PasswordAuthentication in project knime-core by knime.

the class ThreadLocalHTTPAuthenticator method getPasswordAuthentication.

/**
 * {@inheritDoc}
 */
@Override
protected PasswordAuthentication getPasswordAuthentication() {
    if (SUPPRESS_POPUP.get() == Boolean.TRUE) {
        return null;
    }
    try {
        // write request values from this object into the delegate
        for (final Field f : Authenticator.class.getDeclaredFields()) {
            if (!Modifier.isStatic(f.getModifiers())) {
                f.setAccessible(true);
                Object o = f.get(this);
                f.set(m_delegate, o);
            }
        }
        final Method m = Authenticator.class.getDeclaredMethod("getPasswordAuthentication");
        m.setAccessible(true);
        return (PasswordAuthentication) m.invoke(m_delegate);
    } catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
        NodeLogger.getLogger(getClass()).warn("Could not delegate HTTP authentication request: " + ex.getMessage(), ex);
        return null;
    }
}
Also used : Field(java.lang.reflect.Field) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) PasswordAuthentication(java.net.PasswordAuthentication)

Example 48 with PasswordAuthentication

use of java.net.PasswordAuthentication in project Payara by payara.

the class HttpAuthenticator method getPasswordAuthentication.

/**
 * This is called when authentication is needed for a protected
 * web resource. It looks for the authentication data in the subject.
 * If the data is not found then login is invoked on the login context.
 */
@Override
protected PasswordAuthentication getPasswordAuthentication() {
    String user = null;
    char[] password = null;
    Subject subject = null;
    String scheme = getRequestingScheme();
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine("scheme=" + scheme);
        _logger.fine("requesting prompt=" + getRequestingPrompt());
        _logger.fine("requesting protocol=" + getRequestingProtocol());
    }
    ClientSecurityContext cont = ClientSecurityContext.getCurrent();
    subject = (cont != null) ? cont.getSubject() : null;
    user = getUserName(subject);
    password = getPassword(subject);
    if (user == null || password == null) {
        try {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.fine("Initiating login again...");
            }
            securityInfo.doClientLogin(loginType);
            cont = ClientSecurityContext.getCurrent();
            subject = cont.getSubject();
            user = getUserName(subject);
            password = getPassword(subject);
        } catch (Exception e) {
            _logger.log(Level.FINE, "Exception " + e.toString(), e);
            return null;
        }
    }
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine("Username:" + user);
    }
    return new PasswordAuthentication(user, password);
}
Also used : ClientSecurityContext(com.sun.enterprise.security.common.ClientSecurityContext) Subject(javax.security.auth.Subject) PasswordAuthentication(java.net.PasswordAuthentication)

Aggregations

PasswordAuthentication (java.net.PasswordAuthentication)48 Authenticator (java.net.Authenticator)18 URL (java.net.URL)11 InetSocketAddress (java.net.InetSocketAddress)9 Proxy (java.net.Proxy)8 InetAddress (java.net.InetAddress)6 Test (org.junit.Test)5 HttpURLConnection (java.net.HttpURLConnection)4 MalformedURLException (java.net.MalformedURLException)4 URI (java.net.URI)4 IOException (java.io.IOException)3 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)3 Dimension (java.awt.Dimension)2 Font (java.awt.Font)2 File (java.io.File)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 Field (java.lang.reflect.Field)2 Method (java.lang.reflect.Method)2 java.net (java.net)2