~ccheney/ubuntu/lucid/eucalyptus/lucid-sru

« back to all changes in this revision

Viewing changes to clc/modules/core/src/edu/ucsb/eucalyptus/cloud/entities/ObjectInfo.java

  • Committer: Bazaar Package Importer
  • Author(s): Soren Hansen
  • Date: 2009-02-11 02:45:39 UTC
  • Revision ID: james.westby@ubuntu.com-20090211024539-0jhzbpg3hk6nu1yg
Tags: upstream-1.5~bzr139
ImportĀ upstreamĀ versionĀ 1.5~bzr139

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Software License Agreement (BSD License)
 
3
 *
 
4
 * Copyright (c) 2008, Regents of the University of California
 
5
 * All rights reserved.
 
6
 *
 
7
 * Redistribution and use of this software in source and binary forms, with or
 
8
 * without modification, are permitted provided that the following conditions
 
9
 * are met:
 
10
 *
 
11
 * * Redistributions of source code must retain the above
 
12
 *   copyright notice, this list of conditions and the
 
13
 *   following disclaimer.
 
14
 *
 
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.
 
19
 *
 
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.
 
31
 *
 
32
 * Author: Sunil Soman sunils@cs.ucsb.edu
 
33
 */
 
34
 
 
35
package edu.ucsb.eucalyptus.cloud.entities;
 
36
 
 
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;
 
43
 
 
44
import javax.persistence.*;
 
45
import java.util.ArrayList;
 
46
import java.util.Date;
 
47
import java.util.List;
 
48
 
 
49
@Entity
 
50
@Table( name = "Objects" )
 
51
@Cache( usage = CacheConcurrencyStrategy.READ_WRITE )
 
52
public class ObjectInfo {
 
53
    @Id
 
54
    @GeneratedValue
 
55
    @Column( name = "object_id" )
 
56
    private Long id = -1l;
 
57
 
 
58
    @Column( name = "owner_id" )
 
59
    private String ownerId;
 
60
 
 
61
    @Column( name = "object_key" )
 
62
    private String objectKey;
 
63
 
 
64
    @Column( name = "object_name" )
 
65
    private String objectName;
 
66
 
 
67
    @Column(name="global_read")
 
68
    private Boolean globalRead;
 
69
 
 
70
    @Column(name="global_write")
 
71
    private Boolean globalWrite;
 
72
 
 
73
    @Column(name="global_read_acp")
 
74
    private Boolean globalReadACP;
 
75
 
 
76
    @Column(name="global_write_acp")
 
77
    private Boolean globalWriteACP;
 
78
 
 
79
    @OneToMany( cascade = CascadeType.ALL )
 
80
    @JoinTable(
 
81
            name = "object_has_grants",
 
82
            joinColumns = { @JoinColumn( name = "object_id" ) },
 
83
            inverseJoinColumns = @JoinColumn( name = "grant_id" )
 
84
    )
 
85
    @Cache( usage = CacheConcurrencyStrategy.READ_WRITE )
 
86
    private List<GrantInfo> grants = new ArrayList<GrantInfo>();
 
87
 
 
88
    @Column(name="etag")
 
89
    private String etag;
 
90
 
 
91
    @Column(name="last_modified")
 
92
    private Date lastModified;
 
93
 
 
94
    @Column(name="size")
 
95
    private Long size;
 
96
 
 
97
    @Column(name="storage_class")
 
98
    private String storageClass;
 
99
 
 
100
    @OneToMany( cascade = CascadeType.ALL )
 
101
    @JoinTable(
 
102
            name = "object_has_metadata",
 
103
            joinColumns = { @JoinColumn( name = "object_id" ) },
 
104
            inverseJoinColumns = @JoinColumn( name = "metadata_id" )
 
105
    )
 
106
    @Cache( usage = CacheConcurrencyStrategy.READ_WRITE )
 
107
    @Column(name="metadata")
 
108
    private List<MetaDataInfo> metaData = new ArrayList<MetaDataInfo>();
 
109
 
 
110
    public ObjectInfo() {
 
111
    }
 
112
 
 
113
    public ObjectInfo(String ownerId) {
 
114
        this.ownerId = ownerId;
 
115
    }
 
116
 
 
117
    public String getObjectKey() {
 
118
        return objectKey;
 
119
    }
 
120
 
 
121
    public void setObjectKey(String objectKey) {
 
122
        this.objectKey = objectKey;
 
123
    }
 
124
 
 
125
    public String getObjectName() {
 
126
        return objectName;
 
127
    }
 
128
 
 
129
    public void setObjectName(String objectName) {
 
130
        this.objectName = objectName;
 
131
    }
 
132
 
 
133
    public String getOwnerId() {
 
134
        return ownerId;
 
135
    }
 
136
 
 
137
    public void setOwnerId(String ownerId) {
 
138
        this.ownerId = ownerId;
 
139
    }
 
140
 
 
141
    public boolean isGlobalRead() {
 
142
        return globalRead;
 
143
    }
 
144
 
 
145
    public void setGlobalRead(Boolean globalRead) {
 
146
        this.globalRead = globalRead;
 
147
    }
 
148
 
 
149
    public boolean isGlobalWrite() {
 
150
        return globalWrite;
 
151
    }
 
152
 
 
153
    public void setGlobalWrite(Boolean globalWrite) {
 
154
        this.globalWrite = globalWrite;
 
155
    }
 
156
 
 
157
    public boolean isGlobalReadACP() {
 
158
        return globalReadACP;
 
159
    }
 
160
 
 
161
    public void setGlobalReadACP(Boolean globalReadACP) {
 
162
        this.globalReadACP = globalReadACP;
 
163
    }
 
164
 
 
165
    public boolean isGlobalWriteACP() {
 
166
        return globalWriteACP;
 
167
    }
 
168
 
 
169
    public void setGlobalWriteACP(Boolean globalWriteACP) {
 
170
        this.globalWriteACP = globalWriteACP;
 
171
    }
 
172
 
 
173
    public List<GrantInfo> getGrants() {
 
174
        return grants;
 
175
    }
 
176
 
 
177
    public void setGrants(List<GrantInfo> grants) {
 
178
        this.grants = grants;
 
179
    }
 
180
 
 
181
    public String getEtag() {
 
182
        return etag;
 
183
    }
 
184
 
 
185
    public void setEtag(String etag) {
 
186
        this.etag = etag;
 
187
    }
 
188
 
 
189
    public Date getLastModified() {
 
190
        return lastModified;
 
191
    }
 
192
 
 
193
    public void setLastModified(Date lastModified) {
 
194
        this.lastModified = lastModified;
 
195
    }
 
196
 
 
197
    public Long getSize() {
 
198
        return size;
 
199
    }
 
200
 
 
201
    public void setSize(Long size) {
 
202
        this.size = size;
 
203
    }
 
204
 
 
205
    public String getStorageClass() {
 
206
        return storageClass;
 
207
    }
 
208
 
 
209
    public void setStorageClass(String storageClass) {
 
210
        this.storageClass = storageClass;
 
211
    }
 
212
 
 
213
 
 
214
 
 
215
    public boolean canWrite(String userId) {
 
216
        if (globalWrite) {
 
217
            return true;
 
218
        }
 
219
 
 
220
        for (GrantInfo grantInfo: grants) {
 
221
            if (grantInfo.getUserId().equals(userId)) {
 
222
                if (grantInfo.isWrite()) {
 
223
                    return true;
 
224
                }
 
225
            }
 
226
        }
 
227
 
 
228
        if(UserManagement.isAdministrator(userId)) {
 
229
            return true;
 
230
        }
 
231
 
 
232
        return false;
 
233
    }
 
234
 
 
235
    public boolean canRead(String userId) {
 
236
        if (globalRead) {
 
237
            return true;
 
238
        }
 
239
 
 
240
        for (GrantInfo grantInfo: grants) {
 
241
            if (grantInfo.getUserId().equals(userId)) {
 
242
                if (grantInfo.isRead()) {
 
243
                    return true;
 
244
                }
 
245
            }
 
246
        }
 
247
 
 
248
        if(UserManagement.isAdministrator(userId)) {
 
249
            return true;
 
250
        }
 
251
 
 
252
        return false;
 
253
    }
 
254
 
 
255
    public boolean canReadACP(String userId) {
 
256
        if(ownerId.equals(userId)) {
 
257
            //owner can always acp
 
258
            return true;
 
259
        } else if (globalReadACP) {
 
260
            return true;
 
261
        } else {
 
262
            for (GrantInfo grantInfo: grants) {
 
263
                if(grantInfo.getUserId().equals(userId) && grantInfo.isReadACP()) {
 
264
                    return true;
 
265
                }
 
266
            }
 
267
        }
 
268
 
 
269
        if(UserManagement.isAdministrator(userId)) {
 
270
            return true;
 
271
        }
 
272
 
 
273
        return false;
 
274
    }
 
275
 
 
276
    public boolean canWriteACP(String userId) {
 
277
        if (globalWriteACP) {
 
278
            return true;
 
279
        }
 
280
 
 
281
        for (GrantInfo grantInfo: grants) {
 
282
            if (grantInfo.getUserId().equals(userId)) {
 
283
                if (grantInfo.isWriteACP()) {
 
284
                    return true;
 
285
                }
 
286
            }
 
287
        }
 
288
 
 
289
        if(UserManagement.isAdministrator(userId)) {
 
290
            return true;
 
291
        }
 
292
 
 
293
        return false;
 
294
    }
 
295
 
 
296
    public void resetGlobalGrants() {
 
297
        globalRead = globalWrite = globalReadACP = globalWriteACP = false;
 
298
    }
 
299
        
 
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;
 
311
                    foundGrant = grant;
 
312
                    break;
 
313
                }   else if (permission.equals("public-read")) {
 
314
                    globalRead = globalReadACP = true;
 
315
                    globalWrite = globalWriteACP = false;
 
316
                    foundGrant = grant;
 
317
                    break;
 
318
                }   else if (permission.equals("public-read-write")) {
 
319
                    globalRead = globalReadACP = true;
 
320
                    globalWrite = globalWriteACP = true;
 
321
                    foundGrant = grant;
 
322
                    break;
 
323
                }   else if (permission.equals("authenticated-read")) {
 
324
                    globalRead = globalReadACP = false;
 
325
                    globalWrite = globalWriteACP = false;
 
326
                    foundGrant = grant;
 
327
                    break;
 
328
                }
 
329
            }
 
330
        }
 
331
        if(foundGrant != null) {
 
332
            grants.remove(foundGrant);
 
333
        }
 
334
        GrantInfo.addGrants(ownerId, grantInfos, accessControlList);
 
335
    }
 
336
 
 
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);
 
344
        }
 
345
    }
 
346
 
 
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);
 
353
        }
 
354
    }
 
355
}
 
 
b'\\ No newline at end of file'