Search in sources :

Example 66 with PreAuthorize

use of org.springframework.security.access.prepost.PreAuthorize in project dhis2-core by dhis2.

the class SmsGatewayController method getGatewayConfiguration.

@PreAuthorize("hasRole('ALL') or hasRole('F_MOBILE_SENDSMS')")
@RequestMapping(value = "/{uid}", method = RequestMethod.GET, produces = "application/json")
public void getGatewayConfiguration(@PathVariable String uid, HttpServletRequest request, HttpServletResponse response) throws WebMessageException, IOException {
    SmsGatewayConfig gateway = gatewayAdminService.getGatewayConfigurationByUid(uid);
    if (gateway == null) {
        throw new WebMessageException(WebMessageUtils.notFound("No gateway found"));
    }
    renderService.toJson(response.getOutputStream(), gateway);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) SmsGatewayConfig(org.hisp.dhis.sms.config.SmsGatewayConfig) BulkSmsGatewayConfig(org.hisp.dhis.sms.config.BulkSmsGatewayConfig) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 67 with PreAuthorize

use of org.springframework.security.access.prepost.PreAuthorize in project dhis2-core by dhis2.

the class SystemSettingController method setSystemSetting.

@RequestMapping(value = "/{key}", method = RequestMethod.POST, consumes = { ContextUtils.CONTENT_TYPE_TEXT, ContextUtils.CONTENT_TYPE_HTML })
@PreAuthorize("hasRole('ALL') or hasRole('F_SYSTEM_SETTING')")
public void setSystemSetting(@PathVariable(value = "key") String key, @RequestParam(value = "value", required = false) String value, @RequestBody(required = false) String valuePayload, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
    if (key == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Key must be specified"));
    }
    if (value == null && valuePayload == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Value must be specified as query param or as payload"));
    }
    value = ObjectUtils.firstNonNull(value, valuePayload);
    Serializable valueObject = SettingKey.getAsRealClass(key, value);
    systemSettingManager.saveSystemSetting(key, valueObject);
    webMessageService.send(WebMessageUtils.ok("System setting " + key + " set to value '" + valueObject + "'."), response, request);
}
Also used : Serializable(java.io.Serializable) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 68 with PreAuthorize

use of org.springframework.security.access.prepost.PreAuthorize in project dhis2-core by dhis2.

the class ResourceTableController method resourceTables.

@RequestMapping(method = { RequestMethod.PUT, RequestMethod.POST })
@PreAuthorize("hasRole('ALL') or hasRole('F_PERFORM_MAINTENANCE')")
public void resourceTables(HttpServletResponse response, HttpServletRequest request) {
    TaskId taskId = new TaskId(TaskCategory.RESOURCETABLE_UPDATE, currentUserService.getCurrentUser());
    scheduler.executeTask(() -> analyticsTableGenerator.generateResourceTables(taskId));
    webMessageService.send(WebMessageUtils.ok("Initiated resource table update"), response, request);
}
Also used : TaskId(org.hisp.dhis.scheduling.TaskId) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 69 with PreAuthorize

use of org.springframework.security.access.prepost.PreAuthorize in project dhis2-core by dhis2.

the class PredictorController method runPredictor.

@RequestMapping(value = "/{uid}/run", method = { RequestMethod.POST, RequestMethod.PUT })
@PreAuthorize("hasRole('ALL') or hasRole('F_PREDICTOR_RUN')")
public void runPredictor(@PathVariable("uid") String uid, @RequestParam Date startDate, @RequestParam Date endDate, TranslateParams translateParams, HttpServletRequest request, HttpServletResponse response) throws Exception {
    Predictor predictor = predictorService.getPredictor(uid);
    try {
        int count = predictorService.predict(predictor, startDate, endDate);
        webMessageService.send(WebMessageUtils.ok("Generated " + count + " predictions"), response, request);
    } catch (Exception ex) {
        log.error("Unable to predict " + predictor.getName(), ex);
        webMessageService.send(WebMessageUtils.conflict("Unable to predict " + predictor.getName(), ex.getMessage()), response, request);
    }
}
Also used : Predictor(org.hisp.dhis.predictor.Predictor) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 70 with PreAuthorize

use of org.springframework.security.access.prepost.PreAuthorize in project dhis2-core by dhis2.

the class PredictorController method runPredictors.

@RequestMapping(value = "/run", method = { RequestMethod.POST, RequestMethod.PUT })
@PreAuthorize("hasRole('ALL') or hasRole('F_PREDICTOR_RUN')")
public void runPredictors(@RequestParam Date startDate, @RequestParam Date endDate, TranslateParams translateParams, HttpServletRequest request, HttpServletResponse response) throws Exception {
    int count = 0;
    List<Predictor> allPredictors = predictorService.getAllPredictors();
    for (Predictor predictor : allPredictors) {
        try {
            count += predictorService.predict(predictor, startDate, endDate);
        } catch (Exception ex) {
            log.error("Unable to predict " + predictor.getName(), ex);
            webMessageService.send(WebMessageUtils.conflict("Unable to predict " + predictor.getName(), ex.getMessage()), response, request);
            return;
        }
    }
    webMessageService.send(WebMessageUtils.ok("Generated " + count + " predictions"), response, request);
}
Also used : Predictor(org.hisp.dhis.predictor.Predictor) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)289 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)234 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)88 ApiOperation (io.swagger.annotations.ApiOperation)70 ModelAndView (org.springframework.web.servlet.ModelAndView)51 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)44 ResponseEntity (org.springframework.http.ResponseEntity)41 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)40 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)36 IOException (java.io.IOException)35 ServiceException (org.nhindirect.common.rest.exceptions.ServiceException)34 InputStream (java.io.InputStream)26 Date (java.util.Date)26 ArrayList (java.util.ArrayList)25 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)23 ConfigurationServiceException (org.nhindirect.config.service.ConfigurationServiceException)21 List (java.util.List)17 HttpHeaders (org.springframework.http.HttpHeaders)16 Grid (org.hisp.dhis.common.Grid)14 SearchDomainForm (org.nhindirect.config.ui.form.SearchDomainForm)14