001: /*
002: * Copyright 2002 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */
013: package com.sun.portal.portletcontainercommon.descriptor;
014:
015: import java.util.List;
016: import java.util.ArrayList;
017: import java.util.Iterator;
018: import java.util.Map;
019: import java.util.HashMap;
020: import java.util.logging.Logger;
021:
022: import org.jdom.Element;
023: import org.jdom.Namespace;
024: import org.jdom.Attribute;
025: import com.sun.portal.log.common.PortalLogger;
026:
027: /**
028: * The security constraint descriptor is the descriptor for defining
029: * portlet security information.
030: * <P>
031: */
032: public class SecurityConstraintDescriptor {
033:
034: // Security constraint descriptor element names
035: public static final String PORTLET_COLLECTION = "portlet-collection";
036: public static final String USER_DATA_CONSTRAINT = "user-data-constraint";
037: public static final String TRANSPORT_GUARANTEE = "transport-guarantee";
038:
039: // Security transport-guarantee types
040: public static final String CONFIDENTIAL = "CONFIDENTIAL";
041: public static final String INTEGRAL = "INTEGRAL";
042: public static final String NONE = "NONE";
043:
044: // Global Variables
045: private List _displayNames = new ArrayList();
046: private Map _displayNameMap = new HashMap();
047: private List _portletNames = new ArrayList();
048: private List _constraintDescs = new ArrayList();
049: private String _transGuaranteeType = NONE;
050:
051: // Create a logger for this class
052: private static Logger debugLogger = PortalLogger
053: .getLogger(SecurityConstraintDescriptor.class);
054:
055: public SecurityConstraintDescriptor(Logger logger) {
056: }
057:
058: /**
059: * Loads the security constraint descriptor
060: */
061: public void load(Element element, Namespace namespace)
062: throws DeploymentDescriptorException {
063:
064: List displayNameElements = element.getChildren(
065: PortletAppDescriptor.DISPLAY_NAME, namespace);
066: for (Iterator i = displayNameElements.iterator(); i.hasNext();) {
067: Element displayNameElement = (Element) i.next();
068: _displayNames.add(displayNameElement.getTextTrim());
069: List attrList = displayNameElement.getAttributes();
070: for (Iterator it = attrList.iterator(); it.hasNext();) {
071: Attribute attr = (Attribute) it.next();
072: if (attr.getName().equals(
073: PortletAppDescriptor.XML_LANG_ATTR)) {
074: _displayNameMap.put(attr.getValue(),
075: displayNameElement.getTextTrim());
076: }
077:
078: }
079: }
080:
081: List portletCollectionElements = element.getChildren(
082: PORTLET_COLLECTION, namespace);
083: for (Iterator i = portletCollectionElements.iterator(); i
084: .hasNext();) {
085: Element portletCollectionElement = (Element) i.next();
086: List portletNameElements = portletCollectionElement
087: .getChildren(PortletDescriptor.PORTLET_NAME,
088: namespace);
089: for (Iterator j = portletNameElements.iterator(); j
090: .hasNext();) {
091: Element portletNameElement = (Element) j.next();
092: String portletName = portletNameElement.getTextTrim();
093: _portletNames.add(portletName);
094: }
095: }
096:
097: Element constraintElement = element.getChild(
098: USER_DATA_CONSTRAINT, namespace);
099: if (constraintElement == null) {
100: debugLogger.warning("PSPL_PCCCSPPCCD0013");
101: } else {
102: _transGuaranteeType = constraintElement.getChildTextTrim(
103: TRANSPORT_GUARANTEE, namespace);
104: List descriptionElements = element.getChildren(
105: PortletAppDescriptor.DESCRIPTION, namespace);
106: for (Iterator i = descriptionElements.iterator(); i
107: .hasNext();) {
108: Element descriptionElement = (Element) i.next();
109: _constraintDescs.add(descriptionElement.getTextTrim());
110: }
111:
112: }
113:
114: }
115:
116: public List getConstrainedPortlets() {
117: return _portletNames;
118: }
119:
120: public String getTransportGuaranteeType() {
121: return _transGuaranteeType;
122: }
123:
124: public List getDisplayNames() {
125: return _displayNames;
126: }
127:
128: /**
129: * Returns display names in a Map
130: * <P>
131: * @return <code>Map</code> of lang/display name pairs of the
132: * display names. Empty <code>Map</code> will be returned
133: * if not defined.
134: */
135: public Map getDisplayNameMap() {
136: return _displayNameMap;
137: }
138:
139: public List getConstraintDescriptions() {
140: return _constraintDescs;
141: }
142:
143: public String toString() {
144: StringBuffer sb = new StringBuffer("PortletDescriptor ");
145:
146: sb.append(" display names [");
147: Iterator iterator = _displayNames.iterator();
148: while (iterator.hasNext()) {
149: sb.append((String) iterator.next());
150: }
151: sb.append(" ]");
152:
153: sb.append(" constrained portlet names [");
154: Iterator iterator1 = _portletNames.iterator();
155: while (iterator1.hasNext()) {
156: sb.append((String) iterator1.next());
157: }
158: sb.append(" ]");
159:
160: if (_transGuaranteeType != null) {
161: sb.append(" transport guarantee type [");
162: sb.append(_transGuaranteeType);
163: sb.append(" ]");
164:
165: sb.append(" constrained portlet names [");
166: Iterator iterator2 = _constraintDescs.iterator();
167: while (iterator2.hasNext()) {
168: sb.append((String) iterator2.next());
169: }
170: sb.append(" ]");
171: }
172: return sb.toString();
173: }
174:
175: }
|