1 19 20 package com.sslexplorer.security.forms; 21 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 import javax.servlet.http.HttpServletRequest ; 26 27 import org.apache.struts.Globals; 28 import org.apache.struts.action.ActionErrors; 29 import org.apache.struts.action.ActionMapping; 30 import org.apache.struts.action.ActionMessage; 31 32 import com.sslexplorer.boot.PropertyList; 33 import com.sslexplorer.input.MultiSelectSelectionModel; 34 import com.sslexplorer.policyframework.Policy; 35 import com.sslexplorer.policyframework.PolicyConstants; 36 import com.sslexplorer.policyframework.PolicyDatabaseFactory; 37 import com.sslexplorer.policyframework.Resource; 38 import com.sslexplorer.policyframework.ResourceUtil; 39 import com.sslexplorer.policyframework.forms.AbstractResourceForm; 40 import com.sslexplorer.security.AuthenticationModuleDefinition; 41 import com.sslexplorer.security.AuthenticationModuleManager; 42 import com.sslexplorer.security.AuthenticationScheme; 43 import com.sslexplorer.security.DefaultAuthenticationScheme; 44 import com.sslexplorer.security.LogonControllerFactory; 45 import com.sslexplorer.security.SessionInfo; 46 import com.sslexplorer.security.User; 47 48 56 public class AuthenticationSchemeForm extends AbstractResourceForm { 57 protected String selectedTab = "details"; 58 protected MultiSelectSelectionModel moduleModel; 59 protected PropertyList selectedModules; 60 protected boolean isSystem = false; 61 62 67 public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { 68 ActionErrors errs = super.validate(mapping, request); 69 if (isCommiting()) { 70 PropertyList l = getSelectedModulesList(); 71 if (l.size() < 1) { 72 errs.add(Globals.ERROR_KEY, new ActionMessage("editAuthenticationScheme.error.noModulesSelected")); 73 } else { 74 AuthenticationModuleDefinition def = AuthenticationModuleManager.getInstance().getModuleDefinition(l.get(0).toString()); 75 if (!def.getPrimary() && (!def.getPrimaryIfSecondardExists() && l.size() > 1)) { 76 errs.add(Globals.ERROR_KEY, new ActionMessage("editAuthenticationScheme.error.firstModuleNotPrimary")); 77 } 78 } 79 80 try { 81 List granted = ResourceUtil.getGrantedResource(LogonControllerFactory.getInstance() 82 .getSessionInfo(request), PolicyConstants.AUTHENTICATION_SCHEMES_RESOURCE_TYPE); 83 boolean found = false; 85 SessionInfo info = LogonControllerFactory.getInstance().getSessionInfo(request); 86 for (Iterator iter = granted.iterator(); iter.hasNext();) { 87 AuthenticationScheme element = (DefaultAuthenticationScheme) iter.next(); 88 if (element.getEnabled() && !element.isSystemScheme() && element.getResourceId() != this.getResourceId()) { 89 90 for (Iterator iterator = PolicyDatabaseFactory.getInstance() 91 .getPoliciesAttachedToResource(element, info.getUser().getRealm()).iterator(); iterator.hasNext();) { 92 Policy policy = (Policy) iterator.next(); 93 if (PolicyDatabaseFactory.getInstance().isPolicyGrantedToUser(policy, 94 LogonControllerFactory.getInstance().getSessionInfo(request).getUser())) { 95 found = true; 96 } 97 } 98 } 99 } 100 if (!found) { 102 for (Iterator iter2 = this.getSelectedPoliciesList().iterator(); iter2.hasNext();) { 103 String id = (String ) iter2.next(); 104 if (PolicyDatabaseFactory.getInstance().isPolicyGrantedToUser( 105 PolicyDatabaseFactory.getInstance().getPolicy(Integer.parseInt(id)), 106 LogonControllerFactory.getInstance().getSessionInfo(request).getUser())) { 107 found = true; 108 } 109 } 110 } 111 112 if (!found) { 113 errs.add(Globals.ERROR_KEY, new ActionMessage("authenticationSchemes.error.mustHavePolicySuperUserAssociation")); 114 } 115 } catch (Exception e) { 116 errs.add(Globals.ERROR_KEY, new ActionMessage("authenticationSchemes.error.failedToValidateSuperUserAuthSchemeConnection")); 117 } 118 119 } 120 return errs; 121 } 122 123 127 public void applyToResource() throws Exception { 128 AuthenticationScheme seq = (DefaultAuthenticationScheme) getResource(); 129 seq.clearModules(); 130 for (Iterator i = getSelectedModulesList().iterator(); i.hasNext();) { 131 seq.addModule((String ) i.next()); 132 } 133 } 134 135 139 public int getTabCount() { 140 return 3; 141 } 142 143 147 public String getTabName(int idx) { 148 switch (idx) { 149 case 0: 150 return "details"; 151 case 1: 152 return "modules"; 153 default: 154 return "policies"; 155 } 156 } 157 158 162 public String getSelectedTab() { 163 return selectedTab; 164 } 165 166 170 public void setSelectedTab(String selectedTab) { 171 this.selectedTab = selectedTab; 172 } 173 174 178 public String getTabTitle(int i) { 179 return null; 180 } 181 182 185 public Resource getResourceByName(String resourceName, SessionInfo session) throws Exception { 186 return PolicyConstants.AUTHENTICATION_SCHEMES_RESOURCE_TYPE.getResourceByName(resourceName, session); 187 } 188 189 193 public MultiSelectSelectionModel getModuleModel() { 194 return moduleModel; 195 } 196 197 201 public void setModuleModel(MultiSelectSelectionModel moduleModel) { 202 this.moduleModel = moduleModel; 203 } 204 205 209 public PropertyList getSelectedModulesList() { 210 return selectedModules; 211 } 212 213 217 public String getSelectedModules() { 218 return selectedModules.getAsTextFieldText(); 219 } 220 221 225 public void setSelectedModules(String selectedModules) { 226 this.selectedModules.setAsTextFieldText(selectedModules); 227 } 228 229 233 public void setSelectedModulesList(PropertyList selectedModules) { 234 this.selectedModules = selectedModules; 235 } 236 237 241 public String getTabBundle(int idx) { 242 return null; 243 } 244 245 public void initialise(User user, Resource resource, boolean editing, MultiSelectSelectionModel policyModel, 246 PropertyList selectedPolicies, User owner, boolean assignOnly) throws Exception { 247 super.initialise(user, resource, editing, policyModel, selectedPolicies, owner, assignOnly); 248 this.isSystem = (((DefaultAuthenticationScheme) resource).isSystemScheme()); 249 } 250 251 254 public boolean isSystem() { 255 return isSystem; 256 } 257 } | Popular Tags |