KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > policyframework > itemactions > RemovePolicyAction


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.policyframework.itemactions;
21
22 import com.sslexplorer.core.UserDatabaseManager;
23 import com.sslexplorer.policyframework.NoPermissionException;
24 import com.sslexplorer.policyframework.Permission;
25 import com.sslexplorer.policyframework.Policy;
26 import com.sslexplorer.policyframework.PolicyConstants;
27 import com.sslexplorer.policyframework.PolicyDatabaseFactory;
28 import com.sslexplorer.policyframework.ResourceItem;
29 import com.sslexplorer.policyframework.ResourceUtil;
30 import com.sslexplorer.realms.Realm;
31 import com.sslexplorer.table.AvailableTableItemAction;
32
33 public class RemovePolicyAction extends RemoveResourceAction {
34
35     /**
36      * @param navigationContext
37      * @param messageResourcesKey
38      */

39     public RemovePolicyAction(int navigationContext, String JavaDoc messageResourcesKey) {
40         super(navigationContext, messageResourcesKey);
41     }
42
43     public boolean isEnabled(AvailableTableItemAction availableItem) {
44         try {
45             ResourceItem item = (ResourceItem) availableItem.getRowItem();
46             try {
47                 Realm realm = UserDatabaseManager.getInstance().getRealm(item.getResource().getRealmID());
48                 if (item.getResource().getResourceId() == PolicyDatabaseFactory.getInstance().getEveryonePolicyIDForRealm(realm)){
49                     // it is the Everyone Policy this cannot be deleted.
50
return false;
51                 }
52             } catch (Exception JavaDoc e) {
53                 // there has been an error so do not display
54
return false;
55             }
56             
57             Permission[] permissions = new Permission[] { PolicyConstants.PERM_DELETE };
58             ResourceUtil.checkResourceManagementRights(item.getResource(), availableItem.getSessionInfo(), permissions);
59             return true;
60         } catch (NoPermissionException e) {
61             return false;
62         }
63     }
64
65 }
66
Popular Tags