use of javax.annotation.security.RolesAllowed in project ff4j by ff4j.
the class FF4jAuthorizationFilter method getRoles.
private Set<String> getRoles() {
Set<String> roles = new HashSet<String>();
RolesAllowed ra1 = info.getResourceClass().getAnnotation(RolesAllowed.class);
if (ra1 != null) {
roles.addAll(Arrays.asList(ra1.value()));
}
RolesAllowed ra2 = info.getResourceMethod().getAnnotation(RolesAllowed.class);
if (ra2 != null) {
roles.addAll(Arrays.asList(ra2.value()));
}
return roles;
}
use of javax.annotation.security.RolesAllowed in project openscoring by openscoring.
the class ModelResource method undeploy.
@DELETE
@Path("{id:" + ModelRegistry.ID_REGEX + "}")
@RolesAllowed(value = { "admin" })
@Produces(MediaType.APPLICATION_JSON)
public SimpleResponse undeploy(@PathParam("id") String id) {
Model model = this.modelRegistry.get(id);
if (model == null) {
throw new NotFoundException("Model \"" + id + "\" not found");
}
boolean success = this.modelRegistry.remove(id, model);
if (!success) {
throw new InternalServerErrorException("Concurrent modification");
}
final String prefix = createNamePrefix(id);
MetricFilter filter = new MetricFilter() {
@Override
public boolean matches(String name, Metric metric) {
return name.startsWith(prefix);
}
};
this.metricRegistry.removeMatching(filter);
SimpleResponse response = new SimpleResponse();
return response;
}
use of javax.annotation.security.RolesAllowed in project coastal-hazards by USGS-CIDA.
the class ItemResource method postItem.
/**
* Only allows one card to be posted at a time for now
*
* @param content Posted content as text string (should be JSON)
* @param request passed through context of request
* @return
*/
@RolesAllowed({ CoastalHazardsTokenBasedSecurityFilter.CCH_ADMIN_ROLE })
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response postItem(String content, @Context HttpServletRequest request) {
Response response;
Item item = Item.fromJSON(content);
final String id;
try (ItemManager itemManager = new ItemManager()) {
id = itemManager.persist(item);
}
if (null == id) {
throw new BadRequestException();
} else {
Map<String, Object> ok = new HashMap<String, Object>() {
private static final long serialVersionUID = 2398472L;
{
put("id", id);
}
};
response = Response.ok(GsonUtil.getDefault().toJson(ok, HashMap.class), MediaType.APPLICATION_JSON_TYPE).build();
}
try (StatusManager statusMan = new StatusManager();
ThumbnailManager thumbMan = new ThumbnailManager()) {
Status status = new Status();
status.setStatusName(Status.StatusName.ITEM_UPDATE);
statusMan.save(status);
thumbMan.updateDirtyBits(id);
}
return response;
}
use of javax.annotation.security.RolesAllowed in project coastal-hazards by USGS-CIDA.
the class MetadataResource method acceptMetadata.
@POST
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ CoastalHazardsTokenBasedSecurityFilter.CCH_ADMIN_ROLE })
public Response acceptMetadata(@Context HttpServletRequest req) throws IOException {
int maxFileSize = FILE_UPLOAD_MAX_SIZE;
int fileSize = Integer.parseInt(req.getHeader("Content-Length"));
File tempFile = File.createTempFile(UUID.randomUUID().toString(), "temp");
Map<String, String> responseContent = new HashMap<>();
String fileName;
if (maxFileSize > 0 && fileSize > maxFileSize) {
responseContent.put("message", "File too large");
responseContent.put("success", "false");
return Response.notAcceptable(null).entity(responseContent).build();
}
try {
FileUtils.forceMkdir(UPLOAD_DIR);
} catch (IOException ex) {
return Response.serverError().build();
}
try {
FormUploadHandler.saveFileFromRequest(req, FILENAME_PARAM, tempFile);
} catch (FileUploadException | IOException ex) {
responseContent.put("message", ex.getMessage());
responseContent.put("success", "false");
return Response.serverError().entity(responseContent).build();
}
try {
fileName = StringHelper.makeSHA1Hash(IOUtils.toString(new FileInputStream(tempFile)));
} catch (NoSuchAlgorithmException ex) {
responseContent.put("message", ex.getMessage());
responseContent.put("success", "false");
return Response.serverError().entity(responseContent).build();
}
File savedFile = new File(UPLOAD_DIR, fileName);
if (savedFile.exists()) {
responseContent.put("fid", fileName);
} else {
FileUtils.moveFile(tempFile, savedFile);
responseContent.put("fid", fileName);
}
responseContent.put("success", "true");
return Response.ok(GsonUtil.getDefault().toJson(responseContent, HashMap.class), MediaType.APPLICATION_JSON_TYPE).build();
}
use of javax.annotation.security.RolesAllowed in project coastal-hazards by USGS-CIDA.
the class TemplateResource method instantiateStormTemplate.
@GET
@Path("/storm")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ CoastalHazardsTokenBasedSecurityFilter.CCH_ADMIN_ROLE })
public Response instantiateStormTemplate(@Context HttpServletRequest request, @QueryParam("layerId") String layerId, @QueryParam("activeStorm") String active, @QueryParam("alias") String alias, @QueryParam("copyType") String copyType, @QueryParam("copyVal") String copyVal, @QueryParam("trackId") String trackId) {
Response response;
if (layerId != null && active != null) {
Gson gson = GsonUtil.getDefault();
String childJson = null;
childJson = gson.toJson(StormUtil.createStormChildMap(layerId, Boolean.parseBoolean(active), trackId));
if (childJson != null && childJson.length() > 0) {
try (ItemManager itemMan = new ItemManager();
LayerManager layerMan = new LayerManager();
AliasManager aliasMan = new AliasManager()) {
Layer layer = layerMan.load(layerId);
if (layer != null) {
Summary summary = null;
if (copyType.equalsIgnoreCase("item") || copyType.equalsIgnoreCase("alias")) {
summary = copyExistingSummary(copyType, copyVal, itemMan, aliasMan);
} else {
summary = StormUtil.buildStormTemplateSummary(layer);
}
if (summary != null) {
List<Service> services = layer.getServices();
List<Service> serviceCopies = new LinkedList<>();
for (Service service : services) {
serviceCopies.add(Service.copyValues(service, new Service()));
}
Item baseTemplate = baseTemplateItem(Boolean.parseBoolean(active), layer.getBbox(), serviceCopies, summary);
String templateId = itemMan.persist(baseTemplate);
if (templateId != null && templateId.length() > 0) {
response = instantiateTemplate(request, templateId, childJson);
if (response.getStatus() == HttpStatus.SC_OK) {
Map<String, Object> ok = new HashMap<String, Object>() {
private static final long serialVersionUID = 2398472L;
{
put("id", templateId);
}
};
if (alias != null && alias.length() > 0) {
Alias fullAlias = aliasMan.load(alias);
if (fullAlias != null) {
fullAlias.setItemId(templateId);
aliasMan.update(fullAlias);
} else {
fullAlias = new Alias();
fullAlias.setId(alias);
fullAlias.setItemId(templateId);
aliasMan.save(fullAlias);
}
}
response = Response.ok(GsonUtil.getDefault().toJson(ok, HashMap.class), MediaType.APPLICATION_JSON_TYPE).build();
}
} else {
response = Response.status(500).build();
}
} else {
response = Response.status(400).build();
}
} else {
response = Response.status(400).build();
}
} catch (Exception e) {
log.error(e.toString());
response = Response.status(500).build();
}
} else {
response = Response.status(400).build();
}
} else {
response = Response.status(400).build();
}
return response;
}
Aggregations