001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.console.configcreator;
017:
018: import java.util.ArrayList;
019: import java.util.List;
020: import java.util.Map;
021:
022: import javax.portlet.ActionResponse;
023: import javax.portlet.PortletRequest;
024: import javax.portlet.PortletSession;
025:
026: import org.apache.commons.logging.Log;
027: import org.apache.commons.logging.LogFactory;
028: import org.apache.geronimo.console.MultiPageAbstractHandler;
029: import org.apache.geronimo.console.MultiPageModel;
030: import org.apache.geronimo.deployment.xbeans.PatternType;
031: import org.apache.geronimo.xbeans.geronimo.naming.GerPortType;
032: import org.apache.geronimo.xbeans.geronimo.naming.GerServiceRefType;
033: import org.apache.geronimo.xbeans.geronimo.security.GerDistinguishedNameType;
034: import org.apache.geronimo.xbeans.geronimo.security.GerLoginDomainPrincipalType;
035: import org.apache.geronimo.xbeans.geronimo.security.GerPrincipalType;
036: import org.apache.geronimo.xbeans.geronimo.security.GerRealmPrincipalType;
037: import org.apache.geronimo.xbeans.geronimo.security.GerRoleType;
038: import org.apache.geronimo.xbeans.geronimo.security.GerSecurityType;
039: import org.apache.geronimo.xbeans.geronimo.security.GerSubjectInfoType;
040:
041: /**
042: * Base class for portlet helpers
043: *
044: * @version $Rev: 594759 $ $Date: 2007-11-13 20:32:35 -0800 (Tue, 13 Nov 2007) $
045: */
046: public abstract class AbstractHandler extends MultiPageAbstractHandler {
047: private final static Log log = LogFactory
048: .getLog(AbstractHandler.class);
049:
050: protected final static String GET_ARCHIVE_MODE = "index";
051: // 'mode' of initial portlet must be one of "index" or "list"
052:
053: protected final static String ENVIRONMENT_MODE = "environment";
054:
055: protected final static String REFERENCES_MODE = "references";
056:
057: protected final static String SECURITY_MODE = "security";
058:
059: protected final static String DEPENDENCIES_MODE = "dependencies";
060:
061: protected final static String DISPLAY_PLAN_MODE = "displayPlan";
062:
063: protected final static String DEPLOY_STATUS_MODE = "deployStatus";
064:
065: protected final static String WAR_CONFIG_DATA_ID = "org.apache.geronimo.configcreator.warConfigData";
066:
067: protected final static String DATA_PARAMETER = "data";
068:
069: protected final static String MODULE_URI_PARAMETER = "moduleURI";
070:
071: protected final static String UPLOADED_WAR_URI_PARAMETER = "uploadedWarUri";
072:
073: protected final static String DEPLOYMENT_PLAN_PARAMETER = "deploymentPlan";
074:
075: protected final static String CONTEXT_ROOT_PARAMETER = "contextRoot";
076:
077: protected final static String ARTIFACT_ID_PARAMETER = "artifactId";
078:
079: protected final static String GROUP_ID_PARAMETER = "groupId";
080:
081: protected final static String VERSION_PARAMETER = "version";
082:
083: protected final static String TYPE_PARAMETER = "type";
084:
085: protected final static String HIDDEN_CLASSES_PARAMETER = "hiddenClasses";
086:
087: protected final static String NON_OVERRIDABLE_CLASSES_PARAMETER = "nonOverridableClasses";
088:
089: protected final static String INVERSE_CLASSLOADING_PARAMETER = "inverseClassLoading";
090:
091: protected final static String EJB_REF_PREFIX = "ejbRef";
092:
093: protected final static String EJB_LOCAL_REF_PREFIX = "ejbLocalRef";
094:
095: protected final static String JMS_CONNECTION_FACTORY_REF_PREFIX = "jmsConnectionFactoryRef";
096:
097: protected final static String JMS_DESTINATION_REF_PREFIX = "jmsDestinationRef";
098:
099: protected final static String MESSAGE_DESTINATION_PREFIX = "messageDestination";
100:
101: protected final static String JDBC_POOL_REF_PREFIX = "jdbcPoolRef";
102:
103: protected final static String JAVAMAIL_SESSION_REF_PREFIX = "javaMailSessionRef";
104:
105: protected final static String REF_NAME = "refName";
106:
107: protected final static String REF_LINK = "refLink";
108:
109: protected final static String DEPENDENCY_PREFIX = "dependency";
110:
111: protected final static String ARCHIVE_NOT_SUPPORTED_PARAMETER = "archiveNotSupported";
112:
113: protected final static String REFERENCE_NOT_RESOLVED_PARAMETER = "referenceNotResolved";
114:
115: protected final static String DEPLOYED_EJBS_PARAMETER = "deployedEjbs";
116:
117: protected final static String DEPLOYED_JDBC_CONNECTION_POOLS_PARAMETER = "deployedJdbcConnectionPools";
118:
119: protected final static String DEPLOYED_JMS_CONNECTION_FACTORIES_PARAMETER = "deployedJmsConnectionFactories";
120:
121: protected final static String DEPLOYED_JMS_DESTINATIONS_PARAMETER = "deployedJmsDestinations";
122:
123: protected final static String DEPLOYED_JAVAMAIL_SESSIONS_PARAMETER = "deployedJavaMailSessions";
124:
125: protected final static String DEPLOYED_SECURITY_REALMS_PARAMETER = "deployedSecurityRealms";
126:
127: protected final static String DEPLOYED_CREDENTIAL_STORES_PARAMETER = "deployedCredentialStores";
128:
129: protected final static String COMMON_LIBS_PARAMETER = "commonLibs";
130:
131: protected final static String SELECTED_LIBS_PARAMETER = "selectedLibs";
132:
133: protected final static String DEPLOY_ABBR_STATUS_PARAMETER = "abbrStatusMessage";
134:
135: protected final static String DEPLOY_FULL_STATUS_PARAMETER = "fullStatusMessage";
136:
137: public AbstractHandler(String mode, String viewName) {
138: super (mode, viewName);
139: }
140:
141: public static class WARConfigModel implements MultiPageModel {
142: public WARConfigModel(PortletRequest request) {
143: }
144:
145: public void save(ActionResponse response, PortletSession session) {
146: }
147: }
148:
149: public WARConfigData getSessionData(PortletRequest request) {
150: return (WARConfigData) request.getPortletSession()
151: .getAttribute(WAR_CONFIG_DATA_ID);
152: }
153:
154: public void setNewSessionData(PortletRequest request) {
155: request.getPortletSession().setAttribute(WAR_CONFIG_DATA_ID,
156: new WARConfigData());
157: }
158:
159: public static class WARConfigData {
160: private String uploadedWarUri;
161:
162: private String deploymentPlan;
163:
164: private String contextRoot;
165:
166: private String artifactId;
167:
168: private String groupId;
169:
170: private String version;
171:
172: private String type;
173:
174: private String hiddenClasses;
175:
176: private String nonOverridableClasses;
177:
178: private boolean inverseClassLoading;
179:
180: private List ejbRefs = new ArrayList();
181:
182: private List ejbLocalRefs = new ArrayList();
183:
184: private List jdbcPoolRefs = new ArrayList();
185:
186: private List jmsConnectionFactoryRefs = new ArrayList();
187:
188: private List jmsDestinationRefs = new ArrayList();
189:
190: private List messageDestinations = new ArrayList();
191:
192: private List javaMailSessionRefs = new ArrayList();
193:
194: private List<GerServiceRefType> webServiceRefs = new ArrayList<GerServiceRefType>();
195:
196: private List dependencies = new ArrayList();
197:
198: private boolean referenceNotResolved;
199:
200: private String securityRealmName;
201:
202: private GerSecurityType security = null;
203:
204: public WARConfigData() {
205: }
206:
207: public void readEnvironmentData(PortletRequest request) {
208: contextRoot = request.getParameter(CONTEXT_ROOT_PARAMETER);
209: artifactId = request.getParameter(ARTIFACT_ID_PARAMETER);
210: groupId = request.getParameter(GROUP_ID_PARAMETER);
211: version = request.getParameter(VERSION_PARAMETER);
212: type = request.getParameter(TYPE_PARAMETER);
213: hiddenClasses = request
214: .getParameter(HIDDEN_CLASSES_PARAMETER);
215: nonOverridableClasses = request
216: .getParameter(NON_OVERRIDABLE_CLASSES_PARAMETER);
217: inverseClassLoading = "true".equalsIgnoreCase(request
218: .getParameter(INVERSE_CLASSLOADING_PARAMETER)) ? true
219: : false;
220: }
221:
222: public void readReferencesData(PortletRequest request) {
223: readParameters(EJB_REF_PREFIX, ejbRefs, request);
224: readParameters(EJB_LOCAL_REF_PREFIX, ejbLocalRefs, request);
225: readParameters(JMS_CONNECTION_FACTORY_REF_PREFIX,
226: jmsConnectionFactoryRefs, request);
227: readParameters(JMS_DESTINATION_REF_PREFIX,
228: jmsDestinationRefs, request);
229: readParameters(MESSAGE_DESTINATION_PREFIX,
230: messageDestinations, request);
231: readParameters(JDBC_POOL_REF_PREFIX, jdbcPoolRefs, request);
232: readParameters(JAVAMAIL_SESSION_REF_PREFIX,
233: javaMailSessionRefs, request);
234: readWebServiceRefsData(request);
235: }
236:
237: private void readParameters(String prefix1, List list,
238: PortletRequest request) {
239: list.clear();
240: Map map = request.getParameterMap();
241: int index = 0;
242: while (true) {
243: String prefix2 = prefix1 + "." + (index++) + ".";
244: if (!map.containsKey(prefix2 + REF_NAME)) {
245: break;
246: }
247: ReferenceData data = new ReferenceData();
248: data.load(request, prefix2);
249: list.add(data);
250: }
251: }
252:
253: public void readWebServiceRefsData(PortletRequest request) {
254: Map map = request.getParameterMap();
255: for (int i = 0; i < getWebServiceRefs().size(); i++) {
256: GerServiceRefType serviceRef = getWebServiceRefs().get(
257: i);
258: for (int j = serviceRef.getPortArray().length - 1; j >= 0; j--) {
259: serviceRef.removePort(j);
260: }
261: String prefix1 = "serviceRef" + "." + i + "." + "port"
262: + ".";
263: int lastIndex = Integer.parseInt(request
264: .getParameter(prefix1 + "lastIndex"));
265: for (int j = 0; j < lastIndex; j++) {
266: String prefix2 = prefix1 + j + ".";
267: if (!map.containsKey(prefix2 + "portName")) {
268: continue;
269: }
270: GerPortType port = serviceRef.addNewPort();
271: String value = request.getParameter(prefix2
272: + "portName");
273: if (!isEmpty(value)) {
274: port.setPortName(value);
275: }
276: value = request.getParameter(prefix2 + "protocol");
277: if (!isEmpty(value)) {
278: port.setProtocol(value);
279: }
280: value = request.getParameter(prefix2 + "host");
281: if (!isEmpty(value)) {
282: port.setHost(value);
283: }
284: value = request.getParameter(prefix2 + "port");
285: if (!isEmpty(value)) {
286: int portValue = Integer.parseInt(value);
287: port.setPort(portValue);
288: }
289: value = request.getParameter(prefix2 + "uri");
290: if (!isEmpty(value)) {
291: port.setUri(value);
292: }
293: value = request.getParameter(prefix2
294: + "credentialsName");
295: if (!isEmpty(value)) {
296: port.setCredentialsName(value);
297: }
298: }
299: }
300: }
301:
302: public void readSecurityData(PortletRequest request) {
303: securityRealmName = request
304: .getParameter("securityRealmName");
305: readSecurityParameters(request);
306: }
307:
308: private void readSecurityParameters(PortletRequest request) {
309: Map map = request.getParameterMap();
310: boolean processAdvancedSettings = false;
311: if (map.containsKey("security.advancedSettings.isPresent")
312: && "true"
313: .equalsIgnoreCase(request
314: .getParameter("security.advancedSettings.isPresent"))) {
315: processAdvancedSettings = true;
316: }
317: GerRoleType[] roles = security.getRoleMappings()
318: .getRoleArray();
319: for (int index = 0; index < roles.length; index++) {
320: String prefix1 = "security.roleMappings" + "." + index
321: + ".";
322: GerRoleType role = roles[index];
323:
324: for (int i = role.sizeOfPrincipalArray() - 1; i >= 0; i--) {
325: role.removePrincipal(i);
326: }
327: int lastIndex = Integer.parseInt(request
328: .getParameter(prefix1 + "principal.lastIndex"));
329: for (int i = 0; i < lastIndex; i++) {
330: String prefix2 = prefix1 + "principal" + "." + i
331: + ".";
332: if (!map.containsKey(prefix2 + "name")) {
333: continue;
334: }
335: GerPrincipalType principal = role.addNewPrincipal();
336: principal.setName(request.getParameter(prefix2
337: + "name"));
338: principal.setClass1(request.getParameter(prefix2
339: + "class"));
340: }
341:
342: for (int i = role.sizeOfLoginDomainPrincipalArray() - 1; i >= 0; i--) {
343: role.removeLoginDomainPrincipal(i);
344: }
345: lastIndex = Integer.parseInt(request
346: .getParameter(prefix1
347: + "loginDomainPrincipal.lastIndex"));
348: for (int i = 0; i < lastIndex; i++) {
349: String prefix2 = prefix1 + "loginDomainPrincipal"
350: + "." + i + ".";
351: if (!map.containsKey(prefix2 + "name")) {
352: continue;
353: }
354: GerLoginDomainPrincipalType loginDomainPrincipal = role
355: .addNewLoginDomainPrincipal();
356: loginDomainPrincipal.setName(request
357: .getParameter(prefix2 + "name"));
358: loginDomainPrincipal.setClass1(request
359: .getParameter(prefix2 + "class"));
360: loginDomainPrincipal.setDomainName(request
361: .getParameter(prefix2 + "domainName"));
362: }
363:
364: for (int i = role.sizeOfRealmPrincipalArray() - 1; i >= 0; i--) {
365: role.removeRealmPrincipal(i);
366: }
367: lastIndex = Integer.parseInt(request
368: .getParameter(prefix1
369: + "realmPrincipal.lastIndex"));
370: for (int i = 0; i < lastIndex; i++) {
371: String prefix2 = prefix1 + "realmPrincipal" + "."
372: + i + ".";
373: if (!map.containsKey(prefix2 + "name")) {
374: continue;
375: }
376: GerRealmPrincipalType realmPrincipal = role
377: .addNewRealmPrincipal();
378: realmPrincipal.setName(request.getParameter(prefix2
379: + "name"));
380: realmPrincipal.setClass1(request
381: .getParameter(prefix2 + "class"));
382: realmPrincipal.setDomainName(request
383: .getParameter(prefix2 + "domainName"));
384: realmPrincipal.setRealmName(request
385: .getParameter(prefix2 + "realmName"));
386: }
387:
388: for (int i = role.sizeOfDistinguishedNameArray() - 1; i >= 0; i--) {
389: role.removeDistinguishedName(i);
390: }
391: lastIndex = Integer.parseInt(request
392: .getParameter(prefix1
393: + "distinguishedName.lastIndex"));
394: for (int i = 0; i < lastIndex; i++) {
395: String prefix2 = prefix1 + "distinguishedName"
396: + "." + i + ".";
397: if (!map.containsKey(prefix2 + "name")) {
398: continue;
399: }
400: GerDistinguishedNameType distinguishedName = role
401: .addNewDistinguishedName();
402: distinguishedName.setName(request
403: .getParameter(prefix2 + "name"));
404: }
405:
406: if (processAdvancedSettings) {
407: String prefix2 = prefix1 + "runAsSubject" + ".";
408: if (map.containsKey(prefix2 + "realm")) {
409: if (role.isSetRunAsSubject()) {
410: role.unsetRunAsSubject();
411: }
412: String realm = request.getParameter(prefix2
413: + "realm");
414: String id = request
415: .getParameter(prefix2 + "id");
416: if (!isEmpty(realm) && !isEmpty(id)) {
417: GerSubjectInfoType runAsSubject = role
418: .addNewRunAsSubject();
419: runAsSubject.setRealm(realm);
420: runAsSubject.setId(id);
421: }
422: }
423: }
424: }
425: if (processAdvancedSettings) {
426: String parameterName = "security" + "."
427: + "credentialStoreRef";
428: if (map.containsKey(parameterName)) {
429: String patternString = request
430: .getParameter(parameterName);
431: String[] elements = patternString.split("/", 6);
432: PatternType pattern = PatternType.Factory
433: .newInstance();
434: pattern.setGroupId(elements[0]);
435: pattern.setArtifactId(elements[1]);
436: //pattern.setVersion(elements[2]);
437: //pattern.setType(elements[3]);
438: //pattern.setModule(elements[4]);
439: pattern.setName(elements[5]);
440: security.setCredentialStoreRef(pattern);
441: dependencies.add(JSR88_Util
442: .getDependencyString(patternString));
443: }
444: String prefix = "security" + "." + "defaultSubject"
445: + ".";
446: if (map.containsKey(prefix + "realm")) {
447: if (security.isSetDefaultSubject()) {
448: security.unsetDefaultSubject();
449: }
450: String realm = request.getParameter(prefix
451: + "realm");
452: String id = request.getParameter(prefix + "id");
453: if (!isEmpty(realm) && !isEmpty(id)) {
454: GerSubjectInfoType runAsSubject = security
455: .addNewDefaultSubject();
456: runAsSubject.setRealm(realm);
457: runAsSubject.setId(id);
458: }
459: }
460: parameterName = "security" + "." + "doasCurrentCaller";
461: if ("true".equalsIgnoreCase(request
462: .getParameter(parameterName))) {
463: security.setDoasCurrentCaller(true);
464: }
465: parameterName = "security" + "." + "useContextHandler";
466: if ("true".equalsIgnoreCase(request
467: .getParameter(parameterName))) {
468: security.setUseContextHandler(true);
469: }
470: String defaultRole = request.getParameter("security"
471: + "." + "defaultRole");
472: if (!isEmpty(defaultRole)) {
473: security.setDefaultRole(defaultRole);
474: }
475: }
476: }
477:
478: public String getContextRoot() {
479: return contextRoot;
480: }
481:
482: public void setContextRoot(String contextRoot) {
483: this .contextRoot = contextRoot;
484: }
485:
486: public String getArtifactId() {
487: return artifactId;
488: }
489:
490: public void setArtifactId(String artifactId) {
491: this .artifactId = artifactId;
492: }
493:
494: public String getGroupId() {
495: return groupId;
496: }
497:
498: public void setGroupId(String groupId) {
499: this .groupId = groupId;
500: }
501:
502: public String getType() {
503: return type;
504: }
505:
506: public void setType(String type) {
507: this .type = type;
508: }
509:
510: public String getVersion() {
511: return version;
512: }
513:
514: public void setVersion(String version) {
515: this .version = version;
516: }
517:
518: public String getHiddenClasses() {
519: return hiddenClasses;
520: }
521:
522: public void setHiddenClasses(String hiddenClasses) {
523: this .hiddenClasses = hiddenClasses;
524: }
525:
526: public String getNonOverridableClasses() {
527: return nonOverridableClasses;
528: }
529:
530: public void setNonOverridableClasses(
531: String nonOverridableClasses) {
532: this .nonOverridableClasses = nonOverridableClasses;
533: }
534:
535: public boolean isInverseClassLoading() {
536: return inverseClassLoading;
537: }
538:
539: public void setInverseClassLoading(boolean inverseClassLoading) {
540: this .inverseClassLoading = inverseClassLoading;
541: }
542:
543: public List getDependencies() {
544: return dependencies;
545: }
546:
547: public List getEjbLocalRefs() {
548: return ejbLocalRefs;
549: }
550:
551: public List getEjbRefs() {
552: return ejbRefs;
553: }
554:
555: public List getJdbcPoolRefs() {
556: return jdbcPoolRefs;
557: }
558:
559: public List getJmsConnectionFactoryRefs() {
560: return jmsConnectionFactoryRefs;
561: }
562:
563: public List getJmsDestinationRefs() {
564: return jmsDestinationRefs;
565: }
566:
567: public List getMessageDestinations() {
568: return messageDestinations;
569: }
570:
571: public List getJavaMailSessionRefs() {
572: return javaMailSessionRefs;
573: }
574:
575: public List<GerServiceRefType> getWebServiceRefs() {
576: return webServiceRefs;
577: }
578:
579: public boolean isReferenceNotResolved() {
580: return referenceNotResolved;
581: }
582:
583: public void setReferenceNotResolved(boolean referenceNotResolved) {
584: this .referenceNotResolved = referenceNotResolved;
585: }
586:
587: public String getUploadedWarUri() {
588: return uploadedWarUri;
589: }
590:
591: public void setUploadedWarUri(String uploadedWarUri) {
592: this .uploadedWarUri = uploadedWarUri;
593: }
594:
595: public String getDeploymentPlan() {
596: return deploymentPlan;
597: }
598:
599: public void setDeploymentPlan(String deploymentPlan) {
600: this .deploymentPlan = deploymentPlan;
601: }
602:
603: public String getSecurityRealmName() {
604: return securityRealmName;
605: }
606:
607: public void setSecurityRealmName(String securityRealmName) {
608: this .securityRealmName = securityRealmName;
609: }
610:
611: public GerSecurityType getSecurity() {
612: return security;
613: }
614:
615: public void setSecurity(GerSecurityType security) {
616: this .security = security;
617: }
618: }
619:
620: public static class ReferenceData {
621: private String refName;
622:
623: private String refLink;
624:
625: public ReferenceData() {
626: }
627:
628: public ReferenceData(String refName) {
629: this .refName = refName;
630: }
631:
632: public void load(PortletRequest request, String prefix) {
633: refName = request.getParameter(prefix + REF_NAME);
634: refLink = request.getParameter(prefix + REF_LINK);
635: }
636:
637: public void save(ActionResponse response, String prefix) {
638: if (!isEmpty(refName))
639: response.setRenderParameter(prefix + REF_NAME, refName);
640: if (!isEmpty(refLink))
641: response.setRenderParameter(prefix + REF_LINK, refLink);
642: }
643:
644: public String getRefName() {
645: return refName;
646: }
647:
648: public void setRefName(String refName) {
649: this .refName = refName;
650: }
651:
652: public String getRefLink() {
653: return refLink;
654: }
655:
656: public void setRefLink(String refLink) {
657: this.refLink = refLink;
658: }
659: }
660: }
|