List of usage examples for org.springframework.http HttpStatus UNAUTHORIZED
HttpStatus UNAUTHORIZED
To view the source code for org.springframework.http HttpStatus UNAUTHORIZED.
Click Source Link
From source file:io.getlime.security.powerauth.rest.api.spring.exception.PowerAuthExceptionHandler.java
/** * Handle PowerAuthAuthenticationException exceptions. * @param ex Exception instance.//w ww. j a v a2s . com * @return Error response. */ @ExceptionHandler(value = PowerAuthAuthenticationException.class) @ResponseStatus(value = HttpStatus.UNAUTHORIZED) public @ResponseBody PowerAuthApiResponse<ErrorModel> handleUnauthorizedException(Exception ex) { PowerAuthAuthenticationException paex = (PowerAuthAuthenticationException) ex; Logger.getLogger(PowerAuthExceptionHandler.class.getName()).log(Level.SEVERE, paex.getMessage(), paex); ErrorModel error = new ErrorModel(paex.getDefaultCode(), paex.getMessage()); return new PowerAuthApiResponse<>(PowerAuthApiResponse.Status.ERROR, error); }
From source file:org.shaf.server.controller.ExceptionHandlingController.java
@ExceptionHandler({ AuthenticationException.class }) @ResponseStatus(value = HttpStatus.UNAUTHORIZED) public ModelAndView handleAuthenticationException(HttpServletRequest request, Exception exception) { LOG.debug("CALL: error handler"); exception.printStackTrace();/*from w w w .j a v a 2 s .co m*/ return ViewError.getErrorView().header("url", request.getRequestURL().toString()).addException(exception) .warn("Check the system log for more details."); }
From source file:com.crazyacking.learn.spring.actuator.ManagementAddressActuatorApplicationTests.java
@Test public void testHome() { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port, Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); }
From source file:br.com.bancooriginal.notificacao.servlet.SampleServletApplicationTests.java
@Test public void testHomeIsSecure() throws Exception { ResponseEntity<String> entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port, String.class); assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); }
From source file:sample.RestTests.java
@Test(expected = HttpClientErrorException.class) public void unauthenticatedUserSentToLogInPage() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); ResponseEntity<String> entity = getForUser(this.baseUrl + "/", headers, String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); }
From source file:com.crazyacking.learn.spring.actuator.ManagementPathSampleActuatorApplicationTests.java
@Test public void testHomeIsSecure() { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = this.restTemplate.getForEntity("/", Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); assertThat(body.get("error")).isEqualTo("Unauthorized"); assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); }
From source file:org.cloudfoundry.identity.batch.integration.BatchEndpointIntegrationTests.java
/** * tests a unauthorized flow of the <code>/batch</code> endpoint *//*www .j av a2s . co m*/ @Test public void testUnauthorized() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", String.format("Basic %s", new String(Base64.encode("batch:bogus".getBytes())))); ResponseEntity<String> response = serverRunning.getForString("/batch/", headers); assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); String map = response.getBody(); // System.err.println(map); assertTrue(map.contains("{\"error\"")); }
From source file:demo.EmbeddedIntegrationTests.java
@Test public void testSecure() throws IOException { ResponseEntity<String> body = new TestRestTemplate().getForEntity("http://127.0.0.1:" + port + "/", String.class); assertEquals("Wrong body: " + body, HttpStatus.UNAUTHORIZED, body.getStatusCode()); }
From source file:ch.heigvd.gamification.api.PointScalesEndpoint.java
@Override @RequestMapping(method = RequestMethod.GET) public ResponseEntity<List<PointScaleDTO>> pointScalesGet( @ApiParam(value = "token that identifies the app sending the request", required = true) @RequestHeader(value = "X-Gamification-Token", required = true) String xGamificationToken) { AuthenKey apiKey = authenRepository.findByAppKey(xGamificationToken); if (apiKey == null) { return new ResponseEntity("apikey not exist", HttpStatus.UNAUTHORIZED); }//from w ww .j av a2s.c o m return new ResponseEntity<>( StreamSupport.stream(pointscaleRepository.findAllByApp(apiKey.getApp()).spliterator(), true) .map(p -> toDTO(p)).collect(toList()), HttpStatus.OK); }