1 19 20 package com.sslexplorer.properties.forms; 21 22 import java.util.List ; 23 24 import javax.servlet.http.HttpServletRequest ; 25 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 import org.apache.struts.Globals; 29 import org.apache.struts.action.ActionErrors; 30 import org.apache.struts.action.ActionMapping; 31 import org.apache.struts.action.ActionMessage; 32 33 import com.sslexplorer.boot.PropertyList; 34 import com.sslexplorer.input.MultiSelectSelectionModel; 35 import com.sslexplorer.policyframework.Resource; 36 import com.sslexplorer.policyframework.ResourceUtil; 37 import com.sslexplorer.policyframework.forms.AbstractResourceForm; 38 import com.sslexplorer.properties.ProfilesFactory; 39 import com.sslexplorer.properties.PropertyProfile; 40 import com.sslexplorer.security.Constants; 41 import com.sslexplorer.security.SessionInfo; 42 import com.sslexplorer.security.User; 43 44 50 public class PropertyProfileForm extends AbstractResourceForm { 51 static Log log = LogFactory.getLog(PropertyProfileForm.class); 52 private List propertyProfiles; 53 private int selectedPropertyProfile; 54 private String scope; 55 private String selectedTab = "details"; 56 57 62 public String getUpdateAction() { 63 return getEditing() ? (Constants.SCOPE_GLOBAL.equals(getPropertyScope()) ? "/editGlobalPropertyProfile.do" 64 : "/editPropertyProfile.do") 65 : (Constants.SCOPE_GLOBAL.equals(getPropertyScope()) ? "/createGlobalPropertyProfile.do" 66 : "/createPropertyProfile.do"); 67 } 68 69 75 public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { 76 ActionErrors errs = super.validate(mapping, request); 77 if (isCommiting()) { 78 if (getResourceName().equalsIgnoreCase("default") 79 && (!getEditing() || (getEditing() && !getResource().getResourceName().equalsIgnoreCase("default")))) { 80 errs.add(Globals.ERROR_KEY, new ActionMessage("error.createProfile.cantUseNameDefault")); 81 setResourceName(""); 82 } 83 } 84 return errs; 85 } 86 87 90 public List getPropertyProfiles() { 91 return propertyProfiles; 92 } 93 94 97 public void setSelectedPropertyProfile(int selectedPropertyProfile) { 98 this.selectedPropertyProfile = selectedPropertyProfile; 99 } 100 101 104 public int getSelectedPropertyProfile() { 105 return selectedPropertyProfile; 106 } 107 108 111 public String getPropertyScope() { 112 return scope; 113 } 114 115 118 public void setPropertyScope(String scope) { 119 this.scope = scope; 120 } 121 122 125 public void setPropertyProfiles(List propertyProfiles) { 126 this.propertyProfiles = propertyProfiles; 127 } 128 129 135 public Resource getResourceByName(String name, SessionInfo session) throws Exception { 136 String username = Constants.SCOPE_GLOBAL.equals(getPropertyScope()) ? null : getUser().getPrincipalName(); 137 return ProfilesFactory.getInstance().getPropertyProfile(username, name, getUser().getRealm().getResourceId()); 138 } 139 140 145 public int getTabCount() { 146 return getPropertyScope().equals(Constants.SCOPE_PERSONAL) ? 1 : 2; 147 } 148 149 154 public String getTabName(int idx) { 155 switch (idx) { 156 case 0: 157 return "details"; 158 default: 159 return "policies"; 160 } 161 } 162 163 168 public String getTabTitle(int idx) { 169 return null; 171 } 172 173 183 public void initialise(User user, Resource resource, boolean editing, MultiSelectSelectionModel policyModel, 184 PropertyList selectedPolicies, User owner, boolean assignOnly) throws Exception { 185 super.initialise(user, resource, editing, policyModel, selectedPolicies, owner, assignOnly); 186 propertyProfiles = ProfilesFactory.getInstance().getPropertyProfiles(owner == null ? null : owner.getPrincipalName(), true, 187 ((PropertyProfile)resource).getRealmID()); 188 if (owner != null) { 189 propertyProfiles = ResourceUtil.filterResources(owner, propertyProfiles, owner == null ? true : false); 190 } 191 if (resource != null) { 192 selectedPropertyProfile = ((PropertyProfile) resource).getResourceId(); 193 } else { 194 selectedPropertyProfile = 0; 195 } 196 } 197 198 203 public String getSelectedTab() { 204 return selectedTab; 205 } 206 207 212 public void setSelectedTab(String selectedTab) { 213 this.selectedTab = selectedTab; 214 } 215 216 221 public void applyToResource() throws Exception { 222 } 223 224 229 public String getTabBundle(int idx) { 230 return null; 231 } 232 } | Popular Tags |