1 16 17 package org.apache.webapp.admin.realm; 18 19 import java.io.IOException ; 20 import java.net.URLEncoder ; 21 import java.util.Locale ; 22 import java.util.ArrayList ; 23 import javax.servlet.ServletException ; 24 import javax.servlet.http.HttpServletRequest ; 25 import javax.servlet.http.HttpServletResponse ; 26 import javax.servlet.http.HttpSession ; 27 import org.apache.struts.action.Action; 28 import org.apache.struts.action.ActionErrors; 29 import org.apache.struts.action.ActionForm; 30 import org.apache.struts.action.ActionForward; 31 import org.apache.struts.action.ActionMapping; 32 import org.apache.struts.util.MessageResources; 33 import org.apache.webapp.admin.TomcatTreeBuilder; 34 import org.apache.webapp.admin.LabelValueBean; 35 import org.apache.webapp.admin.Lists; 36 37 43 44 public class AddRealmAction extends Action { 45 46 private ArrayList types = null; 48 49 51 66 public ActionForward execute(ActionMapping mapping, 67 ActionForm form, 68 HttpServletRequest request, 69 HttpServletResponse response) 70 throws IOException , ServletException { 71 72 HttpSession session = request.getSession(); 74 Locale locale = getLocale(request); 75 MessageResources resources = getResources(request); 76 78 String realmTypes[] = new String [5]; 79 realmTypes[0] = "UserDatabaseRealm"; 80 realmTypes[1] = "JNDIRealm"; 81 realmTypes[2] = "MemoryRealm"; 82 realmTypes[3] = "JDBCRealm"; 83 realmTypes[4] = "DataSourceRealm"; 84 85 String parent = request.getParameter("parent"); 86 String type = request.getParameter("type"); 87 if (type == null) 88 type = "UserDatabaseRealm"; 90 types = new ArrayList (); 91 types.add(new LabelValueBean(type, 93 "AddRealm.do?parent=" + 94 URLEncoder.encode(parent,TomcatTreeBuilder.URL_ENCODING) 95 + "&type=" + type)); 96 for (int i=0; i< realmTypes.length; i++) { 97 if (!type.equalsIgnoreCase(realmTypes[i])) { 98 types.add(new LabelValueBean(realmTypes[i], 99 "AddRealm.do?parent=" + 100 URLEncoder.encode(parent,TomcatTreeBuilder.URL_ENCODING) 101 + "&type=" + realmTypes[i])); 102 } 103 } 104 105 if ("UserDatabaseRealm".equalsIgnoreCase(type)) { 106 createUserDatabaseRealm(session, parent); 107 } else if ("JNDIRealm".equalsIgnoreCase(type)) { 108 createJNDIRealm(session, parent); 109 } else if ("MemoryRealm".equalsIgnoreCase(type)) { 110 createMemoryRealm(session, parent); 111 } else if ("JDBCRealm".equalsIgnoreCase(type)){ 112 createJDBCRealm(session, parent); 113 } else if ("DataSourceRealm".equalsIgnoreCase(type)) { 114 createDataSourceRealm(session, parent); 115 } 116 return (mapping.findForward(type)); 118 119 } 120 121 private void createUserDatabaseRealm(HttpSession session, String parent) { 122 123 UserDatabaseRealmForm realmFm = new UserDatabaseRealmForm(); 124 session.setAttribute("userDatabaseRealmForm", realmFm); 125 realmFm.setAdminAction("Create"); 126 realmFm.setObjectName(""); 127 realmFm.setParentObjectName(parent); 128 String realmType = "UserDatabaseRealm"; 129 realmFm.setNodeLabel("Realm (" + realmType + ")"); 130 realmFm.setRealmType(realmType); 131 realmFm.setResource(""); 132 realmFm.setRealmTypeVals(types); 133 } 134 135 private void createJNDIRealm(HttpSession session, String parent) { 136 137 JNDIRealmForm realmFm = new JNDIRealmForm(); 138 session.setAttribute("jndiRealmForm", realmFm); 139 realmFm.setAdminAction("Create"); 140 realmFm.setObjectName(""); 141 realmFm.setParentObjectName(parent); 142 String realmType = "JNDIRealm"; 143 realmFm.setNodeLabel("Realm (" + realmType + ")"); 144 realmFm.setRealmType(realmType); 145 realmFm.setDigest(""); 146 realmFm.setRoleBase(""); 147 realmFm.setUserSubtree("false"); 148 realmFm.setRoleSubtree("false"); 149 realmFm.setRolePattern(""); 150 realmFm.setUserRoleName(""); 151 realmFm.setRoleName(""); 152 realmFm.setRoleBase(""); 153 realmFm.setContextFactory(""); 154 realmFm.setUserPattern(""); 155 realmFm.setUserSearch(""); 156 realmFm.setUserPassword(""); 157 realmFm.setConnectionName(""); 158 realmFm.setConnectionPassword(""); 159 realmFm.setConnectionURL(""); 160 realmFm.setSearchVals(Lists.getBooleanValues()); 161 realmFm.setRealmTypeVals(types); 162 } 163 164 private void createMemoryRealm(HttpSession session, String parent) { 165 166 MemoryRealmForm realmFm = new MemoryRealmForm(); 167 session.setAttribute("memoryRealmForm", realmFm); 168 realmFm.setAdminAction("Create"); 169 realmFm.setObjectName(""); 170 realmFm.setParentObjectName(parent); 171 String realmType = "MemoryRealm"; 172 realmFm.setNodeLabel("Realm (" + realmType + ")"); 173 realmFm.setRealmType(realmType); 174 realmFm.setPathName(""); 175 realmFm.setRealmTypeVals(types); 176 } 177 178 private void createJDBCRealm(HttpSession session, String parent) { 179 180 JDBCRealmForm realmFm = new JDBCRealmForm(); 181 session.setAttribute("jdbcRealmForm", realmFm); 182 realmFm.setAdminAction("Create"); 183 realmFm.setObjectName(""); 184 realmFm.setParentObjectName(parent); 185 String realmType = "JDBCRealm"; 186 realmFm.setNodeLabel("Realm (" + realmType + ")"); 187 realmFm.setRealmType(realmType); 188 realmFm.setDigest(""); 189 realmFm.setDriver(""); 190 realmFm.setRoleNameCol(""); 191 realmFm.setPasswordCol(""); 192 realmFm.setUserTable(""); 193 realmFm.setRoleTable(""); 194 realmFm.setConnectionName(""); 195 realmFm.setConnectionPassword(""); 196 realmFm.setConnectionURL(""); 197 realmFm.setRealmTypeVals(types); 198 } 199 200 private void createDataSourceRealm(HttpSession session, String parent) { 201 202 DataSourceRealmForm realmFm = new DataSourceRealmForm(); 203 session.setAttribute("dataSourceRealmForm", realmFm); 204 realmFm.setAdminAction("Create"); 205 realmFm.setObjectName(""); 206 realmFm.setParentObjectName(parent); 207 String realmType = "DataSourceRealm"; 208 realmFm.setNodeLabel("Realm (" + realmType + ")"); 209 realmFm.setRealmType(realmType); 210 realmFm.setDataSourceName(""); 211 realmFm.setDigest(""); 212 realmFm.setLocalDataSource("false"); 213 realmFm.setRoleNameCol(""); 214 realmFm.setUserCredCol(""); 215 realmFm.setUserNameCol(""); 216 realmFm.setUserRoleTable(""); 217 realmFm.setUserTable(""); 218 realmFm.setRealmTypeVals(types); 219 realmFm.setBooleanVals(Lists.getBooleanValues()); 220 } 221 222 223 } 224 | Popular Tags |