usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/swing/view/AuthPanel.java
author Dan Labrecque <Dan.Labrecque@oracle.com>
Fri, 05 Nov 2010 15:51:25 -0400
changeset 598 90e364205db8
parent 591 7c5752b99fd6
child 651 eeb57de7d602
permissions -rw-r--r--
15799 - login button should show menu with history
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
223
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
     1
/*
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
     2
 * CDDL HEADER START
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
     3
 *
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
     5
 * Common Development and Distribution License (the "License").
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
     6
 * You may not use this file except in compliance with the License.
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
     7
 *
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    11
 * and limitations under the License.
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    12
 *
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    18
 *
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    19
 * CDDL HEADER END
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    20
 */
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    21
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    22
/*
591
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 473
diff changeset
    23
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
223
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    24
 */
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    25
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    26
package org.opensolaris.os.vp.panel.swing.view;
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    27
266
b6e25669b646 7654 add status/status text to header
Stephen Talley <stephen.talley@sun.com>
parents: 223
diff changeset
    28
import java.awt.BorderLayout;
b6e25669b646 7654 add status/status text to header
Stephen Talley <stephen.talley@sun.com>
parents: 223
diff changeset
    29
import javax.swing.*;
473
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 306
diff changeset
    30
import org.opensolaris.os.vp.panel.common.*;
591
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 473
diff changeset
    31
import org.opensolaris.os.vp.util.misc.NetUtil;
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 473
diff changeset
    32
import org.opensolaris.os.vp.util.misc.finder.Finder;
266
b6e25669b646 7654 add status/status text to header
Stephen Talley <stephen.talley@sun.com>
parents: 223
diff changeset
    33
import org.opensolaris.os.vp.util.swing.*;
223
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    34
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    35
@SuppressWarnings({"serial"})
266
b6e25669b646 7654 add status/status text to header
Stephen Talley <stephen.talley@sun.com>
parents: 223
diff changeset
    36
public class AuthPanel extends JPanel {
223
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    37
    //
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    38
    // Instance data
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    39
    //
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    40
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    41
    private ConnectionInfo info;
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    42
    private boolean privileged;
266
b6e25669b646 7654 add status/status text to header
Stephen Talley <stephen.talley@sun.com>
parents: 223
diff changeset
    43
    private JLabel label;
b6e25669b646 7654 add status/status text to header
Stephen Talley <stephen.talley@sun.com>
parents: 223
diff changeset
    44
    private JButton button;
223
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    45
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    46
    //
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    47
    // Constructors
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    48
    //
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    49
266
b6e25669b646 7654 add status/status text to header
Stephen Talley <stephen.talley@sun.com>
parents: 223
diff changeset
    50
    public AuthPanel() {
b6e25669b646 7654 add status/status text to header
Stephen Talley <stephen.talley@sun.com>
parents: 223
diff changeset
    51
	setOpaque(false);
b6e25669b646 7654 add status/status text to header
Stephen Talley <stephen.talley@sun.com>
parents: 223
diff changeset
    52
	label = new JLabel();
b6e25669b646 7654 add status/status text to header
Stephen Talley <stephen.talley@sun.com>
parents: 223
diff changeset
    53
b6e25669b646 7654 add status/status text to header
Stephen Talley <stephen.talley@sun.com>
parents: 223
diff changeset
    54
	button = new JButton();
b6e25669b646 7654 add status/status text to header
Stephen Talley <stephen.talley@sun.com>
parents: 223
diff changeset
    55
	new RolloverHandler(button);
b6e25669b646 7654 add status/status text to header
Stephen Talley <stephen.talley@sun.com>
parents: 223
diff changeset
    56
b6e25669b646 7654 add status/status text to header
Stephen Talley <stephen.talley@sun.com>
parents: 223
diff changeset
    57
	int gap = GUIUtil.getHalfGap();
b6e25669b646 7654 add status/status text to header
Stephen Talley <stephen.talley@sun.com>
parents: 223
diff changeset
    58
	setLayout(new BorderLayout());
b6e25669b646 7654 add status/status text to header
Stephen Talley <stephen.talley@sun.com>
parents: 223
diff changeset
    59
	add(label, BorderLayout.CENTER);
b6e25669b646 7654 add status/status text to header
Stephen Talley <stephen.talley@sun.com>
parents: 223
diff changeset
    60
	add(button, BorderLayout.EAST);
223
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    61
    }
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    62
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    63
    //
266
b6e25669b646 7654 add status/status text to header
Stephen Talley <stephen.talley@sun.com>
parents: 223
diff changeset
    64
    // AuthPanel methods
223
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    65
    //
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    66
266
b6e25669b646 7654 add status/status text to header
Stephen Talley <stephen.talley@sun.com>
parents: 223
diff changeset
    67
    public JButton getButton() {
b6e25669b646 7654 add status/status text to header
Stephen Talley <stephen.talley@sun.com>
parents: 223
diff changeset
    68
	return button;
b6e25669b646 7654 add status/status text to header
Stephen Talley <stephen.talley@sun.com>
parents: 223
diff changeset
    69
    }
b6e25669b646 7654 add status/status text to header
Stephen Talley <stephen.talley@sun.com>
parents: 223
diff changeset
    70
223
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    71
    public ConnectionInfo getConnectionInfo() {
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    72
	return info;
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    73
    }
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    74
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    75
    public boolean getPrivileged() {
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    76
	return privileged;
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    77
    }
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    78
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    79
    public void setConnectionInfo(ConnectionInfo info) {
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    80
	this.info = info;
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    81
	updateAuth();
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    82
    }
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    83
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    84
    public void setPrivileged(boolean privileged) {
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    85
	this.privileged = privileged;
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    86
	updateAuth();
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    87
    }
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    88
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    89
    protected void updateAuth() {
266
b6e25669b646 7654 add status/status text to header
Stephen Talley <stephen.talley@sun.com>
parents: 223
diff changeset
    90
	label.setText(Finder.getString("auth.label", toString(info)));
223
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    91
266
b6e25669b646 7654 add status/status text to header
Stephen Talley <stephen.talley@sun.com>
parents: 223
diff changeset
    92
	button.setIcon(Finder.getIcon(privileged ?
306
b08061f1d961 9379 integrate visual design icons and feedback
Stephen Talley <stephen.talley@sun.com>
parents: 266
diff changeset
    93
	    "images/auth/lock/authorized-16.png" :
b08061f1d961 9379 integrate visual design icons and feedback
Stephen Talley <stephen.talley@sun.com>
parents: 266
diff changeset
    94
	    "images/auth/lock/unauthorized-16.png"));
223
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    95
266
b6e25669b646 7654 add status/status text to header
Stephen Talley <stephen.talley@sun.com>
parents: 223
diff changeset
    96
	button.setToolTipText(Finder.getString(privileged ?
223
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    97
	    "auth.tooltip.authorized" : "auth.tooltip.unauthorized"));
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    98
    }
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
    99
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
   100
    //
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
   101
    // Static methods
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
   102
    //
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
   103
473
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 306
diff changeset
   104
    public static String toString(String host, String user, String role) {
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 306
diff changeset
   105
	if (NetUtil.isLoopbackAddress(host)) {
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 306
diff changeset
   106
	    host = NetUtil.getHostName();
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 306
diff changeset
   107
	}
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 306
diff changeset
   108
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 306
diff changeset
   109
	String resource = role == null ?
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 306
diff changeset
   110
	    "auth.text.host.user" : "auth.text.host.user.role";
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 306
diff changeset
   111
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 306
diff changeset
   112
	return Finder.getString(resource, host, user, role);
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 306
diff changeset
   113
    }
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 306
diff changeset
   114
598
90e364205db8 15799 - login button should show menu with history
Dan Labrecque <Dan.Labrecque@oracle.com>
parents: 591
diff changeset
   115
    public static String toString(LoginInfo info) {
223
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
   116
	if (info == null) {
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
   117
	    return null;
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
   118
	}
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
   119
473
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 306
diff changeset
   120
	return toString(info.getHost(), info.getUser(), info.getRole());
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 306
diff changeset
   121
    }
223
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
   122
473
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 306
diff changeset
   123
    public static String toString(LoginRequest request) {
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 306
diff changeset
   124
	if (request == null) {
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 306
diff changeset
   125
	    return null;
223
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
   126
	}
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
   127
473
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 306
diff changeset
   128
        return toString(request.getHost().getValue(),
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 306
diff changeset
   129
	    request.getUser().getValue(), request.getRole().getValue());
223
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
   130
    }
aa68c366f3d0 6923 Menu, connection pull-down should be removed from main window
Stephen Talley <stephen.talley@sun.com>
parents:
diff changeset
   131
}