2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2009 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
24 * This document is a part of the source code and related artifacts
25 * for CollectionSpace, an open source collections management system
26 * for museums and related institutions:
28 * http://www.collectionspace.org
29 * http://wiki.collectionspace.org
31 * Copyright 2009 University of California at Berkeley
33 * Licensed under the Educational Community License (ECL), Version 2.0.
34 * You may not use this file except in compliance with this License.
36 * You may obtain a copy of the ECL 2.0 License at
38 * https://source.collectionspace.org/collection-space/LICENSE.txt
40 * Unless required by applicable law or agreed to in writing, software
41 * distributed under the License is distributed on an "AS IS" BASIS,
42 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
43 * See the License for the specific language governing permissions and
44 * limitations under the License.
46 package org.collectionspace.services.authorization;
48 import java.util.StringTokenizer;
51 * A security resource that represents URI and method invoked on it
54 public class URIResourceImpl extends CSpaceResourceImpl {
57 private String method;
58 private CSpaceAction action;
61 * constructor that is usually called from service runtime
63 * @param method an http method
65 public URIResourceImpl(String uri, String method) {
66 super(getParent(uri) + "#" + getAction(method).toString(), TYPE.URI);
67 action = getAction(method);
73 * constructor that is usually called from administrative interface
77 public URIResourceImpl(String resourceName, ActionType actionType) {
78 //FIXME more validation might be needed
79 super(resourceName + "#" + getAction(actionType).toString(), TYPE.URI);
80 action = getAction(actionType);
86 public String getUri() {
91 * @param uri the uri to set
93 public void setUri(String uri) {
100 public String getMethod() {
105 * @param method the method to set
107 public void setMethod(String method) {
108 this.method = method;
112 * getAction a convenience method to get action invoked on the resource
115 public CSpaceAction getAction() {
119 private static String getParent(String uri) {
120 StringTokenizer stz = new StringTokenizer(uri, "/");
121 //FIXME the following ignores sub resources as well as object instances
122 return stz.nextToken();
126 * getAction is a conveneniece method to get action
127 * for given HTTP method invoked on the resource
128 * @param method http method
131 public static CSpaceAction getAction(String method) {
133 if ("POST".equalsIgnoreCase(method)) {
134 return CSpaceAction.CREATE;
135 } else if ("GET".equalsIgnoreCase(method)) {
136 return CSpaceAction.READ;
137 } else if ("PUT".equalsIgnoreCase(method)) {
138 return CSpaceAction.UPDATE;
139 } else if ("DELETE".equalsIgnoreCase(method)) {
140 return CSpaceAction.DELETE;
142 throw new IllegalStateException("no method found!");
146 * getAction is a convenience method to get corresponding action for
151 public static CSpaceAction getAction(ActionType action) {
152 if (ActionType.CREATE.equals(action)) {
153 return CSpaceAction.CREATE;
154 } else if (ActionType.READ.equals(action)) {
155 return CSpaceAction.READ;
156 } else if (ActionType.UPDATE.equals(action)) {
157 return CSpaceAction.UPDATE;
158 } else if (ActionType.DELETE.equals(action)) {
159 return CSpaceAction.DELETE;
160 } else if (ActionType.SEARCH.equals(action)) {
161 return CSpaceAction.SEARCH;
162 } else if (ActionType.ADMIN.equals(action)) {
163 return CSpaceAction.ADMIN;
164 } else if (ActionType.START.equals(action)) {
165 return CSpaceAction.START;
166 } else if (ActionType.STOP.equals(action)) {
167 return CSpaceAction.STOP;
169 throw new IllegalArgumentException("action = " + action.toString());