KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > policyframework > wizards > forms > AccessRightsPermissionsForm


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.wizards.forms;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.TreeSet JavaDoc;
27
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29
30 import org.apache.struts.Globals;
31 import org.apache.struts.action.ActionErrors;
32 import org.apache.struts.action.ActionMapping;
33
34 import com.sslexplorer.core.BundleActionMessage;
35 import com.sslexplorer.policyframework.AccessRight;
36 import com.sslexplorer.policyframework.Permission;
37 import com.sslexplorer.policyframework.PolicyConstants;
38 import com.sslexplorer.policyframework.PolicyDatabaseFactory;
39 import com.sslexplorer.policyframework.ResourceType;
40 import com.sslexplorer.wizard.AbstractWizardSequence;
41 import com.sslexplorer.wizard.forms.DefaultWizardForm;
42
43 /**
44  * Implementation of a {@link DefaultWizardForm}. Provides setters and getters
45  * for attributes for the access rights page.
46  *
47  * @author James D Robinson <a HREF="mailto:james@3sp.com">&lt;james@3sp.com&gt;</a>
48  *
49  */

50 public class AccessRightsPermissionsForm extends DefaultWizardForm {
51
52     private int selectedResourceTypeId;
53     private Collection JavaDoc<ResourceType> resourceTypes;
54     private ResourceType selectedResourceType;
55     private String JavaDoc[] selectedAvailablePermissions;
56     private List JavaDoc resourceTypePermissions;
57     private String JavaDoc[] selectedResourceTypePermissions;
58     private List JavaDoc<Permission> availablePermissions;
59
60     /**
61      * Resource type constant
62      */

63     public final static String JavaDoc ATTR_RESOURCE_TYPE = "resourceType";
64
65     /**
66      * Resource type permission constant
67      */

68     public final static String JavaDoc ATTR_RESOURCE_TYPE_PERMISSIONS = "resourceTypePermissions";
69
70     /**
71      *
72      */

73     public AccessRightsPermissionsForm() {
74         super(true, true, "/WEB-INF/jsp/content/policyframework/accessRightsWizard/accessRightsPermissions.jspf", "resourceType",
75                         true, false, "accessRightsPermissions", "policyframework", "accessRightsWizard.permissions", 2);
76     }
77
78     /**
79      * @return Returns the resourceType.
80      */

81     public int getSelectedResourceType() {
82         return selectedResourceTypeId;
83     }
84
85     /**
86      * @param resourceType The resourceType to set.
87      */

88     public void setSelectedResourceType(int resourceType) {
89         this.selectedResourceTypeId = resourceType;
90     }
91
92     /*
93      * (non-Javadoc)
94      *
95      * @see com.sslexplorer.core.forms.AbstractResourceWizardForm#apply(com.sslexplorer.wizard.AbstractWizardSequence)
96      */

97     public void apply(AbstractWizardSequence sequence) throws Exception JavaDoc {
98         super.apply(sequence);
99         sequence.putAttribute(ATTR_RESOURCE_TYPE, new Integer JavaDoc(selectedResourceTypeId));
100     }
101
102     /*
103      * (non-Javadoc)
104      *
105      * @see com.sslexplorer.core.forms.AbstractResourceWizardForm#init(com.sslexplorer.wizard.AbstractWizardSequence,
106      * javax.servlet.http.HttpServletRequest)
107      */

108     public void init(AbstractWizardSequence sequence, HttpServletRequest JavaDoc request) throws Exception JavaDoc {
109         super.init(sequence, request);
110         String JavaDoc permissionClass = (String JavaDoc) sequence.getAttribute(AccessRightsDetailsForm.ATTR_RESOURCE_PERMISSION_CLASS,
111                         PolicyConstants.DELEGATION_CLASS);
112         selectedAvailablePermissions = new String JavaDoc[0];
113         resourceTypePermissions = (List JavaDoc) sequence.getAttribute(ATTR_RESOURCE_TYPE_PERMISSIONS, new ArrayList JavaDoc());
114         availablePermissions = new ArrayList JavaDoc<Permission>();
115         Collection JavaDoc<Permission> allAvailablePermissions = new TreeSet JavaDoc<Permission>();
116         if (sequence.hasAttribute(ATTR_RESOURCE_TYPE)) {
117             selectedResourceType = PolicyDatabaseFactory.getInstance().getResourceType(
118                             ((Integer JavaDoc) sequence.getAttribute(ATTR_RESOURCE_TYPE, null)).intValue());
119         }
120         resourceTypes = new TreeSet JavaDoc<ResourceType>();
121         List JavaDoc r = PolicyDatabaseFactory.getInstance().getResourceTypes(permissionClass);
122         for (Iterator JavaDoc i = r.iterator(); i.hasNext();) {
123             ResourceType rt = (ResourceType) i.next();
124             if (rt.getPermissions().size() > 0) {
125                 resourceTypes.add(rt);
126             }
127         }
128         if (selectedResourceType == null) {
129             selectedResourceType = resourceTypes.iterator().next();
130         }
131         allAvailablePermissions.addAll(selectedResourceType.getPermissions());
132
133         selectedResourceTypeId = selectedResourceType.getResourceTypeId();
134         for (Iterator JavaDoc i = allAvailablePermissions.iterator(); i.hasNext();) {
135             Permission p = (Permission) i.next();
136             boolean found = false;
137             for (Iterator JavaDoc j = resourceTypePermissions.iterator(); j.hasNext();) {
138                 AccessRight rp = (AccessRight) j.next();
139                 if (rp.getPermission() == p && rp.getResourceType() == selectedResourceType) {
140                     found = true;
141                 }
142             }
143             if (!found) {
144                 availablePermissions.add(p);
145             }
146         }
147     }
148
149     /**
150      * @return Returns the resourceTypes.
151      */

152     public Collection JavaDoc getResourceTypes() {
153         return resourceTypes;
154     }
155
156     /**
157      * @return Returns the resourceType.
158      */

159     public ResourceType getResourceType() {
160         return selectedResourceType;
161     }
162
163     /**
164      * @return Returns the selectedAvailablePermissions.
165      */

166     public String JavaDoc[] getSelectedAvailablePermissions() {
167         return selectedAvailablePermissions;
168     }
169
170     /**
171      * @param selectedAvailablePermissions The selectedAvailablePermissions to
172      * set.
173      */

174     public void setSelectedAvailablePermissions(String JavaDoc[] selectedAvailablePermissions) {
175         this.selectedAvailablePermissions = selectedAvailablePermissions;
176     }
177
178     /**
179      * @return Returns the resourceTypePermissions.
180      */

181     public List JavaDoc getResourceTypePermissions() {
182         return resourceTypePermissions;
183     }
184
185     /**
186      * @return Returns the selectedResourceTypePermissions.
187      */

188     public String JavaDoc[] getSelectedResourceTypePermissions() {
189         return selectedResourceTypePermissions;
190     }
191
192     /**
193      * @param selectedResourceTypePermissions The
194      * selectedResourceTypePermissions to set.
195      */

196     public void setSelectedResourceTypePermissions(String JavaDoc[] selectedResourceTypePermissions) {
197         this.selectedResourceTypePermissions = selectedResourceTypePermissions;
198     }
199
200     /**
201      * @return Returns the availablePermissions.
202      */

203     public List JavaDoc getAvailablePermissions() {
204         return availablePermissions;
205     }
206 }
Popular Tags