Search in sources :

Example 1 with Handling

use of fi.otavanopisto.security.rest.RESTPermit.Handling in project muikku by otavanopisto.

the class TranscriptofRecordsRESTService method getFileContent.

@GET
@Path("/files/{ID}/content")
@RESTPermit(handling = Handling.INLINE)
@Produces("*/*")
public Response getFileContent(@PathParam("ID") Long fileId) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.FORBIDDEN).entity("Must be logged in").build();
    }
    UserEntity loggedUserEntity = sessionController.getLoggedUserEntity();
    TranscriptOfRecordsFile file = transcriptOfRecordsFileController.findFileById(fileId);
    if (file == null) {
        return Response.status(Status.NOT_FOUND).entity("File not found").build();
    }
    boolean isLoggedUser = Objects.equals(file.getUserEntityId(), loggedUserEntity.getId());
    if (!isLoggedUser) {
        return Response.status(Status.FORBIDDEN).entity("Not your file").build();
    }
    StreamingOutput output = s -> transcriptOfRecordsFileController.outputFileToStream(file, s);
    String contentType = file.getContentType();
    return Response.ok().type(contentType).entity(output).build();
}
Also used : PluginSettingsController(fi.otavanopisto.muikku.controller.PluginSettingsController) Arrays(java.util.Arrays) Produces(javax.ws.rs.Produces) EnvironmentRoleArchetype(fi.otavanopisto.muikku.model.users.EnvironmentRoleArchetype) Path(javax.ws.rs.Path) StringUtils(org.apache.commons.lang3.StringUtils) User(fi.otavanopisto.muikku.schooldata.entity.User) Consumes(javax.ws.rs.Consumes) PermissionController(fi.otavanopisto.muikku.controller.PermissionController) Map(java.util.Map) TranscriptofRecordsUserProperties(fi.otavanopisto.muikku.plugins.transcriptofrecords.TranscriptofRecordsUserProperties) CourseMetaController(fi.otavanopisto.muikku.schooldata.CourseMetaController) DELETE(javax.ws.rs.DELETE) TranscriptOfRecordsFile(fi.otavanopisto.muikku.plugins.transcriptofrecords.model.TranscriptOfRecordsFile) StudiesViewCourseChoice(fi.otavanopisto.muikku.plugins.transcriptofrecords.model.StudiesViewCourseChoice) UserGroupEntityController(fi.otavanopisto.muikku.users.UserGroupEntityController) SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) StreamingOutput(javax.ws.rs.core.StreamingOutput) EnvironmentUser(fi.otavanopisto.muikku.model.users.EnvironmentUser) VopsLister(fi.otavanopisto.muikku.plugins.transcriptofrecords.VopsLister) TranscriptofRecordsPermissions(fi.otavanopisto.muikku.plugins.transcriptofrecords.TranscriptofRecordsPermissions) GradingController(fi.otavanopisto.muikku.schooldata.GradingController) Objects(java.util.Objects) StudiesViewCourseChoiceController(fi.otavanopisto.muikku.plugins.transcriptofrecords.StudiesViewCourseChoiceController) List(java.util.List) UserEntityController(fi.otavanopisto.muikku.users.UserEntityController) Response(javax.ws.rs.core.Response) UserController(fi.otavanopisto.muikku.users.UserController) EnvironmentRoleEntity(fi.otavanopisto.muikku.model.users.EnvironmentRoleEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceController(fi.otavanopisto.muikku.schooldata.WorkspaceController) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) Subject(fi.otavanopisto.muikku.schooldata.entity.Subject) EnvironmentUserController(fi.otavanopisto.muikku.users.EnvironmentUserController) Handling(fi.otavanopisto.security.rest.RESTPermit.Handling) ArrayList(java.util.ArrayList) SessionController(fi.otavanopisto.muikku.session.SessionController) Inject(javax.inject.Inject) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) Status(javax.ws.rs.core.Response.Status) POST(javax.ws.rs.POST) TransferCredit(fi.otavanopisto.muikku.schooldata.entity.TransferCredit) WorkspaceAssessment(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment) IOException(java.io.IOException) TranscriptOfRecordsFileController(fi.otavanopisto.muikku.plugins.transcriptofrecords.TranscriptOfRecordsFileController) Stateful(javax.ejb.Stateful) RestCatchSchoolDataExceptions(fi.otavanopisto.muikku.schooldata.RestCatchSchoolDataExceptions) PluginRESTService(fi.otavanopisto.muikku.plugin.PluginRESTService) WorkspaceUserEntityController(fi.otavanopisto.muikku.users.WorkspaceUserEntityController) RequestScoped(javax.enterprise.context.RequestScoped) PUT(javax.ws.rs.PUT) TranscriptOfRecordsController(fi.otavanopisto.muikku.plugins.transcriptofrecords.TranscriptOfRecordsController) Comparator(java.util.Comparator) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) TranscriptOfRecordsFile(fi.otavanopisto.muikku.plugins.transcriptofrecords.model.TranscriptOfRecordsFile) StreamingOutput(javax.ws.rs.core.StreamingOutput) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with Handling

use of fi.otavanopisto.security.rest.RESTPermit.Handling in project muikku by otavanopisto.

the class WorkspaceRESTService method getWorkspaceFileContent.

@GET
@Path("/workspaces/{WORKSPACEID}/workspacefile/{FILEIDENTIFIER}")
@RESTPermit(handling = Handling.INLINE)
public Response getWorkspaceFileContent(@PathParam("WORKSPACEID") Long workspaceId, @PathParam("FILEIDENTIFIER") String fileIdentifier, @Context Request request) {
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceId);
    if (workspaceEntity == null)
        return Response.status(Status.BAD_REQUEST).build();
    WorkspaceEntityFile imageFile = workspaceEntityFileController.findWorkspaceEntityFile(workspaceEntity, fileIdentifier);
    if (imageFile == null)
        return Response.status(Status.NOT_FOUND).build();
    StreamingOutput output = s -> fileController.outputFileToStream("workspace", imageFile.getDiskName(), s);
    String contentType = imageFile.getContentType();
    String tagIdentifier = String.format("%d-%s-%d", imageFile.getWorkspaceEntity(), imageFile.getDiskName(), imageFile.getLastModified().getTime());
    EntityTag tag = new EntityTag(DigestUtils.md5Hex(String.valueOf(tagIdentifier)));
    ResponseBuilder builder = request.evaluatePreconditions(tag);
    if (builder != null) {
        return builder.build();
    }
    CacheControl cacheControl = new CacheControl();
    cacheControl.setMustRevalidate(true);
    return Response.ok().cacheControl(cacheControl).tag(tag).type(contentType).entity(output).build();
}
Also used : WorkspaceEntityFileRESTModel(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceEntityFileRESTModel) Arrays(java.util.Arrays) Produces(javax.ws.rs.Produces) WorkspaceCompositeReply(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceCompositeReply) EnvironmentRoleArchetype(fi.otavanopisto.muikku.model.users.EnvironmentRoleArchetype) WorkspaceMaterialFileFieldAnswerFile(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialFileFieldAnswerFile) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) Material(fi.otavanopisto.muikku.plugins.material.model.Material) Flag(fi.otavanopisto.muikku.model.users.Flag) StringUtils(org.apache.commons.lang3.StringUtils) User(fi.otavanopisto.muikku.schooldata.entity.User) WorkspaceEntityFileController(fi.otavanopisto.muikku.plugins.workspace.WorkspaceEntityFileController) WorkspaceMaterialAudioFieldAnswerClip(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialAudioFieldAnswerClip) Map(java.util.Map) CourseMetaController(fi.otavanopisto.muikku.schooldata.CourseMetaController) WorkspaceMaterialCompositeReply(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceMaterialCompositeReply) Instance(javax.enterprise.inject.Instance) WorkspaceDetails(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceDetails) WorkspaceFeeInfo(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceFeeInfo) WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder) WorkspaceEntityController(fi.otavanopisto.muikku.schooldata.WorkspaceEntityController) AssessmentRequestController(fi.otavanopisto.muikku.plugins.assessmentrequest.AssessmentRequestController) SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial) Set(java.util.Set) TempFileUtils(fi.otavanopisto.muikku.files.TempFileUtils) IOUtils(org.apache.commons.io.IOUtils) WorkspaceMaterialProducer(fi.otavanopisto.muikku.model.workspace.WorkspaceMaterialProducer) WorkspaceType(fi.otavanopisto.muikku.schooldata.entity.WorkspaceType) WorkspaceFieldIOException(fi.otavanopisto.muikku.plugins.workspace.fieldio.WorkspaceFieldIOException) DatatypeConverter(javax.xml.bind.DatatypeConverter) WorkspaceIndexer(fi.otavanopisto.muikku.plugins.search.WorkspaceIndexer) ZipOutputStream(java.util.zip.ZipOutputStream) GET(javax.ws.rs.GET) MuikkuPermissions(fi.otavanopisto.muikku.security.MuikkuPermissions) WorkspaceMaterialField(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialField) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) Handling(fi.otavanopisto.security.rest.RESTPermit.Handling) WorkspaceVisitController(fi.otavanopisto.muikku.plugins.workspace.WorkspaceVisitController) ArrayList(java.util.ArrayList) SessionController(fi.otavanopisto.muikku.session.SessionController) WorkspaceJournalEntryRESTModel(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceJournalEntryRESTModel) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) WorkspaceMaterialReplyController(fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialReplyController) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) WorkspaceMaterialFieldAnswer(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceMaterialFieldAnswer) IOException(java.io.IOException) MaterialViewRestrict(fi.otavanopisto.muikku.plugins.material.model.MaterialViewRestrict) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) Stateful(javax.ejb.Stateful) RestCatchSchoolDataExceptions(fi.otavanopisto.muikku.schooldata.RestCatchSchoolDataExceptions) WorkspaceUserEntityController(fi.otavanopisto.muikku.users.WorkspaceUserEntityController) SearchProvider(fi.otavanopisto.muikku.search.SearchProvider) WorkspaceMaterialFieldController(fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialFieldController) WorkspaceNodeType(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNodeType) MaterialController(fi.otavanopisto.muikku.plugins.material.MaterialController) WorkspaceMaterialController(fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialController) WorkspaceMaterialReplyState(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialReplyState) Date(java.util.Date) Path(javax.ws.rs.Path) BooleanPredicate(fi.otavanopisto.muikku.model.base.BooleanPredicate) QueryParam(javax.ws.rs.QueryParam) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultValue(javax.ws.rs.DefaultValue) Any(javax.enterprise.inject.Any) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace) ZipEntry(java.util.zip.ZipEntry) Sort(fi.otavanopisto.muikku.search.SearchProvider.Sort) DELETE(javax.ws.rs.DELETE) Context(javax.ws.rs.core.Context) WorkspaceJournalEntry(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceJournalEntry) WorkspaceMaterialAssignmentType(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialAssignmentType) Collection(java.util.Collection) WorkspaceEntityFile(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceEntityFile) WorkspaceMaterialContainsAnswersExeption(fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialContainsAnswersExeption) StreamingOutput(javax.ws.rs.core.StreamingOutput) Logger(java.util.logging.Logger) GradingController(fi.otavanopisto.muikku.schooldata.GradingController) Objects(java.util.Objects) EducationType(fi.otavanopisto.muikku.schooldata.entity.EducationType) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) UserEntityController(fi.otavanopisto.muikku.users.UserEntityController) Response(javax.ws.rs.core.Response) UserController(fi.otavanopisto.muikku.users.UserController) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) WorkspaceMaterialReply(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceMaterialReply) WorkspaceRoleArchetype(fi.otavanopisto.muikku.model.workspace.WorkspaceRoleArchetype) Request(javax.ws.rs.core.Request) CacheControl(javax.ws.rs.core.CacheControl) WorkspaceStudent(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceStudent) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) UserIndexer(fi.otavanopisto.muikku.plugins.search.UserIndexer) WorkspaceController(fi.otavanopisto.muikku.schooldata.WorkspaceController) PathParam(javax.ws.rs.PathParam) WorkspaceRootFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder) FlagController(fi.otavanopisto.muikku.users.FlagController) WorkspaceUser(fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser) HashMap(java.util.HashMap) WorkspaceMaterialDeleteError(fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialDeleteError) Level(java.util.logging.Level) MessagingWidget(fi.otavanopisto.muikku.controller.messaging.MessagingWidget) HashSet(java.util.HashSet) Inject(javax.inject.Inject) FileController(fi.otavanopisto.muikku.plugins.data.FileController) CollectionUtils(org.apache.commons.collections.CollectionUtils) Status(javax.ws.rs.core.Response.Status) OutputStream(java.io.OutputStream) POST(javax.ws.rs.POST) Iterator(java.util.Iterator) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceStaffMember(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceStaffMember) SearchResult(fi.otavanopisto.muikku.search.SearchResult) EntityTag(javax.ws.rs.core.EntityTag) WorkspaceJournalController(fi.otavanopisto.muikku.plugins.workspace.WorkspaceJournalController) PluginRESTService(fi.otavanopisto.muikku.plugin.PluginRESTService) RequestScoped(javax.enterprise.context.RequestScoped) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) QueryFieldController(fi.otavanopisto.muikku.plugins.material.QueryFieldController) WorkspaceMaterialFieldAnswerController(fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialFieldAnswerController) SchoolDataBridgeSessionController(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeSessionController) PUT(javax.ws.rs.PUT) Comparator(java.util.Comparator) DigestUtils(org.apache.commons.codec.digest.DigestUtils) Collections(java.util.Collections) InputStream(java.io.InputStream) WorkspaceEntityFile(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceEntityFile) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) StreamingOutput(javax.ws.rs.core.StreamingOutput) EntityTag(javax.ws.rs.core.EntityTag) CacheControl(javax.ws.rs.core.CacheControl) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Aggregations

EnvironmentRoleArchetype (fi.otavanopisto.muikku.model.users.EnvironmentRoleArchetype)2 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)2 PluginRESTService (fi.otavanopisto.muikku.plugin.PluginRESTService)2 CourseMetaController (fi.otavanopisto.muikku.schooldata.CourseMetaController)2 GradingController (fi.otavanopisto.muikku.schooldata.GradingController)2 RestCatchSchoolDataExceptions (fi.otavanopisto.muikku.schooldata.RestCatchSchoolDataExceptions)2 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)2 WorkspaceController (fi.otavanopisto.muikku.schooldata.WorkspaceController)2 User (fi.otavanopisto.muikku.schooldata.entity.User)2 SessionController (fi.otavanopisto.muikku.session.SessionController)2 UserController (fi.otavanopisto.muikku.users.UserController)2 UserEntityController (fi.otavanopisto.muikku.users.UserEntityController)2 WorkspaceUserEntityController (fi.otavanopisto.muikku.users.WorkspaceUserEntityController)2 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)2 Handling (fi.otavanopisto.security.rest.RESTPermit.Handling)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Comparator (java.util.Comparator)2 List (java.util.List)2