List of usage examples for org.springframework.http HttpStatus FORBIDDEN
HttpStatus FORBIDDEN
To view the source code for org.springframework.http HttpStatus FORBIDDEN.
Click Source Link
From source file:org.swarmcom.jsynapse.controller.client.api.v1.UserRestApiTest.java
@Test public void testUserProfile() throws Exception { //try to set display name for non existing user putAndCheckStatus(/* www . jav a 2 s .c o m*/ "/_matrix/client/api/v1/profile/@user:swarmcom.org/displayname?access_token=abcdef0123456789", putDisplayName, HttpStatus.FORBIDDEN); //try to set avatar for non existing user putAndCheckStatus( "/_matrix/client/api/v1/profile/@user:swarmcom.org/avatar_url?access_token=abcdef0123456789", putAvatarUrl, HttpStatus.FORBIDDEN); //register postAndCompareResult("/_matrix/client/api/v1/register", postLoginRequest, postLoginResponse); //set display name for registered user putAndCheckStatus( "/_matrix/client/api/v1/profile/@user:swarmcom.org/displayname?access_token=abcdef0123456789", putDisplayName, HttpStatus.OK); //get display name for registered user getAndCompareResult( "/_matrix/client/api/v1/profile/@user:swarmcom.org/displayname?access_token=abcdef0123456789", putDisplayName); //set avatar url for registered user putAndCheckStatus( "/_matrix/client/api/v1/profile/@user:swarmcom.org/avatar_url?access_token=abcdef0123456789", putAvatarUrl, HttpStatus.OK); //get avatar url for registered user getAndCompareResult( "/_matrix/client/api/v1/profile/@user:swarmcom.org/avatar_url?access_token=abcdef0123456789", putAvatarUrl); }
From source file:org.smigo.config.RestExceptionResolver.java
@Override public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {// w w w . j a va2 s. c om if (ex instanceof AccessDeniedException) { return getModelAndView(response, HttpStatus.FORBIDDEN, new Object[] { new ObjectError("AccessDenied", "msg.needtobeloggedin") }); } final String uri = (String) request.getAttribute("javax.servlet.error.request_uri"); if (request.getRequestURI().startsWith("/rest/") || uri != null && uri.startsWith("/rest/")) { return getModelAndView(response, HttpStatus.INTERNAL_SERVER_ERROR, new Object[] { new ObjectError("unknown-error", "msg.unknownerror") }); } if (handler == null) { return null; } try { final HandlerMethod handlerMethod = (HandlerMethod) handler; final boolean annotatedWithRestController = handlerMethod.getBeanType() .isAnnotationPresent(RestController.class); final boolean annotatedWithResponseBody = handlerMethod.getMethodAnnotation(ResponseBody.class) != null; if (annotatedWithResponseBody || annotatedWithRestController) { return getModelAndView(response, HttpStatus.INTERNAL_SERVER_ERROR, new Object[] { new ObjectError("unknown-error", "msg.unknownerror") }); } } catch (Exception e) { log.error("Failed to return object error. Handler:" + handler, ex); } return null; }
From source file:fr.itldev.koya.services.UserServiceImplTest.java
@Test public void testUnknownLogin() throws Exception { try {// w w w . j ava2 s . c o m User userUnknown = userService.login("unknown", "unknown"); } catch (AlfrescoServiceException aex) { assertEquals(aex.getHttpErrorCode().intValue(), HttpStatus.FORBIDDEN.value()); } }
From source file:edu.eci.arsw.kalendan.controllers.ProjectResourceController.java
@RequestMapping(method = RequestMethod.POST) public ResponseEntity<?> projectPostRecursoActividad(@RequestBody Activity a) { try {//from ww w.ja v a 2s. c om pj.registrarActividad(a); return new ResponseEntity<>(HttpStatus.CREATED); } catch (Exception e) { Logger.getLogger(ProjectResourceController.class.getName()).log(Level.SEVERE, null, e); return new ResponseEntity<>("Actividad no creada!", HttpStatus.FORBIDDEN); } }
From source file:edu.eci.arsw.kalendan.controllers.TeamResourceController.java
@RequestMapping(path = "/equipos/{idT}/{permiso}", method = RequestMethod.POST) public ResponseEntity<?> teamAddMember(@PathVariable("idT") Integer teamid, @PathVariable String permiso, @RequestBody User u) {/*ww w .j a v a2 s. c om*/ try { List<Project> con = ps.getProyectos(); ts.setProyectos(con); ts.agregaProject(); System.out.println("lalalalala"); ts.agregarMiembro(u, teamid, permiso); return new ResponseEntity<>(HttpStatus.CREATED); } catch (Exception e) { Logger.getLogger(TeamResourceController.class.getName()).log(Level.SEVERE, null, e); return new ResponseEntity<>("Equipo no creado!", HttpStatus.FORBIDDEN); } }
From source file:com.hillert.botanic.controller.AuthenticationControllerTests.java
@Test public void testAuthenticateUnSuccessfully() throws Exception { mockMvc.perform(//w ww . j a v a 2s . c om post("/authenticate").content("{ \"username\": \"wrong\", \"password\": \"password\" }".getBytes()) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andExpect(status().isForbidden()) .andExpect(jsonPath("$.status", Matchers.is(HttpStatus.FORBIDDEN.value()))); }
From source file:com.hyphenated.card.controller.ExceptionController.java
/** * Handles any Illegal State Exception from a controller method * @param e The exception that was thrown * @return JSON Map with error messages specific to the illegal state exception thrown *///from w w w . j a va2 s .c o m @ExceptionHandler(IllegalStateException.class) @ResponseStatus(HttpStatus.FORBIDDEN) public @ResponseBody Map<String, String> handleIOExcpetion(IllegalStateException e) { Map<String, String> error = new HashMap<String, String>(); error.put("error", "Opperation not currently allowed."); error.put("errorDetails", e.getMessage()); log.error("Error: " + e.getMessage()); return error; }
From source file:com.github.marsbits.restfbmessenger.sample.EchoWebhookController.java
@RequestMapping(method = RequestMethod.GET) public ResponseEntity<String> get(@RequestParam(HUB_MODE_PARAM_NAME) String mode, @RequestParam(HUB_VERIFY_TOKEN_PARAM_NAME) String verifyToken, @RequestParam(HUB_CHALLENGE_PARAM_NAME) String challenge) { logger.info("Validating webhook..."); if (HUB_MODE_SUBSCRIBE_VALUE.equals(mode) && messenger.verifyToken(verifyToken)) { logger.info("Validating webhook succeeded"); return new ResponseEntity<>(challenge, HttpStatus.OK); } else {// w w w . j a va2s . com logger.warning("Validating webhook failed"); return new ResponseEntity<>("Failed validation. Make sure the validation tokens match.", HttpStatus.FORBIDDEN); } }
From source file:com.github.woki.payments.adyen.simulator.web.controller.PaymentController.java
@RequestMapping(value = { "/pal/servlet/Payment/v30/authorise", "/pal/servlet/Payment/v30/authorise3d" }, method = RequestMethod.POST) public ResponseEntity<PaymentResponse> authorize(@RequestBody PaymentRequest request) { PaymentResponse res = new PaymentResponse(); if ("gimme_500".equals(request.getReference())) { res.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); return new ResponseEntity<>(res, HttpStatus.INTERNAL_SERVER_ERROR); }//w w w.j ava2 s .c om if ("gimme_400".equals(request.getReference())) { res.setStatus(HttpStatus.BAD_REQUEST.value()); return new ResponseEntity<>(res, HttpStatus.BAD_REQUEST); } if ("gimme_422".equals(request.getReference())) { res.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value()); return new ResponseEntity<>(res, HttpStatus.UNPROCESSABLE_ENTITY); } if ("gimme_401".equals(request.getReference())) { res.setStatus(HttpStatus.UNAUTHORIZED.value()); return new ResponseEntity<>(res, HttpStatus.UNAUTHORIZED); } if ("gimme_403".equals(request.getReference())) { res.setStatus(HttpStatus.FORBIDDEN.value()); return new ResponseEntity<>(res, HttpStatus.FORBIDDEN); } if ("gimme_404".equals(request.getReference())) { res.setStatus(HttpStatus.NOT_FOUND.value()); return new ResponseEntity<>(res, HttpStatus.NOT_FOUND); } if ("gimme_200".equals(request.getReference())) { res.setStatus(HttpStatus.OK.value()); return new ResponseEntity<>(res, HttpStatus.OK); } res.setStatus(HttpStatus.NON_AUTHORITATIVE_INFORMATION.value()); return new ResponseEntity<>(res, HttpStatus.NON_AUTHORITATIVE_INFORMATION); }
From source file:de.sainth.recipe.backend.rest.controller.RecipeController.java
@Secured({ "ROLE_USER", "ROLE_ADMIN" }) @RequestMapping()/*from w ww .j a v a 2 s . c o m*/ HttpEntity<List<Recipe>> getAll() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication instanceof RecipeManagerAuthenticationToken) { RecipeManagerAuthenticationToken token = (RecipeManagerAuthenticationToken) authentication; if (ROLE_ADMIN.name().equals(token.getRole())) { return new ResponseEntity<>(repository.findAll(), HttpStatus.OK); } else { return new ResponseEntity<>(repository.findAllFor(token.getPrincipal()), HttpStatus.OK); } } return new ResponseEntity<>(HttpStatus.FORBIDDEN); }