001/* 002 * (C) Copyright 2006-2008 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * bstefanescu 018 * 019 * $Id$ 020 */ 021 022package org.nuxeo.ecm.webengine.model.impl; 023 024import java.text.ParseException; 025import java.util.Arrays; 026import java.util.HashSet; 027 028import org.nuxeo.ecm.core.api.NuxeoException; 029import org.nuxeo.ecm.webengine.WebEngine; 030import org.nuxeo.ecm.webengine.loader.ClassProxy; 031import org.nuxeo.ecm.webengine.model.Access; 032import org.nuxeo.ecm.webengine.model.WebObject; 033import org.nuxeo.ecm.webengine.security.PermissionService; 034import org.nuxeo.ecm.webengine.security.guards.And; 035import org.nuxeo.ecm.webengine.security.guards.IsAdministratorGuard; 036import org.nuxeo.runtime.annotations.AnnotationManager; 037 038import com.sun.jersey.server.spi.component.ResourceComponentConstructor; 039 040/** 041 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 042 */ 043public class ResourceTypeImpl extends AbstractResourceType { 044 045 public ResourceTypeImpl(WebEngine engine, ModuleImpl module, ResourceTypeImpl superType, String name, 046 ClassProxy clazz, ResourceComponentConstructor constructor, int visibility) { 047 super(engine, module, superType, name, clazz, constructor, visibility); 048 } 049 050 @Override 051 protected void loadAnnotations(AnnotationManager annoMgr) { 052 Class<?> c = clazz.get(); 053 WebObject wo = c.getAnnotation(WebObject.class); 054 if (wo == null) { 055 return; 056 } 057 String g = wo.guard(); 058 if (g != null && g.length() > 0) { 059 try { 060 guard = PermissionService.parse(g); 061 } catch (ParseException e) { 062 throw new NuxeoException("Failed to parse guard: " + g + " on WebObject " + c.getName(), e); 063 } 064 } else { 065 loadGuardFromAnnoation(c); 066 } 067 Access requireAdministrators = wo.administrator(); 068 if (requireAdministrators != Access.NULL) { 069 if (guard != null) { 070 guard = new And(new IsAdministratorGuard(requireAdministrators), guard); 071 } else { 072 guard = new IsAdministratorGuard(requireAdministrators); 073 } 074 } 075 String[] facets = wo.facets(); 076 if (facets != null && facets.length > 0) { 077 this.facets = new HashSet<String>(Arrays.asList(facets)); 078 } 079 } 080 081}