001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.core.impl.model.portal;
023:
024: import org.jboss.portal.core.model.content.ContentType;
025: import org.jboss.portal.core.model.content.spi.ContentProvider;
026: import org.jboss.portal.core.model.content.spi.ContentProviderRegistry;
027: import org.jboss.portal.core.model.content.spi.handler.ContentHandler;
028: import org.jboss.portal.core.model.portal.Context;
029: import org.jboss.portal.core.model.portal.DuplicatePortalObjectException;
030: import org.jboss.portal.core.model.portal.PortalObject;
031: import org.jboss.portal.core.model.portal.PortalObjectContainer;
032: import org.jboss.portal.core.model.portal.PortalObjectId;
033: import org.jboss.portal.core.model.portal.PortalObjectPath;
034: import org.jboss.portal.core.model.portal.PortalObjectPermission;
035: import org.jboss.portal.jems.as.system.AbstractJBossService;
036: import org.jboss.portal.security.PortalPermission;
037: import org.jboss.portal.security.PortalPermissionCollection;
038: import org.jboss.portal.security.PortalSecurityException;
039: import org.jboss.portal.security.RoleSecurityBinding;
040: import org.jboss.portal.security.spi.provider.AuthorizationDomain;
041: import org.jboss.portal.security.spi.provider.DomainConfigurator;
042: import org.jboss.portal.security.spi.provider.PermissionFactory;
043: import org.jboss.portal.security.spi.provider.PermissionRepository;
044: import org.jboss.portal.security.spi.provider.SecurityConfigurationException;
045:
046: import java.util.Collection;
047: import java.util.HashSet;
048: import java.util.Set;
049:
050: /**
051: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
052: * @version $Revision: 9516 $
053: */
054: public abstract class AbstractPortalObjectContainer extends
055: AbstractJBossService implements PortalObjectContainer,
056: PermissionFactory, AuthorizationDomain, DomainConfigurator,
057: PermissionRepository {
058:
059: /** . */
060: private ContentProviderRegistry contentProviderRegistry;
061:
062: protected AbstractPortalObjectContainer() {
063: }
064:
065: public ContentProviderRegistry getContentProviderRegistry() {
066: return contentProviderRegistry;
067: }
068:
069: public void setContentProviderRegistry(
070: ContentProviderRegistry contentProviderRegistry) {
071: this .contentProviderRegistry = contentProviderRegistry;
072: }
073:
074: // PortalObjectContainer implementation******************************************************************************
075:
076: public org.jboss.portal.core.model.portal.Context getContext() {
077: return getContext("");
078: }
079:
080: public PortalObject getObject(PortalObjectId id)
081: throws IllegalArgumentException {
082: if (id == null) {
083: throw new IllegalArgumentException("No null id accepted");
084: }
085: ObjectNode node = getObjectNode(id);
086: return node == null ? null : node.getObject();
087: }
088:
089: public Context getContext(String namespace) {
090: if (namespace == null) {
091: throw new IllegalArgumentException(
092: "No null namespace accepted");
093: }
094: PortalObjectId id = new PortalObjectId(namespace,
095: PortalObjectPath.ROOT_PATH);
096: ObjectNode node = getObjectNode(id);
097: return node == null ? null : (Context) node.getObject();
098: }
099:
100: public Context createContext(String namespace)
101: throws DuplicatePortalObjectException {
102: if (namespace == null) {
103: throw new IllegalArgumentException(
104: "No null namespace accepted");
105: }
106: return createRoot(namespace);
107: }
108:
109: public AuthorizationDomain getAuthorizationDomain() {
110: return this ;
111: }
112:
113: protected abstract ContextImpl createRoot(String namespace)
114: throws DuplicatePortalObjectException;
115:
116: // AuthorizationDomain implementation *******************************************************************************
117:
118: public String getType() {
119: return PortalObjectPermission.PERMISSION_TYPE;
120: }
121:
122: public DomainConfigurator getConfigurator() {
123: return this ;
124: }
125:
126: public PermissionRepository getPermissionRepository() {
127: return this ;
128: }
129:
130: public PermissionFactory getPermissionFactory() {
131: return this ;
132: }
133:
134: // PermissionFactory implementation *********************************************************************************
135:
136: public PortalPermission createPermissionContainer(
137: PortalPermissionCollection collection)
138: throws PortalSecurityException {
139: return new PortalObjectPermission(collection);
140: }
141:
142: public PortalPermission createPermission(String uri, String action)
143: throws PortalSecurityException {
144: PortalObjectId id = PortalObjectId.parse(uri,
145: PortalObjectPath.CANONICAL_FORMAT);
146: return new PortalObjectPermission(id, action);
147: }
148:
149: public PortalPermission createPermission(String uri,
150: Collection actions) throws PortalSecurityException {
151: PortalObjectId id = PortalObjectId.parse(uri,
152: PortalObjectPath.CANONICAL_FORMAT);
153: return new PortalObjectPermission(id, actions);
154: }
155:
156: // PermissionRepository implementation ******************************************************************************
157:
158: public PortalPermission getPermission(String roleName, String uri)
159: throws PortalSecurityException {
160: PortalObjectId id = PortalObjectId.parse(uri,
161: PortalObjectPath.CANONICAL_FORMAT);
162: ObjectNode on = getObjectNode(id);
163: if (on != null) {
164: RoleSecurityBinding binding = on.getBinding(roleName);
165: if (binding != null) {
166: return createPermission(uri, binding.getActions());
167: }
168: }
169: return null;
170: }
171:
172: // DomainConfigurator implementation ********************************************************************************
173:
174: public void removeSecurityBindings(String uri)
175: throws SecurityConfigurationException {
176: PortalObjectId id = PortalObjectId.parse(uri,
177: PortalObjectPath.CANONICAL_FORMAT);
178: ObjectNode on = getObjectNode(id);
179: if (on == null) {
180: throw new SecurityConfigurationException(
181: "The object should exist prior its security is configured : fixme");
182: }
183: on.setBindings(new HashSet());
184: }
185:
186: public void setSecurityBindings(String uri, Set securityBindings)
187: throws SecurityConfigurationException {
188: PortalObjectId id = PortalObjectId.parse(uri,
189: PortalObjectPath.CANONICAL_FORMAT);
190: ObjectNode on = getObjectNode(id);
191: if (on == null) {
192: throw new SecurityConfigurationException(
193: "The object should exist prior its security is configured : fixme");
194: }
195: on.setBindings(securityBindings);
196: }
197:
198: public Set getSecurityBindings(String uri) {
199: PortalObjectId id = PortalObjectId.parse(uri,
200: PortalObjectPath.CANONICAL_FORMAT);
201: ObjectNode on = getObjectNode(id);
202: if (on != null) {
203: return on.getBindings();
204: } else {
205: return null;
206: }
207: }
208:
209: // ******************************************************************************************************************
210:
211: /**
212: * Must be subclasses to provide the access to a node.
213: *
214: * @param id the portal object path
215: * @return a node or null if not found
216: */
217: protected abstract ObjectNode getObjectNode(PortalObjectId id);
218:
219: public class ContainerContext {
220: /**
221: */
222: public PortalObjectContainer getContainer() {
223: return AbstractPortalObjectContainer.this ;
224: }
225:
226: public ContentType getDefaultContentType() {
227: return ContentType.PORTLET;
228: }
229:
230: /**
231: */
232: public void destroyChild(ObjectNode node) {
233: }
234:
235: /**
236: * @throws DuplicatePortalObjectException
237: */
238: public void createChild(ObjectNode node)
239: throws DuplicatePortalObjectException {
240: }
241:
242: /**
243: */
244: public void updated(ObjectNode node) {
245: }
246:
247: /**
248: */
249: public ContentHandler getContentHandler(ContentType contentType) {
250: ContentProvider contentProvider = contentProviderRegistry
251: .getContentProvider(contentType);
252:
253: //
254: if (contentProvider != null) {
255: return contentProvider.getHandler();
256: } else {
257: return null;
258: }
259: }
260: }
261: }
|