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:com.cloudbees.jenkins.plugins.demo.actuator.SampleActuatorApplicationTests.java
@Test public void testMetricsIsSecure() throws Exception { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port + "/metrics", Map.class); assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port + "/metrics/", Map.class); assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port + "/metrics/foo", Map.class); assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port + "/metrics.json", Map.class); assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); }
From source file:com.devnexus.ting.web.controller.CalendarController.java
@RequestMapping(value = { "/{eventKey}/usercalendar" }, method = RequestMethod.GET) @ResponseBody/*w w w . j ava 2 s.com*/ public ResponseEntity<List<UserCalendar>> calendar(@PathVariable("eventKey") String eventKey) throws JsonProcessingException { HttpHeaders headers = new HttpHeaders(); headers.add("Content-Type", "application/json; charset=utf-8"); if (SecurityContextHolder.getContext().getAuthentication().getPrincipal() instanceof String) { headers.add("WWW-Authenticate", "Google realm=\"http://www.devnexus.org\""); return new ResponseEntity<List<UserCalendar>>(new ArrayList<UserCalendar>(), headers, HttpStatus.UNAUTHORIZED); } User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); List<UserCalendar> calendar = calendarService.getUserCalendar(user, eventKey); return new ResponseEntity<>(calendar, headers, HttpStatus.OK); }
From source file:org.fineract.module.stellar.TestCreateTrustLine.java
@Test public void createTrustLineIncorrectApiKey() { final TrustLineConfiguration trustLine = new TrustLineConfiguration(BigDecimal.valueOf(100)); String issuer = "blub"; given().header(CONTENT_TYPE_HEADER).header(API_KEY_HEADER_LABEL, "wrong_key") .header(TENANT_ID_HEADER_LABEL, firstTenantId).pathParameter("assetCode", ASSET_CODE) .pathParameter("issuer", issuer).body(trustLine) .put("/modules/stellarbridge/trustlines/{assetCode}/{issuer}/").then().assertThat() .statusCode(HttpStatus.UNAUTHORIZED.value()); }
From source file:io.github.proxyprint.kitchen.controllers.notifications.NotificationsController.java
@Transactional @ApiOperation(value = "Returns success/insuccess.", notes = "This method allows a consumer to subscribe the SSE.") @RequestMapping(value = "/consumer/subscribe", produces = "text/event-stream") public ResponseEntity<SseEmitter> subscribe(WebRequest request) { String username = request.getParameter("username"); String password = request.getParameter("password"); Consumer consumer = this.consumers.findByUsername(username); if (consumer == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } else if (consumer.getPassword().equals(password)) { return new ResponseEntity<>(this.notificationManager.subscribe(username), HttpStatus.OK); } else {//from w w w .j a va 2s . co m return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); } }
From source file:uk.org.funcube.fcdw.server.processor.DataProcessor.java
@Transactional(readOnly = false) @RequestMapping(value = "/{siteId}/", method = RequestMethod.POST) public ResponseEntity<String> uploadData(@PathVariable String siteId, @RequestParam(value = "digest") String digest, @RequestBody String body) { // get the user from the repository List<UserEntity> users = userDao.findBySiteId(siteId); if (users.size() != 0) { String hexString = StringUtils.substringBetween(body, "=", "&"); hexString = hexString.replace("+", " "); String authKey = userAuthKeys.get(siteId); final UserEntity user = users.get(0); try {/*from www . j ava 2 s . com*/ if (authKey == null) { if (user != null) { authKey = user.getAuthKey(); userAuthKeys.put(siteId, authKey); } else { LOG.error(USER_WITH_SITE_ID + siteId + NOT_FOUND); return new ResponseEntity<String>("UNAUTHORIZED", HttpStatus.UNAUTHORIZED); } } final String calculatedDigest = calculateDigest(hexString, authKey, null); final String calculatedDigestUTF8 = calculateDigest(hexString, authKey, new Integer(8)); final String calculatedDigestUTF16 = calculateDigest(hexString, authKey, new Integer(16)); if (null != digest && (digest.equals(calculatedDigest) || digest.equals(calculatedDigestUTF8)) || digest.equals(calculatedDigestUTF16)) { hexString = StringUtils.deleteWhitespace(hexString); final int frameId = Integer.parseInt(hexString.substring(0, 2), 16); final int frameType = frameId & 63; final int satelliteId = (frameId & (128 + 64)) >> 6; final int sensorId = frameId % 2; final String binaryString = convertHexBytePairToBinary( hexString.substring(2, hexString.length())); final Date now = clock.currentDate(); final RealTime realTime = new RealTime(satelliteId, frameType, sensorId, now, binaryString); final long sequenceNumber = realTime.getSequenceNumber(); if (sequenceNumber != -1) { final List<HexFrameEntity> frames = hexFrameDao .findBySatelliteIdAndSequenceNumberAndFrameType(satelliteId, sequenceNumber, frameType); HexFrameEntity hexFrame = null; if (frames != null && frames.size() == 0) { hexFrame = new HexFrameEntity((long) satelliteId, (long) frameType, sequenceNumber, hexString, now, true); hexFrame.getUsers().add(user); hexFrameDao.save(hexFrame); RealTimeEntity realTimeEntity = new RealTimeEntity(realTime); realTimeDao.save(realTimeEntity); } else { hexFrame = frames.get(0); hexFrame.getUsers().add(user); hexFrameDao.save(hexFrame); } } return new ResponseEntity<String>("OK", HttpStatus.OK); } else { LOG.error(USER_WITH_SITE_ID + siteId + HAD_INCORRECT_DIGEST + ", received: " + digest + ", calculated: " + calculatedDigest); return new ResponseEntity<String>("UNAUTHORIZED", HttpStatus.UNAUTHORIZED); } } catch (final Exception e) { LOG.error(e.getMessage()); return new ResponseEntity<String>(e.getMessage(), HttpStatus.BAD_REQUEST); } } else { LOG.error("Site id: " + siteId + " not found in database"); return new ResponseEntity<String>("UNAUTHORIZED", HttpStatus.UNAUTHORIZED); } }
From source file:sample.jetty.SampleJetty8ApplicationTests.java
@Test public void testHomeBasicAuthWrongCredentials403() throws Exception { ResponseEntity<String> entity = new TestRestTemplate().exchange( "http://localhost:" + this.port + "/static.html", HttpMethod.GET, new HttpEntity<String>(createHeaders("admin", "wrong-password")), String.class); assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); }
From source file:com.salmon.security.xacml.demo.springmvc.rest.HTTPPopulatorsTest.java
@Test public void badUserPrevented() { HttpHeaders headers = this.getHeaders("wrongusername" + ":" + "wrongpwd"); RestTemplate template = new RestTemplate(); HttpEntity<String> requestEntity = new HttpEntity<String>(DriverFixtures.standardDriverJSON(), headers); try {//from w w w . ja va 2s.c om ResponseEntity<Driver> entity = template.postForEntity( "http://localhost:8085/xacml/populators/dvla/driveradd", requestEntity, Driver.class); fail("Request Passed incorrectly with status " + entity.getStatusCode()); } catch (HttpClientErrorException ex) { assertEquals(HttpStatus.UNAUTHORIZED, ex.getStatusCode()); } }
From source file:org.zaizi.AuthServerApplicationTests.java
@Test public void userEndpointProtected() { ResponseEntity<String> response = template.getForEntity("http://localhost:" + port + contextPath + "/", String.class); assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); String auth = response.getHeaders().getFirst("WWW-Authenticate"); assertTrue("Wrong header: " + auth, auth.startsWith("Bearer realm=\"")); }
From source file:net.prasenjit.auth.config.CustomAjaxAwareHandler.java
/** {@inheritDoc} */ @Override// w w w. j a v a 2s. c o m public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { if (checkIfAjaxRequest(request)) { response.setStatus(HttpStatus.UNAUTHORIZED.value()); } else { delegatedFailureHandler.onAuthenticationFailure(request, response, exception); } }
From source file:app.api.swagger.SwaggerConfig.java
private List<ResponseMessage> defaultHttpResponses() { final List<ResponseMessage> results = new ArrayList<ResponseMessage>(); results.add(response(HttpStatus.FORBIDDEN, null)); results.add(response(HttpStatus.UNAUTHORIZED, null)); results.add(response(HttpStatus.BAD_REQUEST, null)); results.add(response(HttpStatus.UNPROCESSABLE_ENTITY, ERROR_MODEL)); return results; }