Examples‎ > ‎

Authentication

import com.jniwrapper.win32.ie.Browser;
import com.jniwrapper.win32.ie.event.AuthenticationHandler;

import javax.swing.*;
import java.awt.*;

/**
 * The sample demonstrates how to handle authentication requests.
 */
public class AuthenticationSample {
    public static void main(String[] args) {
        Browser browser = new Browser();
        
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(browser, BorderLayout.CENTER);
        frame.setSize(800, 600);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        
        browser.setAuthenticationHandler(new AuthenticationHandler() {
            public void onAuthenticate() {
                // display your login/password dialog here
            }

            public String getUserName() {
                return "username";
            }

            public String getPassword() {
                return "password";
            }
        });
        
        browser.navigate("<authentication-website>");
    }
}