KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > policyframework > forms > PoliciesForm


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.forms;
21
22 import java.lang.reflect.Constructor JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27 import javax.servlet.http.HttpSession JavaDoc;
28
29 import org.apache.struts.Globals;
30 import org.apache.struts.action.ActionErrors;
31 import org.apache.struts.action.ActionMapping;
32 import org.apache.struts.action.ActionMessage;
33
34 import com.sslexplorer.core.BundleActionMessage;
35 import com.sslexplorer.policyframework.Policy;
36 import com.sslexplorer.policyframework.PolicyConstants;
37 import com.sslexplorer.policyframework.PolicyDatabaseFactory;
38 import com.sslexplorer.policyframework.PolicyItem;
39 import com.sslexplorer.policyframework.Resource;
40 import com.sslexplorer.policyframework.ResourceUtil;
41 import com.sslexplorer.security.AuthenticationScheme;
42 import com.sslexplorer.security.DefaultAuthenticationScheme;
43 import com.sslexplorer.security.LogonControllerFactory;
44 import com.sslexplorer.security.SessionInfo;
45
46
47 public class PoliciesForm extends AbstractResourcesForm {
48     public PoliciesForm() {
49         super("policies");
50     }
51     
52     public ActionErrors validate(ActionMapping mapping, HttpServletRequest JavaDoc request) {
53         ActionErrors errs = new ActionErrors();
54         // on removal we need to ensure that we are not ostresizing the super user.
55
if (this.getActionTarget() != null && this.getActionTarget().equals("confirmRemove")) {
56             SessionInfo info = LogonControllerFactory.getInstance().getSessionInfo(request);
57             boolean found = false;
58
59             try {
60                 List JavaDoc authSchemes = ResourceUtil.getGrantedResource(info, PolicyConstants.AUTHENTICATION_SCHEMES_RESOURCE_TYPE);
61                 for (Iterator JavaDoc iter = authSchemes.iterator(); iter.hasNext();) {
62                     AuthenticationScheme element = (DefaultAuthenticationScheme) iter.next();
63                     if (!element.isSystemScheme() && element.getEnabled()) {
64                         List JavaDoc attachedPolicies = PolicyDatabaseFactory.getInstance().getPoliciesAttachedToResource(
65                                         element, info.getUser().getRealm());
66                         for (Iterator JavaDoc iterator = attachedPolicies.iterator(); iterator.hasNext();) {
67                             Policy policy = (Policy) iterator.next();
68                             // we don't check the current policy as it is about to be deleted.
69
if (policy.getResourceId() != this.selectedResource && PolicyDatabaseFactory.getInstance().isPolicyGrantedToUser(policy,
70                                             info.getUser())) {
71                                 found = true;
72                                 break;
73                             }
74                         }
75                     }
76                 }
77             } catch (Exception JavaDoc e) {
78                 errs.add(Globals.ERROR_KEY, new ActionMessage("authenticationSchemes.error.failedToValidateSuperUserAuthSchemeConnection"));
79             }
80
81             try {
82                 if (!found) {
83                     errs.add(Globals.ERROR_KEY, new BundleActionMessage("security", "authenticationSchemes.error.mustHavePolicySuperUserAssociation"));
84                 }
85             } catch (RuntimeException JavaDoc e) {
86                 e.printStackTrace();
87             }
88             
89         }
90         return errs;
91     }
92
93     public void initialize(List JavaDoc resources, Class JavaDoc resourceItemClass, HttpSession JavaDoc session, String JavaDoc defaultSortColumnId) {
94         super.initialize(session, defaultSortColumnId);
95         launchedPolicy = -1;
96         try {
97             for (Iterator JavaDoc i = resources.iterator(); i.hasNext();) {
98                 Resource dr = (Resource) i.next();
99                 Constructor JavaDoc c = resourceItemClass.getConstructor(new Class JavaDoc[] { Resource.class, List JavaDoc.class });
100                 List JavaDoc policies = PolicyDatabaseFactory.getInstance().getPoliciesAttachedToResource(dr,
101                                 LogonControllerFactory.getInstance().getSessionInfo(session).getUser().getRealm());
102                 PolicyItem item = new PolicyItem(dr, policies);
103                 getModel().addItem(item);
104             }
105             getPager().rebuild(getFilterText());
106         } catch (Throwable JavaDoc t) {
107             log.error("Failed to initialise resources form.", t);
108         }
109     }
110
111 }
Popular Tags