Example usage for org.springframework.http HttpStatus FORBIDDEN

List of usage examples for org.springframework.http HttpStatus FORBIDDEN

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus FORBIDDEN.

Prototype

HttpStatus FORBIDDEN

To view the source code for org.springframework.http HttpStatus FORBIDDEN.

Click Source Link

Document

403 Forbidden .

Usage

From source file:org.cloudfoundry.identity.uaa.integration.VmcScimUserEndpointIntegrationTests.java

@Test
public void findUsersFails() throws Exception {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> response = serverRunning.getForObject(usersEndpoint, Map.class);
    @SuppressWarnings("unchecked")
    Map<String, Object> results = response.getBody();
    assertEquals(HttpStatus.FORBIDDEN, response.getStatusCode());
    assertNotNull("There should be an error", results.get("error"));
}

From source file:plbtw.klmpk.barang.hilang.controller.BarangController.java

@RequestMapping(method = RequestMethod.POST, produces = "application/json")
public CustomResponseMessage addBarang(@RequestHeader String apiKey, @RequestBody BarangRequest barangRequest) {
    try {/*from w w w. j  a va  2s  . com*/
        if (!authApiKey(apiKey)) {
            return new CustomResponseMessage(HttpStatus.FORBIDDEN, "Please use your api key to authentication");
        }

        if (checkRateLimit(RATE_LIMIT, apiKey)) {
            return new CustomResponseMessage(HttpStatus.BANDWIDTH_LIMIT_EXCEEDED,
                    "Please wait a while, you have reached your rate limit");
        }

        LogRequest temp = DependencyFactory.createLog(apiKey, "Post");

        Log log = new Log();
        log.setApiKey(temp.getApiKey());
        log.setStatus(temp.getStatus());
        log.setTimeRequest(temp.getTime_request());
        logService.addLog(log);

        Barang barang = new Barang();
        barang.setJumlah(barangRequest.getJumlahBarang());
        barang.setKategoriBarang(kategoriBarangService.getKategoriBarang(barangRequest.getIdKategoriBarang()));
        barang.setNama(barangRequest.getNama());
        barang.setStatus(barangRequest.getStatus());
        barang.setUrl_image(barangRequest.getUrl_image());
        barang.setUser(userService.getUser(barangRequest.getIdUserPemilik()));
        barangService.addBarang(barang);
        return new CustomResponseMessage(HttpStatus.CREATED, "Insert Success");
    } catch (Exception ex) {
        return new CustomResponseMessage(HttpStatus.BAD_REQUEST, ex.toString());
    }

}

From source file:org.dawnsci.marketplace.controllers.ExtendedRestApiController.java

/**
 * Uploads a screenshot to the solution and updates the solution data with
 * the name of the file being uploaded. Returns a <b>403 Forbidden</b> if
 * the logged in user is not the owner of the solution.
 *//*from ww w . ja v  a2 s. c  o m*/
@PreAuthorize("hasRole('UPLOAD')")
@RequestMapping(value = "/upload-screenshot")
public ResponseEntity<String> uploadScreenshot(Principal principal, @RequestParam("id") Long id,
        @RequestParam("file") MultipartFile file) throws Exception {
    // verify that we have the correct owner
    Account account = accountRepository.findOne(principal.getName());
    if (!canEdit(principal, id)) {
        return new ResponseEntity<String>("Logged in user is not the owner of the solution",
                HttpStatus.FORBIDDEN);
    }
    fileService.saveSolutionFile(id, file);
    // get solution and update with new information
    Node node = marketplaceDAO.getSolution(id);
    node.setScreenshot(file.getOriginalFilename());
    Object result = marketplaceDAO.saveOrUpdateSolution(node, account);
    if (result instanceof Node) {
        return new ResponseEntity<String>(MarketplaceSerializer.serialize((Node) result), HttpStatus.OK);
    } else {
        return new ResponseEntity<String>((String) result, HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

From source file:org.eclipse.cft.server.core.internal.CloudErrorUtil.java

public static boolean isWrongCredentialsException(CoreException e) {
    Throwable cause = e.getCause();
    if (cause instanceof HttpClientErrorException) {
        HttpClientErrorException httpException = (HttpClientErrorException) cause;
        HttpStatus statusCode = httpException.getStatusCode();
        if (statusCode.equals(HttpStatus.FORBIDDEN) && httpException instanceof CloudFoundryException) {
            return ((CloudFoundryException) httpException).getDescription().equals("Operation not permitted"); //$NON-NLS-1$
        }/*from w  ww. ja va 2  s.com*/
    }
    return false;
}

From source file:org.mitre.uma.web.PolicyAPI.java

/**
 * List all the policies for the given resource set
 * @param rsid//from  w  ww .ja v  a2s .  c  om
 * @param m
 * @param auth
 * @return
 */
@RequestMapping(value = "/{rsid}"
        + POLICYURL, method = RequestMethod.GET, produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public String getPoliciesForResourceSet(@PathVariable(value = "rsid") Long rsid, Model m, Authentication auth) {

    ResourceSet rs = resourceSetService.getById(rsid);

    if (rs == null) {
        m.addAttribute(HttpCodeView.CODE, HttpStatus.NOT_FOUND);
        return HttpCodeView.VIEWNAME;
    }

    if (!rs.getOwner().equals(auth.getName())) {
        logger.warn("Unauthorized resource set request from bad user; expected " + rs.getOwner() + " got "
                + auth.getName());

        // authenticated user didn't match the owner of the resource set
        m.addAttribute(HttpCodeView.CODE, HttpStatus.FORBIDDEN);
        return HttpCodeView.VIEWNAME;
    }

    m.addAttribute(JsonEntityView.ENTITY, rs.getPolicies());

    return JsonEntityView.VIEWNAME;
}

From source file:com.chevres.rss.restapi.controller.UserController.java

@CrossOrigin
@RequestMapping(path = "/user/{username}", method = RequestMethod.DELETE)
@ResponseBody//from w w  w .j a v a  2  s . com
public ResponseEntity<String> deleteUser(@RequestHeader(value = "User-token") String userToken,
        @PathVariable String username) {

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
    UserDAO userDAO = context.getBean(UserDAO.class);
    FeedDAO feedDAO = context.getBean(FeedDAO.class);
    UserAuthDAO userAuthDAO = context.getBean(UserAuthDAO.class);

    UserAuth userAuth = userAuthDAO.findByToken(userToken);
    if (userAuth == null) {
        context.close();
        return new ResponseEntity(new ErrorMessageResponse("invalid_token"), HttpStatus.BAD_REQUEST);
    }

    User user = userDAO.findByUsername(username);
    if (user == null) {
        context.close();
        return new ResponseEntity(HttpStatus.NOT_FOUND);
    }

    boolean isAdmin = userDAO.isAdmin(userAuth.getIdUser());
    if (!isAdmin && (userAuth.getIdUser() != user.getId())) {
        context.close();
        return new ResponseEntity(new ErrorMessageResponse("admin_required"), HttpStatus.FORBIDDEN);
    }

    userAuthDAO.removeAllForUser(user);
    feedDAO.removeAllForUser(user);
    userDAO.delete(user);
    context.close();

    return new ResponseEntity(new SuccessMessageResponse("success"), HttpStatus.OK);
}

From source file:org.craftercms.profile.controllers.rest.ExceptionHandlers.java

@ExceptionHandler(NoSuchVerificationTokenException.class)
public ResponseEntity<Object> handleNoSuchVerificationTokenException(NoSuchVerificationTokenException e,
        WebRequest request) {/*  w ww  .ja  v a2  s .co m*/
    return handleExceptionInternal(e, HttpStatus.FORBIDDEN, ErrorCode.NO_SUCH_VERIFICATION_TOKEN, request);
}

From source file:ru.org.linux.comment.DeleteCommentController.java

@ExceptionHandler({ ScriptErrorException.class, UserErrorException.class, AccessViolationException.class })
@ResponseStatus(HttpStatus.FORBIDDEN)
public ModelAndView handleUserNotFound(Exception ex) {
    ModelAndView mav = new ModelAndView("errors/good-penguin");
    mav.addObject("msgTitle", ": " + ex.getMessage());
    mav.addObject("msgHeader", ex.getMessage());
    mav.addObject("msgMessage", "");
    return mav;/*from   w  w  w  . java 2s  .c  o  m*/
}

From source file:com.wiiyaya.consumer.web.main.controller.ExceptionController.java

/**
 * /*from   w ww .j  a  va 2 s . co m*/
 * @param request ?
 * @param exception 
 * @return ExceptionDto JSON
 */
@ExceptionHandler(value = BusinessException.class)
@ResponseStatus(HttpStatus.FORBIDDEN)
public ModelAndView businessException(HttpServletRequest request, BusinessException exception) {
    String errorMessage = messageSource.getMessage(exception.getCode(), exception.getArguments(),
            LocaleContextHolder.getLocale());
    return prepareExceptionInfo(request, HttpStatus.FORBIDDEN, exception.getCode(), errorMessage);
}

From source file:org.avidj.zuul.rs.ZuulTest.java

@Test
public void itShallRejectLockNestedIntoDeepLock() {
    final Zuul zuul = createZuul();
    given().standaloneSetup(zuul).param("t", "w").param("s", "d").when().put("/s/1/foo").then()
            .statusCode(HttpStatus.CREATED.value());
    given().standaloneSetup(zuul).param("t", "r").when().put("/s/2/foo/bar").then()
            .statusCode(HttpStatus.FORBIDDEN.value());
}