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) 2009, 2013, Oracle and/or its affiliates. All rights reserved. |
|
24 */ |
|
25 |
|
26 package com.oracle.solaris.vp.panels.firewall.client.swing; |
|
27 |
|
28 import java.beans.PropertyChangeEvent; |
|
29 import java.io.IOException; |
|
30 import java.net.UnknownHostException; |
|
31 import java.util.*; |
|
32 import javax.swing.*; |
|
33 import javax.swing.filechooser.FileSystemView; |
|
34 import com.oracle.solaris.rad.client.RadObjectException; |
|
35 import com.oracle.solaris.rad.connect.Connection; |
|
36 import com.oracle.solaris.scf.common.ScfException; |
|
37 import com.oracle.solaris.vp.panel.common.*; |
|
38 import com.oracle.solaris.vp.panel.common.api.network.*; |
|
39 import com.oracle.solaris.vp.panel.common.api.file.RemoteFileSystemView; |
|
40 import com.oracle.solaris.vp.panel.common.api.smf_old.*; |
|
41 import com.oracle.solaris.vp.panel.common.control.*; |
|
42 import com.oracle.solaris.vp.panel.common.model.*; |
|
43 import com.oracle.solaris.vp.panel.common.smf.*; |
|
44 import com.oracle.solaris.vp.panel.swing.control.PanelFrameControl; |
|
45 import com.oracle.solaris.vp.panel.swing.model.SwingPanelDescriptor; |
|
46 import com.oracle.solaris.vp.util.misc.SimpleHasId; |
|
47 import com.oracle.solaris.vp.util.misc.finder.Finder; |
|
48 import com.oracle.solaris.vp.util.swing.HasIcons; |
|
49 |
|
50 @SuppressWarnings({"serial"}) |
|
51 public class FirewallPanelDescriptor |
|
52 extends ServicePanelDescriptor<ServiceManagedObject> |
|
53 implements SwingPanelDescriptor<ServiceManagedObject>, HasIcons, |
|
54 HasAccessPolicy { |
|
55 |
|
56 // |
|
57 // Static data |
|
58 // |
|
59 |
|
60 protected static final List<ImageIcon> icons = Finder.getIcons( |
|
61 "images/global-16.png", |
|
62 "images/global-24.png", |
|
63 "images/global-32.png"); |
|
64 |
|
65 public static final String PROPERTY_ACCESS_POLICY = "access policy"; |
|
66 |
|
67 private static final String SERVICE = "network/ipfilter"; |
|
68 private static final String INSTANCE = "default"; |
|
69 |
|
70 public static final String FW_GLOBAL_DEF_PG = "firewall_config_default"; |
|
71 public static final String FW_GLOBAL_OVR_PG = "firewall_config_override"; |
|
72 |
|
73 // |
|
74 // Instance data |
|
75 // |
|
76 |
|
77 public AccessPolicy policy = new SimpleAccessPolicy(AccessPolicy.Type.NONE); |
|
78 public AccessPolicy ovrPolicy = new SimpleAccessPolicy( |
|
79 AccessPolicy.Type.NONE); |
|
80 |
|
81 private DefaultControl control; |
|
82 private RemoteFileSystemView fsView; |
|
83 private BeanTracker<Network> networkBeanTracker; |
|
84 private SimpleHasId tmpHasId = new SimpleHasId(); |
|
85 |
|
86 private SimpleSmfPropertyGroupInfo defaultPgInfo; |
|
87 private SimpleSmfPropertyGroupInfo overridePgInfo; |
|
88 |
|
89 private List<ServiceManagedObject> services = |
|
90 new LinkedList<ServiceManagedObject>(); |
|
91 private List<ServiceManagedObject> roServices = |
|
92 Collections.unmodifiableList(services); |
|
93 |
|
94 // |
|
95 // Constructors |
|
96 // |
|
97 |
|
98 public FirewallPanelDescriptor(String id, |
|
99 ClientContext context) throws IOException, |
|
100 ScfException, InvalidScfDataException, MissingScfDataException, |
|
101 TrackerException { |
|
102 |
|
103 super(id, context, SERVICE, INSTANCE); |
|
104 |
|
105 fsView = new RemoteFileSystemView(context); |
|
106 |
|
107 networkBeanTracker = new BeanTracker<Network>( |
|
108 (new Network()).getName(), Network.class, context); |
|
109 |
|
110 setComparator(SimpleHasId.COMPARATOR); |
|
111 |
|
112 defaultPgInfo = new SimpleSmfPropertyGroupInfo( |
|
113 getService(), FW_GLOBAL_DEF_PG); |
|
114 overridePgInfo = new SimpleSmfPropertyGroupInfo( |
|
115 getService(), FW_GLOBAL_OVR_PG); |
|
116 |
|
117 ((SimpleAccessPolicy) policy).setPgInfo(defaultPgInfo); |
|
118 ((SimpleAccessPolicy) ovrPolicy).setPgInfo(overridePgInfo); |
|
119 refresh(true); |
|
120 |
|
121 // populate managed services |
|
122 populateServiceList(); |
|
123 |
|
124 control = new PanelFrameControl<FirewallPanelDescriptor>(this); |
|
125 control.addChildren(new MainControl(this)); |
|
126 } |
|
127 |
|
128 // |
|
129 // HasIcon methods |
|
130 // |
|
131 |
|
132 @Override |
|
133 public List<? extends Icon> getIcons() { |
|
134 return icons; |
|
135 } |
|
136 |
|
137 // |
|
138 // HasAccessPolicy methods |
|
139 // |
|
140 |
|
141 @Override |
|
142 public AccessPolicy getAccessPolicy() { |
|
143 return policy; |
|
144 } |
|
145 |
|
146 @Override |
|
147 public void setAccessPolicy(AccessPolicy policy) { |
|
148 this.policy = policy; |
|
149 } |
|
150 |
|
151 // |
|
152 // ManagedObject methods |
|
153 // |
|
154 |
|
155 /** |
|
156 * Stops monitoring the connection to the remote host. |
|
157 */ |
|
158 @Override |
|
159 public void dispose() { |
|
160 networkBeanTracker.dispose(); |
|
161 fsView.dispose(); |
|
162 super.dispose(); |
|
163 } |
|
164 |
|
165 @Override |
|
166 public String getName() { |
|
167 return Finder.getString("panel.firewall.name"); |
|
168 } |
|
169 |
|
170 // |
|
171 // AbstractManagedObject methods |
|
172 // |
|
173 |
|
174 @Override |
|
175 public void addChildren(ServiceManagedObject... toAdd) { |
|
176 super.addChildren(toAdd); |
|
177 for (ServiceManagedObject c : toAdd) { |
|
178 int index = Collections.binarySearch(services, c, getComparator()); |
|
179 services.remove(index); |
|
180 } |
|
181 } |
|
182 |
|
183 @Override |
|
184 public void removeChildren(ServiceManagedObject... toRemove) { |
|
185 super.removeChildren(toRemove); |
|
186 addManagedServices(toRemove); |
|
187 } |
|
188 |
|
189 // |
|
190 // PanelDescriptor methods |
|
191 // |
|
192 |
|
193 @Override |
|
194 public Control getControl() { |
|
195 return control; |
|
196 } |
|
197 |
|
198 // |
|
199 // ServicePanelDescriptor methods |
|
200 // |
|
201 |
|
202 @Override |
|
203 public void refresh(boolean force) throws ScfException, |
|
204 InvalidScfDataException, MissingScfDataException { |
|
205 super.refresh(force); |
|
206 |
|
207 ((SimpleAccessPolicy) policy).initFromRepo(); |
|
208 ((SimpleAccessPolicy) ovrPolicy).initFromRepo(); |
|
209 } |
|
210 |
|
211 // |
|
212 // FirewallPanelDescriptor methods |
|
213 // |
|
214 |
|
215 public List<String> getOpenPorts() { |
|
216 return policy.getOpenPortList(); |
|
217 } |
|
218 |
|
219 public AccessPolicy getOvrAccessPolicy() { |
|
220 return ovrPolicy; |
|
221 } |
|
222 |
|
223 public void setOvrAccessPolicy(AccessPolicy policy) { |
|
224 ovrPolicy = policy; |
|
225 } |
|
226 |
|
227 public FileSystemView getFileSystemView() { |
|
228 return fsView; |
|
229 } |
|
230 |
|
231 public List<ServiceManagedObject> getAllServices() { |
|
232 return roServices; |
|
233 } |
|
234 |
|
235 public ServiceManagedObject getManagedService(String id) { |
|
236 synchronized (children) { |
|
237 tmpHasId.setId(id); |
|
238 int index = Collections.binarySearch(children, tmpHasId, |
|
239 SimpleHasId.COMPARATOR); |
|
240 |
|
241 if (index >= 0) { |
|
242 return children.get(index); |
|
243 } |
|
244 |
|
245 return null; |
|
246 } |
|
247 } |
|
248 |
|
249 // |
|
250 // Set open_port values which update default policy. |
|
251 // |
|
252 public void updateOpenPorts(List<String> portList) { |
|
253 ((SimpleAccessPolicy) policy).setPortList(portList); |
|
254 } |
|
255 |
|
256 // |
|
257 // Update all AccessPolicy values but open_port. |
|
258 // |
|
259 public void updateAccessPolicy(AccessPolicy p) { |
|
260 ((SimpleAccessPolicy) policy).update(p.getType(), p.getCustomFile(), |
|
261 p.getApplyToList(), p.getExceptionsList(), |
|
262 new ArrayList<String>(policy.getOpenPortList())); |
|
263 } |
|
264 |
|
265 // |
|
266 // Update OvrAccessPolicy values |
|
267 // |
|
268 public void updateOvrAccessPolicy(AccessPolicy policy) { |
|
269 ((SimpleAccessPolicy) ovrPolicy).update(policy.getType(), |
|
270 policy.getCustomFile(), policy.getApplyToList(), |
|
271 policy.getExceptionsList(), null); |
|
272 } |
|
273 |
|
274 public void saveToRepo() throws ScfException, UnknownHostException { |
|
275 synchronized (getService()) { |
|
276 getService().pause(); |
|
277 try { |
|
278 ((SimpleAccessPolicy) policy).setRepoValue(); |
|
279 ((SimpleAccessPolicy) ovrPolicy).setRepoValue(); |
|
280 |
|
281 if (getEnabledProperty().isChanged()) |
|
282 getEnabledProperty().saveToRepo(); |
|
283 } finally { |
|
284 getService().unpause(); |
|
285 } |
|
286 } |
|
287 |
|
288 PropertyChangeEvent e = new PropertyChangeEvent(this, |
|
289 PROPERTY_ACCESS_POLICY, policy, policy); |
|
290 firePropertyChange(e); |
|
291 |
|
292 e = new PropertyChangeEvent(this, PROPERTY_ACCESS_POLICY, |
|
293 ovrPolicy, ovrPolicy); |
|
294 firePropertyChange(e); |
|
295 } |
|
296 |
|
297 public void resetPolicies() { |
|
298 SimpleAccessPolicy p = (SimpleAccessPolicy) policy; |
|
299 p.update(p.getSavedType(), p.getSavedCustomFile(), |
|
300 p.getSavedApplyToList(), p.getSavedExceptionsList(), |
|
301 p.getSavedOpenPortList()); |
|
302 |
|
303 p = (SimpleAccessPolicy) ovrPolicy; |
|
304 p.update(p.getSavedType(), p.getSavedCustomFile(), |
|
305 p.getSavedApplyToList(), p.getSavedExceptionsList(), |
|
306 p.getSavedOpenPortList()); |
|
307 |
|
308 if (getEnabledProperty().isChanged()) |
|
309 getEnabledProperty().reset(); |
|
310 } |
|
311 |
|
312 public Network getNetworkBean() { |
|
313 return networkBeanTracker.getBean(); |
|
314 } |
|
315 |
|
316 // |
|
317 // Private methods |
|
318 // |
|
319 |
|
320 private void addManagedServices(ServiceManagedObject ...svcs) { |
|
321 for (ServiceManagedObject s : svcs) { |
|
322 int index = Collections.binarySearch(services, s, getComparator()); |
|
323 if (index < 0) |
|
324 services.add(-index - 1, s); |
|
325 } |
|
326 } |
|
327 |
|
328 private void populateServiceList() throws ScfException, |
|
329 InvalidScfDataException, MissingScfDataException { |
|
330 |
|
331 ConnectionInfo cinfo = getClientContext().getConnectionInfo(); |
|
332 Connection conn = cinfo.getConnection(); |
|
333 |
|
334 Set<Instance> instances = null; |
|
335 |
|
336 try { |
|
337 Aggregator aggbean = conn.getObject(new Aggregator()); |
|
338 instances = new HashSet<Instance>(aggbean.getinstances()); |
|
339 |
|
340 for (Instance inst : instances) { |
|
341 ServiceManagedObject sobj = new ServiceManagedObject(this, |
|
342 conn, inst); |
|
343 |
|
344 if (!sobj.isFirewallSupported()) |
|
345 continue; |
|
346 |
|
347 // |
|
348 // Mark service inactive if it has default policy |
|
349 // else mark it active and add to children list |
|
350 // |
|
351 if (sobj.isDefaultPolicy()) { |
|
352 addManagedServices(sobj); |
|
353 } else { |
|
354 super.addChildren(sobj); |
|
355 } |
|
356 } |
|
357 } catch (RadObjectException e) { |
|
358 } catch (IOException e) { |
|
359 } catch (Exception e) { |
|
360 throw e; // Propagate proxy creation exception |
|
361 } |
|
362 |
|
363 Collections.sort(services, SimpleHasId.COMPARATOR); |
|
364 } |
|
365 } |
|