1 /* |
|
2 * CDDL HEADER START |
|
3 * |
|
4 * The contents of this file are subject to the terms of the |
|
5 * Common Development and Distribution License (the "License"). |
|
6 * You may not use this file except in compliance with the License. |
|
7 * |
|
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 * or http://www.opensolaris.org/os/licensing. |
|
10 * See the License for the specific language governing permissions |
|
11 * and limitations under the License. |
|
12 * |
|
13 * When distributing Covered Code, include this CDDL HEADER in each |
|
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 * If applicable, add the following below this CDDL HEADER, with the |
|
16 * fields enclosed by brackets "[]" replaced with your own identifying |
|
17 * information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 * |
|
19 * CDDL HEADER END |
|
20 */ |
|
21 |
|
22 /* |
|
23 * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. |
|
24 */ |
|
25 |
|
26 package com.oracle.solaris.vp.panel.swing.view; |
|
27 |
|
28 import java.awt.BorderLayout; |
|
29 import javax.swing.*; |
|
30 import com.oracle.solaris.vp.panel.common.*; |
|
31 import com.oracle.solaris.vp.util.misc.NetUtil; |
|
32 import com.oracle.solaris.vp.util.misc.finder.Finder; |
|
33 import com.oracle.solaris.vp.util.swing.*; |
|
34 |
|
35 @SuppressWarnings({"serial"}) |
|
36 public class AuthPanel extends JPanel { |
|
37 // |
|
38 // Instance data |
|
39 // |
|
40 |
|
41 private ConnectionInfo info; |
|
42 private boolean privileged; |
|
43 private JLabel label; |
|
44 private JButton button; |
|
45 |
|
46 // |
|
47 // Constructors |
|
48 // |
|
49 |
|
50 public AuthPanel() { |
|
51 setOpaque(false); |
|
52 label = new JLabel(); |
|
53 |
|
54 button = new JButton(); |
|
55 new RolloverHandler(button); |
|
56 |
|
57 int gap = GUIUtil.getHalfGap(); |
|
58 setLayout(new BorderLayout()); |
|
59 add(label, BorderLayout.CENTER); |
|
60 add(button, BorderLayout.EAST); |
|
61 } |
|
62 |
|
63 // |
|
64 // AuthPanel methods |
|
65 // |
|
66 |
|
67 public JButton getButton() { |
|
68 return button; |
|
69 } |
|
70 |
|
71 public ConnectionInfo getConnectionInfo() { |
|
72 return info; |
|
73 } |
|
74 |
|
75 public boolean getPrivileged() { |
|
76 return privileged; |
|
77 } |
|
78 |
|
79 public void setConnectionInfo(ConnectionInfo info) { |
|
80 this.info = info; |
|
81 updateAuth(); |
|
82 } |
|
83 |
|
84 public void setPrivileged(boolean privileged) { |
|
85 this.privileged = privileged; |
|
86 updateAuth(); |
|
87 } |
|
88 |
|
89 protected void updateAuth() { |
|
90 label.setText(Finder.getString("auth.label", toString(info, true))); |
|
91 |
|
92 button.setIcon(Finder.getIcon(privileged ? |
|
93 "images/auth/lock/authorized-16.png" : |
|
94 "images/auth/lock/unauthorized-16.png")); |
|
95 |
|
96 button.setToolTipText(Finder.getString(privileged ? |
|
97 "auth.tooltip.authorized" : "auth.tooltip.unauthorized")); |
|
98 } |
|
99 |
|
100 // |
|
101 // Static methods |
|
102 // |
|
103 |
|
104 public static String toString(String host, String user, String role, |
|
105 String zone, String zoneUser, String zoneRole, boolean shortForm) { |
|
106 |
|
107 if (NetUtil.isLoopbackAddress(host)) { |
|
108 host = NetUtil.getHostName(); |
|
109 } |
|
110 |
|
111 StringBuilder resource = new StringBuilder("auth.text"); |
|
112 if (shortForm) { |
|
113 resource.append(".short"); |
|
114 } |
|
115 |
|
116 resource.append(".host.user"); |
|
117 if (role != null) { |
|
118 resource.append(".role"); |
|
119 } |
|
120 |
|
121 if (zone != null) { |
|
122 resource.append(".zone.user"); |
|
123 if (zoneRole != null) { |
|
124 resource.append(".role"); |
|
125 } |
|
126 } |
|
127 |
|
128 return Finder.getString(resource.toString(), host, user, role, zone, |
|
129 zoneUser, zoneRole); |
|
130 } |
|
131 |
|
132 public static String toString(LoginInfo info, boolean shortForm) { |
|
133 if (info == null) { |
|
134 return null; |
|
135 } |
|
136 |
|
137 return toString(info.getHost(), info.getUser(), info.getRole(), |
|
138 info.getZone(), info.getZoneUser(), info.getZoneRole(), shortForm); |
|
139 } |
|
140 |
|
141 public static String toString(LoginRequest request, boolean shortForm) { |
|
142 if (request == null) { |
|
143 return null; |
|
144 } |
|
145 |
|
146 boolean isZone = request.getZonePrompt().getValue(); |
|
147 String zone = isZone ? request.getZone().getValue() : null; |
|
148 String zoneUser = isZone ? request.getZoneUser().getValue() : null; |
|
149 String zoneRole = isZone ? request.getZoneRole().getValue() : null; |
|
150 |
|
151 return toString(request.getHost().getValue(), |
|
152 request.getUser().getValue(), request.getRole().getValue(), zone, |
|
153 zoneUser, zoneRole, shortForm); |
|
154 } |
|
155 } |
|