2
* Software License Agreement (BSD License)
4
* Copyright (c) 2008, Regents of the University of California
7
* Redistribution and use of this software in source and binary forms, with or
8
* without modification, are permitted provided that the following conditions
11
* * Redistributions of source code must retain the above
12
* copyright notice, this list of conditions and the
13
* following disclaimer.
15
* * Redistributions in binary form must reproduce the above
16
* copyright notice, this list of conditions and the
17
* following disclaimer in the documentation and/or other
18
* materials provided with the distribution.
20
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
* POSSIBILITY OF SUCH DAMAGE.
32
* Author: Sunil Soman sunils@cs.ucsb.edu
35
package edu.ucsb.eucalyptus.cloud.entities;
37
import edu.ucsb.eucalyptus.msgs.AccessControlListType;
38
import edu.ucsb.eucalyptus.msgs.Grant;
39
import edu.ucsb.eucalyptus.msgs.MetaDataEntry;
40
import edu.ucsb.eucalyptus.util.UserManagement;
41
import org.hibernate.annotations.Cache;
42
import org.hibernate.annotations.CacheConcurrencyStrategy;
44
import javax.persistence.*;
45
import java.util.ArrayList;
46
import java.util.Date;
47
import java.util.List;
50
@Table( name = "Objects" )
51
@Cache( usage = CacheConcurrencyStrategy.READ_WRITE )
52
public class ObjectInfo {
55
@Column( name = "object_id" )
56
private Long id = -1l;
58
@Column( name = "owner_id" )
59
private String ownerId;
61
@Column( name = "object_key" )
62
private String objectKey;
64
@Column( name = "object_name" )
65
private String objectName;
67
@Column(name="global_read")
68
private Boolean globalRead;
70
@Column(name="global_write")
71
private Boolean globalWrite;
73
@Column(name="global_read_acp")
74
private Boolean globalReadACP;
76
@Column(name="global_write_acp")
77
private Boolean globalWriteACP;
79
@OneToMany( cascade = CascadeType.ALL )
81
name = "object_has_grants",
82
joinColumns = { @JoinColumn( name = "object_id" ) },
83
inverseJoinColumns = @JoinColumn( name = "grant_id" )
85
@Cache( usage = CacheConcurrencyStrategy.READ_WRITE )
86
private List<GrantInfo> grants = new ArrayList<GrantInfo>();
91
@Column(name="last_modified")
92
private Date lastModified;
97
@Column(name="storage_class")
98
private String storageClass;
100
@OneToMany( cascade = CascadeType.ALL )
102
name = "object_has_metadata",
103
joinColumns = { @JoinColumn( name = "object_id" ) },
104
inverseJoinColumns = @JoinColumn( name = "metadata_id" )
106
@Cache( usage = CacheConcurrencyStrategy.READ_WRITE )
107
@Column(name="metadata")
108
private List<MetaDataInfo> metaData = new ArrayList<MetaDataInfo>();
110
public ObjectInfo() {
113
public ObjectInfo(String ownerId) {
114
this.ownerId = ownerId;
117
public String getObjectKey() {
121
public void setObjectKey(String objectKey) {
122
this.objectKey = objectKey;
125
public String getObjectName() {
129
public void setObjectName(String objectName) {
130
this.objectName = objectName;
133
public String getOwnerId() {
137
public void setOwnerId(String ownerId) {
138
this.ownerId = ownerId;
141
public boolean isGlobalRead() {
145
public void setGlobalRead(Boolean globalRead) {
146
this.globalRead = globalRead;
149
public boolean isGlobalWrite() {
153
public void setGlobalWrite(Boolean globalWrite) {
154
this.globalWrite = globalWrite;
157
public boolean isGlobalReadACP() {
158
return globalReadACP;
161
public void setGlobalReadACP(Boolean globalReadACP) {
162
this.globalReadACP = globalReadACP;
165
public boolean isGlobalWriteACP() {
166
return globalWriteACP;
169
public void setGlobalWriteACP(Boolean globalWriteACP) {
170
this.globalWriteACP = globalWriteACP;
173
public List<GrantInfo> getGrants() {
177
public void setGrants(List<GrantInfo> grants) {
178
this.grants = grants;
181
public String getEtag() {
185
public void setEtag(String etag) {
189
public Date getLastModified() {
193
public void setLastModified(Date lastModified) {
194
this.lastModified = lastModified;
197
public Long getSize() {
201
public void setSize(Long size) {
205
public String getStorageClass() {
209
public void setStorageClass(String storageClass) {
210
this.storageClass = storageClass;
215
public boolean canWrite(String userId) {
220
for (GrantInfo grantInfo: grants) {
221
if (grantInfo.getUserId().equals(userId)) {
222
if (grantInfo.isWrite()) {
228
if(UserManagement.isAdministrator(userId)) {
235
public boolean canRead(String userId) {
240
for (GrantInfo grantInfo: grants) {
241
if (grantInfo.getUserId().equals(userId)) {
242
if (grantInfo.isRead()) {
248
if(UserManagement.isAdministrator(userId)) {
255
public boolean canReadACP(String userId) {
256
if(ownerId.equals(userId)) {
257
//owner can always acp
259
} else if (globalReadACP) {
262
for (GrantInfo grantInfo: grants) {
263
if(grantInfo.getUserId().equals(userId) && grantInfo.isReadACP()) {
269
if(UserManagement.isAdministrator(userId)) {
276
public boolean canWriteACP(String userId) {
277
if (globalWriteACP) {
281
for (GrantInfo grantInfo: grants) {
282
if (grantInfo.getUserId().equals(userId)) {
283
if (grantInfo.isWriteACP()) {
289
if(UserManagement.isAdministrator(userId)) {
296
public void resetGlobalGrants() {
297
globalRead = globalWrite = globalReadACP = globalWriteACP = false;
300
public void addGrants(String ownerId, List<GrantInfo>grantInfos, AccessControlListType accessControlList) {
301
ArrayList<Grant> grants = accessControlList.getGrants();
302
Grant foundGrant = null;
303
globalRead = globalReadACP = false;
304
globalWrite = globalWriteACP = false;
305
if (grants.size() > 0) {
306
for (Grant grant: grants) {
307
String permission = grant.getPermission();
308
if (permission.equals("aws-exec-read")) {
309
globalRead = globalReadACP = false;
310
globalWrite = globalWriteACP = false;
313
} else if (permission.equals("public-read")) {
314
globalRead = globalReadACP = true;
315
globalWrite = globalWriteACP = false;
318
} else if (permission.equals("public-read-write")) {
319
globalRead = globalReadACP = true;
320
globalWrite = globalWriteACP = true;
323
} else if (permission.equals("authenticated-read")) {
324
globalRead = globalReadACP = false;
325
globalWrite = globalWriteACP = false;
331
if(foundGrant != null) {
332
grants.remove(foundGrant);
334
GrantInfo.addGrants(ownerId, grantInfos, accessControlList);
337
public void addMetaData(ArrayList<MetaDataEntry>metaDataEntries) {
338
for (MetaDataEntry metaDataEntry: metaDataEntries) {
339
MetaDataInfo metaDataInfo = new MetaDataInfo();
340
metaDataInfo.setObjectName(objectName);
341
metaDataInfo.setName(metaDataEntry.getName());
342
metaDataInfo.setValue(metaDataEntry.getValue());
343
metaData.add(metaDataInfo);
347
public void getMetaData(ArrayList<MetaDataEntry>metaDataEntries) {
348
for (MetaDataInfo metaDataInfo: metaData) {
349
MetaDataEntry metaDataEntry = new MetaDataEntry();
350
metaDataEntry.setName(metaDataInfo.getName());
351
metaDataEntry.setValue(metaDataInfo.getValue());
352
metaDataEntries.add(metaDataEntry);
b'\\ No newline at end of file'