Commit 0df9094c authored by Andrey Lugovskiy's avatar Andrey Lugovskiy Committed by Matija Obreza
Browse files

Enabled ACL support on RepositoryFile

parent 72794bf5
...@@ -119,6 +119,12 @@ ...@@ -119,6 +119,12 @@
<version>${spring.version}</version> <version>${spring.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>${spring.security.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId> <artifactId>spring-test</artifactId>
...@@ -163,8 +169,8 @@ ...@@ -163,8 +169,8 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.genesys-pgr</groupId> <groupId>org.genesys-pgr</groupId>
<artifactId>application-blocks-core</artifactId> <artifactId>application-blocks-security</artifactId>
<version>1.4-SNAPSHOT</version> <version>${application.blocks.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.querydsl</groupId> <groupId>com.querydsl</groupId>
......
...@@ -38,15 +38,14 @@ import javax.persistence.UniqueConstraint; ...@@ -38,15 +38,14 @@ import javax.persistence.UniqueConstraint;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.genesys.blocks.model.AuditedVersionedModelWithoutId; import org.genesys.blocks.model.AuditedVersionedModelWithoutId;
import org.genesys.blocks.model.Copyable; import org.genesys.blocks.model.Copyable;
import org.genesys.blocks.model.EntityId;
import org.genesys.blocks.model.InMemoryIdGenerator; import org.genesys.blocks.model.InMemoryIdGenerator;
import org.genesys.blocks.security.model.AclAwareModel;
import org.genesys.filerepository.metadata.BaseMetadata; import org.genesys.filerepository.metadata.BaseMetadata;
import org.genesys.filerepository.service.BytesStorageService; import org.genesys.filerepository.service.BytesStorageService;
import org.hibernate.annotations.Type; import org.hibernate.annotations.Type;
// TODO: Auto-generated Javadoc
/** /**
* The Class RepositoryFile. * The RepositoryFile.
*/ */
@Entity @Entity
@Table(name = "repositoryfile", @Table(name = "repositoryfile",
...@@ -55,7 +54,7 @@ import org.hibernate.annotations.Type; ...@@ -55,7 +54,7 @@ import org.hibernate.annotations.Type;
// unique // unique
, uniqueConstraints = { @UniqueConstraint(columnNames = { "path", "originalFilename" }) }) , uniqueConstraints = { @UniqueConstraint(columnNames = { "path", "originalFilename" }) })
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class RepositoryFile extends AuditedVersionedModelWithoutId implements EntityId, BaseMetadata, Copyable<RepositoryFile> { public class RepositoryFile extends AuditedVersionedModelWithoutId implements AclAwareModel, BaseMetadata, Copyable<RepositoryFile> {
/** The Constant serialVersionUID. */ /** The Constant serialVersionUID. */
private static final long serialVersionUID = -4816923593950502695L; private static final long serialVersionUID = -4816923593950502695L;
......
...@@ -29,6 +29,8 @@ import org.genesys.filerepository.metadata.ImageMetadata; ...@@ -29,6 +29,8 @@ import org.genesys.filerepository.metadata.ImageMetadata;
import org.genesys.filerepository.model.RepositoryFile; import org.genesys.filerepository.model.RepositoryFile;
import org.genesys.filerepository.model.RepositoryImage; import org.genesys.filerepository.model.RepositoryImage;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PreAuthorize;
// TODO: Auto-generated Javadoc // TODO: Auto-generated Javadoc
/** /**
...@@ -50,8 +52,9 @@ public interface RepositoryService { ...@@ -50,8 +52,9 @@ public interface RepositoryService {
* exception * exception
* @throws IOException when things go wrong on bytes storage level * @throws IOException when things go wrong on bytes storage level
*/ */
RepositoryFile addFile(String repositoryPath, String originalFilename, String contentType, byte[] bytes, RepositoryFile metaData) throws InvalidRepositoryPathException, @PreAuthorize("isAuthenticated()")
InvalidRepositoryFileDataException, IOException; RepositoryFile addFile(String repositoryPath, String originalFilename, String contentType, byte[] bytes, RepositoryFile metaData)
throws InvalidRepositoryPathException, InvalidRepositoryFileDataException, IOException;
/** /**
* Add a new image to the file repository. * Add a new image to the file repository.
...@@ -67,8 +70,9 @@ public interface RepositoryService { ...@@ -67,8 +70,9 @@ public interface RepositoryService {
* exception * exception
* @throws IOException when things go wrong on bytes storage level * @throws IOException when things go wrong on bytes storage level
*/ */
RepositoryImage addImage(String repositoryPath, String originalFilename, String contentType, byte[] bytes, RepositoryImage metaData) throws InvalidRepositoryPathException, @PreAuthorize("isAuthenticated()")
InvalidRepositoryFileDataException, IOException; RepositoryImage addImage(String repositoryPath, String originalFilename, String contentType, byte[] bytes, RepositoryImage metaData)
throws InvalidRepositoryPathException, InvalidRepositoryFileDataException, IOException;
/** /**
* Get repository file by its UUID. * Get repository file by its UUID.
...@@ -78,6 +82,7 @@ public interface RepositoryService { ...@@ -78,6 +82,7 @@ public interface RepositoryService {
* @throws NoSuchRepositoryFileException when file is not available in the * @throws NoSuchRepositoryFileException when file is not available in the
* repository * repository
*/ */
@PostAuthorize("hasRole('ADMINISTRATOR') or hasPermission(returnObject, 'read')")
RepositoryFile getFile(UUID fileUuid) throws NoSuchRepositoryFileException; RepositoryFile getFile(UUID fileUuid) throws NoSuchRepositoryFileException;
/** /**
...@@ -88,6 +93,7 @@ public interface RepositoryService { ...@@ -88,6 +93,7 @@ public interface RepositoryService {
* @return the file * @return the file
* @throws NoSuchRepositoryFileException the no such repository file exception * @throws NoSuchRepositoryFileException the no such repository file exception
*/ */
@PostAuthorize("hasRole('ADMINISTRATOR') or hasPermission(returnObject, 'read')")
RepositoryFile getFile(String path, String filename) throws NoSuchRepositoryFileException; RepositoryFile getFile(String path, String filename) throws NoSuchRepositoryFileException;
/** /**
...@@ -107,6 +113,7 @@ public interface RepositoryService { ...@@ -107,6 +113,7 @@ public interface RepositoryService {
* @return the file bytes * @return the file bytes
* @throws IOException Signals that an I/O exception has occurred. * @throws IOException Signals that an I/O exception has occurred.
*/ */
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#repositoryFile, 'read')")
byte[] getFileBytes(RepositoryFile repositoryFile) throws IOException; byte[] getFileBytes(RepositoryFile repositoryFile) throws IOException;
/** /**
...@@ -124,7 +131,7 @@ public interface RepositoryService { ...@@ -124,7 +131,7 @@ public interface RepositoryService {
* @return the files * @return the files
*/ */
Stream<RepositoryFile> streamFiles(String repositoryPath); Stream<RepositoryFile> streamFiles(String repositoryPath);
/** /**
* Update file metadata. The update is based on the record UUID. * Update file metadata. The update is based on the record UUID.
* *
...@@ -135,6 +142,7 @@ public interface RepositoryService { ...@@ -135,6 +142,7 @@ public interface RepositoryService {
* @throws NoSuchRepositoryFileException when file is not available in the * @throws NoSuchRepositoryFileException when file is not available in the
* repository * repository
*/ */
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#fileData, 'write')")
<T extends RepositoryFile> T updateMetadata(UUID uuid, T fileData) throws NoSuchRepositoryFileException; <T extends RepositoryFile> T updateMetadata(UUID uuid, T fileData) throws NoSuchRepositoryFileException;
/** /**
...@@ -147,6 +155,7 @@ public interface RepositoryService { ...@@ -147,6 +155,7 @@ public interface RepositoryService {
* @throws NoSuchRepositoryFileException the no such repository file exception * @throws NoSuchRepositoryFileException the no such repository file exception
* @throws IOException Signals that an I/O exception has occurred. * @throws IOException Signals that an I/O exception has occurred.
*/ */
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#fileData, 'write')")
RepositoryFile updateBytes(RepositoryFile fileData, String contentType, byte[] bytes) throws NoSuchRepositoryFileException, IOException; RepositoryFile updateBytes(RepositoryFile fileData, String contentType, byte[] bytes) throws NoSuchRepositoryFileException, IOException;
/** /**
...@@ -160,6 +169,7 @@ public interface RepositoryService { ...@@ -160,6 +169,7 @@ public interface RepositoryService {
* @throws NoSuchRepositoryFileException the no such repository file exception * @throws NoSuchRepositoryFileException the no such repository file exception
* @throws IOException Signals that an I/O exception has occurred. * @throws IOException Signals that an I/O exception has occurred.
*/ */
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#imageData, 'write')")
RepositoryImage updateImageBytes(RepositoryImage imageData, String contentType, byte[] bytes) throws NoSuchRepositoryFileException, IOException; RepositoryImage updateImageBytes(RepositoryImage imageData, String contentType, byte[] bytes) throws NoSuchRepositoryFileException, IOException;
/** /**
...@@ -171,6 +181,7 @@ public interface RepositoryService { ...@@ -171,6 +181,7 @@ public interface RepositoryService {
* repository * repository
* @throws IOException Signals that an I/O exception has occurred. * @throws IOException Signals that an I/O exception has occurred.
*/ */
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#repositoryFile, 'delete')")
RepositoryFile removeFile(RepositoryFile repositoryFile) throws NoSuchRepositoryFileException, IOException; RepositoryFile removeFile(RepositoryFile repositoryFile) throws NoSuchRepositoryFileException, IOException;
/** /**
...@@ -182,6 +193,7 @@ public interface RepositoryService { ...@@ -182,6 +193,7 @@ public interface RepositoryService {
* @throws NoSuchRepositoryFileException the no such repository file exception * @throws NoSuchRepositoryFileException the no such repository file exception
* @throws InvalidRepositoryPathException when the new path is invalid * @throws InvalidRepositoryPathException when the new path is invalid
*/ */
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#repositoryFile, 'write')")
RepositoryFile moveFile(RepositoryFile repositoryFile, String newPath) throws NoSuchRepositoryFileException, InvalidRepositoryPathException; RepositoryFile moveFile(RepositoryFile repositoryFile, String newPath) throws NoSuchRepositoryFileException, InvalidRepositoryPathException;
/** /**
...@@ -194,6 +206,7 @@ public interface RepositoryService { ...@@ -194,6 +206,7 @@ public interface RepositoryService {
* @throws InvalidRepositoryFileDataException the invalid repository file data * @throws InvalidRepositoryFileDataException the invalid repository file data
* exception * exception
*/ */
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#repositoryFile, 'write')")
RepositoryFile moveAndRenameFile(RepositoryFile repositoryFile, String fullPath) throws InvalidRepositoryPathException, InvalidRepositoryFileDataException; RepositoryFile moveAndRenameFile(RepositoryFile repositoryFile, String fullPath) throws InvalidRepositoryPathException, InvalidRepositoryFileDataException;
/** /**
...@@ -234,6 +247,7 @@ public interface RepositoryService { ...@@ -234,6 +247,7 @@ public interface RepositoryService {
* @throws NoSuchRepositoryFileException when file is not available in the * @throws NoSuchRepositoryFileException when file is not available in the
* repository * repository
*/ */
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#imageData, 'write')")
RepositoryImage updateImageMetadata(UUID uuid, RepositoryImage imageData) throws NoSuchRepositoryFileException; RepositoryImage updateImageMetadata(UUID uuid, RepositoryImage imageData) throws NoSuchRepositoryFileException;
/** /**
...@@ -245,6 +259,7 @@ public interface RepositoryService { ...@@ -245,6 +259,7 @@ public interface RepositoryService {
* repository * repository
* @throws IOException Signals that an I/O exception has occurred. * @throws IOException Signals that an I/O exception has occurred.
*/ */
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#repositoryImage, 'delete')")
RepositoryImage removeImage(RepositoryImage repositoryImage) throws NoSuchRepositoryFileException, IOException; RepositoryImage removeImage(RepositoryImage repositoryImage) throws NoSuchRepositoryFileException, IOException;
/** /**
......
...@@ -78,7 +78,7 @@ ...@@ -78,7 +78,7 @@
<jdk.source>1.8</jdk.source> <jdk.source>1.8</jdk.source>
<show.deprecations>false</show.deprecations> <show.deprecations>false</show.deprecations>
<application.blocks.version>1.1-SNAPSHOT</application.blocks.version> <application.blocks.version>1.4-SNAPSHOT</application.blocks.version>
<maven-gpg-plugin.version>1.5</maven-gpg-plugin.version> <maven-gpg-plugin.version>1.5</maven-gpg-plugin.version>
<nexus-staging-maven-plugin.version>1.6.8</nexus-staging-maven-plugin.version> <nexus-staging-maven-plugin.version>1.6.8</nexus-staging-maven-plugin.version>
...@@ -87,6 +87,7 @@ ...@@ -87,6 +87,7 @@
<org.hamcrest.version>1.3</org.hamcrest.version> <org.hamcrest.version>1.3</org.hamcrest.version>
<commons.io.version>2.4</commons.io.version> <commons.io.version>2.4</commons.io.version>
<spring.version>4.3.2.RELEASE</spring.version> <spring.version>4.3.2.RELEASE</spring.version>
<spring.security.version>4.1.3.RELEASE</spring.security.version>
<spring.data.version>1.10.4.RELEASE</spring.data.version> <spring.data.version>1.10.4.RELEASE</spring.data.version>
<querydsl.version>4.1.4</querydsl.version> <querydsl.version>4.1.4</querydsl.version>
<hibernate.version>4.3.11.Final</hibernate.version> <hibernate.version>4.3.11.Final</hibernate.version>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment