コード例 #1
0
 @RolesAllowed({"ROLE_USER"})
 @GET
 public List<ReportResponse> getReports(@Context SecurityContext context) throws EntityException {
   User user = loadUserFromSecurityContext(context);
   if (user != null) {
     log.info("reading all entities by " + user.getId());
     List<Report> list = reportService.listReports();
     List<ReportResponse> listResponse =
         list.stream().map(ReportResponse::new).collect(Collectors.toList());
     return listResponse;
   } else {
     log.info("rejected unauth user reading entities action");
     throw new UnauthorizedUserException("you don't have permit to loading all entities");
   }
 }
コード例 #2
0
 @RolesAllowed({"ROLE_USER"})
 @POST
 public ReportResponse createReport(@Context SecurityContext context, CreateReportRequest request)
     throws EntityException {
   if (request == null) {
     throw new NullParametersException("report");
   }
   User user = loadUserFromSecurityContext(context);
   if (user != null) {
     log.info("creating report [" + request.getName() + "] by [" + user.getId() + "]");
     ReportResponse reportResponse = reportService.createReportFromRequest(request);
     return reportResponse;
   } else {
     log.info("rejected unauth user creating report action");
     throw new UnauthorizedUserException("you don't have permit to create reports");
   }
 }