usr/src/java/vpanels/client/org/opensolaris/os/vp/client/swing/AppLoginManager.java
author Dan Labrecque <Dan.Labrecque@oracle.com>
Tue, 14 Dec 2010 14:54:59 -0500
changeset 624 23c2892e582e
parent 601 9d4e3e0ee603
child 625 0ad7f2393529
permissions -rw-r--r--
17520 - "Change role..." needs better behavior when no roles

/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
 */

package org.opensolaris.os.vp.client.swing;

import java.awt.*;
import java.io.File;
import java.security.cert.Certificate;
import java.util.List;
import org.opensolaris.os.vp.client.common.*;
import org.opensolaris.os.vp.panel.common.*;
import org.opensolaris.os.vp.panel.common.action.*;
import org.opensolaris.os.vp.util.swing.GUIUtil;

public class AppLoginManager extends RadLoginManager {
    //
    // Instance data
    //

    private HasWindow hasWindow;
    private LoginPane loginPane;
    private CertificatePane certPane;
    private LoginDialog dialog;

    //
    // Constructors
    //

    public AppLoginManager(ConnectionManager manager, HasWindow hasWindow) {
	super(manager);
	this.hasWindow = hasWindow;
    }

    //
    // RadLoginManager methods
    //

    @Override
    public ConnectionInfo[] getConnectionInfo(LoginRequest request,
        ConnectionInfo current) throws ActionAbortedException,
        ActionFailedException {

	final Window owner = hasWindow == null ?
	    null : hasWindow.getComponent();

	if (dialog != null && dialog.getOwner() != owner) {
	    dialog.dispose();
	    dialog = null;
	}

	if (dialog == null) {
	    // Lazy create
	    if (loginPane == null) {
		loginPane = new LoginPane();
		certPane = new CertificatePane();
	    }

	    dialog = new LoginDialog(owner, loginPane, certPane);
	}

	EventQueue.invokeLater(
	    new Runnable() {
		@Override
		public void run() {
		    dialog.setLocationRelativeTo(owner);
		}
	    });

	try {
	    return super.getConnectionInfo(request, current);
	} finally {
	    GUIUtil.invokeAndWait(
		new Runnable() {
		    @Override
		    public void run() {
			dialog.setVisible(false);
		    }
		});
	}
    }

    @Override
    public File getTrustStoreFile() {
	return App.TRUSTSTORE_FILE;
    }

    @Override
    protected void promptForAck(LoginRequest request)
	throws ActionAbortedException {

	dialog.getLoginPane().promptForAck(request);
    }

    @Override
    protected void promptForCertificate(
	String host, Certificate certificate) throws ActionAbortedException {

	dialog.getCertificatePane().promptForCertificate(host, certificate);
    }

    @Override
    protected void promptForFailedRequest(LoginRequest request) {
	dialog.getLoginPane().promptForFailedRequest(request);
    }

    @Override
    protected void promptForHostAndUser(LoginRequest request)
	throws ActionAbortedException {

	dialog.getLoginPane().promptForHostAndUser(request);
    }

    @Override
    protected void promptForEnsureRoles(LoginRequest request) {
	dialog.getLoginPane().promptForEnsureRoles(request);
    }

    @Override
    protected void promptForRole(LoginRequest request, List<String> roles)
	throws ActionAbortedException, ActionRegressedException {

	dialog.getLoginPane().promptForRole(request, roles);
    }

    @Override
    protected void promptForRoleAuth(LoginRequest request,
        List<LoginProperty> properties) throws ActionAbortedException,
        ActionRegressedException {

	dialog.getLoginPane().promptForRoleAuth(request, properties);
    }

    @Override
    protected void promptForUserAuth(LoginRequest request,
        List<LoginProperty> properties) throws ActionAbortedException,
	ActionRegressedException {

	dialog.getLoginPane().promptForUserAuth(request, properties);
    }

    //
    // AppLoginManager methods
    //

    public LoginDialog getDialog() {
	return dialog;
    }
}