List of usage examples for org.apache.shiro SecurityUtils getSubject
public static Subject getSubject()
From source file:annis.service.internal.AdminServiceImpl.java
License:Apache License
@GET @Path("import/status/finished/{uuid}") @Override//from www. ja v a2 s.c o m public ImportJob finishedImport(@PathParam("uuid") String uuid) { Subject user = SecurityUtils.getSubject(); user.checkPermission("admin:query-import:finished"); ImportJob job = importWorker.getFinishedJob(uuid); if (job == null) { throw new WebApplicationException(404); } return job; }
From source file:annis.service.internal.AdminServiceImpl.java
License:Apache License
@POST @Path("import") @Consumes({ "application/zip" }) @Override// ww w . ja v a 2 s .c o m public Response importCorpus(@QueryParam("overwrite") String overwriteRaw, @QueryParam("statusMail") String statusMail, @QueryParam("alias") String alias) { Subject user = SecurityUtils.getSubject(); boolean overwrite = Boolean.parseBoolean(overwriteRaw); // write content to temporary file try { File tmpZip = File.createTempFile("annis-import", ".zip"); tmpZip.deleteOnExit(); try (OutputStream tmpOut = new FileOutputStream(tmpZip)) { ByteStreams.copy(request.getInputStream(), tmpOut); } Set<String> allNames = ANNISFormatHelper.corporaInZipfile(tmpZip).keySet(); if (!allNames.isEmpty()) { for (String corpusName : allNames) { user.checkPermission("admin:import:" + corpusName); } String caption = Joiner.on(", ").join(allNames); List<Long> corpusIDs = queryDao.mapCorpusNamesToIds(new LinkedList<>(allNames)); if (overwrite || corpusIDs == null || corpusIDs.isEmpty()) { ImportJob job = new ImportJob(); UUID uuid = UUID.randomUUID(); job.setUuid(uuid.toString()); job.setCaption(caption); job.setImportRootDirectory(tmpZip); job.setStatus(ImportJob.Status.WAITING); job.setOverwrite(overwrite); job.setStatusEmail(statusMail); job.setAlias(alias); corpusAdmin.sendImportStatusMail(statusMail, caption, ImportJob.Status.WAITING, null); try { importWorker.getImportQueue().put(job); return Response.status(Response.Status.ACCEPTED).header("Location", request.getContextPath() + "/annis/admin/import/status/finished/" + uuid.toString()) .build(); } catch (InterruptedException ex) { log.error("Could not add job to import queue", ex); return Response.serverError() .entity("Could not add job to " + "import queue. There might be more information in the server " + "log files. Contact the administrator if necessary.") .build(); } } else { return Response.status(Response.Status.BAD_REQUEST).entity("The corpus already exists").build(); } } else { return Response.status(Response.Status.BAD_REQUEST).entity("no corpus.tab file found in upload") .build(); } } catch (IOException ex) { log.error(null, ex); } return Response.serverError().build(); }
From source file:annis.service.internal.MetadataServiceImpl.java
License:Apache License
@GET @Path("corpus/{toplevel}") @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public List<Annotation> getMetadataTopLevel(@PathParam("toplevel") String topLevelCorpus) { Subject user = SecurityUtils.getSubject(); user.checkPermission("meta:" + topLevelCorpus); return getQueryDao().listCorpusAnnotations(topLevelCorpus); }
From source file:annis.service.internal.MetadataServiceImpl.java
License:Apache License
@Override public List<Annotation> getMetadata(@PathParam("toplevel") String topLevelCorpus, @DefaultValue(value = "false") boolean closure) { Subject user = SecurityUtils.getSubject(); user.checkPermission("meta:" + topLevelCorpus); return getQueryDao().listDocumentsAnnotations(topLevelCorpus, closure); }
From source file:annis.service.internal.MetadataServiceImpl.java
License:Apache License
@GET @Path("docnames/{toplevel}") @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Override/*from w ww.ja v a 2 s.c om*/ public List<Annotation> getDocNames(@PathParam("toplevel") String topLevelCorpus) { Subject user = SecurityUtils.getSubject(); user.checkPermission("meta:" + topLevelCorpus); return getQueryDao().listDocuments(topLevelCorpus); }
From source file:annis.service.internal.MetadataServiceImpl.java
License:Apache License
@GET @Path("binary/{top}/{doc}") @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Override/*w w w.j a v a 2s .c o m*/ public List<AnnisBinaryMetaData> binaryMeta(@PathParam("top") String toplevelCorpusName, @PathParam("doc") String doc) { Subject user = SecurityUtils.getSubject(); user.checkPermission("meta:" + toplevelCorpusName); return getQueryDao().getBinaryMeta(toplevelCorpusName, doc); }
From source file:annis.service.internal.MetadataServiceImpl.java
License:Apache License
@GET @Path("doc/{toplevel}") @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public List<Annotation> getMetaDataDoc(@PathParam("toplevel") String topLevel) { Subject user = SecurityUtils.getSubject(); user.checkPermission("meta:" + topLevel); return getQueryDao().listDocumentsAnnotations(topLevel, false); }
From source file:annis.service.internal.MetadataServiceImpl.java
License:Apache License
@GET @Path("doc/{toplevel}/{doc}") @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public List<Annotation> getMetaDataDoc(@PathParam("toplevel") String topLevelCorpus, @PathParam("doc") String doc) { Subject user = SecurityUtils.getSubject(); user.checkPermission("meta:" + topLevelCorpus); return getQueryDao().listCorpusAnnotations(topLevelCorpus, doc, true); }
From source file:annis.service.internal.MetadataServiceImpl.java
License:Apache License
@Override public List<Annotation> getMetadataDoc(String topLevelCorpus, String docname, boolean path) { Subject user = SecurityUtils.getSubject(); user.checkPermission("meta:" + topLevelCorpus); return getQueryDao().listCorpusAnnotations(topLevelCorpus, docname, path); }
From source file:annis.service.internal.QueryService.java
License:Apache License
@GET @Path("search/count") @Produces("application/xml") public Response count(@QueryParam("q") String query, @QueryParam("corpora") String rawCorpusNames) { requiredParameter(query, "q", "AnnisQL query"); requiredParameter(rawCorpusNames, "corpora", "comma separated list of corpus names"); Subject user = SecurityUtils.getSubject(); List<String> corpusNames = splitCorpusNamesFromRaw(rawCorpusNames); for (String c : corpusNames) { user.checkPermission("query:count:" + c); }/*from ww w . j a va2 s . c o m*/ QueryData data = queryDataFromParameters(query, rawCorpusNames); long start = new Date().getTime(); MatchAndDocumentCount count = annisDao.countMatchesAndDocuments(data); long end = new Date().getTime(); logQuery("COUNT", query, splitCorpusNamesFromRaw(rawCorpusNames), end - start); return Response.ok(count).type(MediaType.APPLICATION_XML_TYPE).build(); }