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.wiiyaya.consumer.web.main.controller.ExceptionController.java
/** * ?//from ww w . ja v a 2 s .c om * @param request ? * @return ExceptionDto JSON */ @ExceptionHandler(value = SessionTimeoutException.class) @ResponseStatus(HttpStatus.UNAUTHORIZED) public ModelAndView sessionTimeoutException(HttpServletRequest request) { String errorMessage = messageSource.getMessage(MSG_ERROR_SESSION_TIMEOUT, null, LocaleContextHolder.getLocale()); return prepareExceptionInfo(request, HttpStatus.UNAUTHORIZED, MSG_ERROR_SESSION_TIMEOUT, errorMessage); }
From source file:comsat.sample.ui.method.SampleMethodSecurityApplicationTests.java
@Test public void testManagementProtected() throws Exception { ResponseEntity<String> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port + "/beans", String.class); assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); }
From source file:org.trustedanalytics.serviceexposer.rest.CredentialsController.java
@ApiOperation(value = "Returns list of all service instance credentials of given type for given organization.", notes = "Privilege level: Consumer of this endpoint must be a member of specified organization based on valid access token") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = ResponseEntity.class), @ApiResponse(code = 401, message = "User is Unauthorized"), @ApiResponse(code = 500, message = "Internal server error, see logs for details") }) @RequestMapping(value = GET_CREDENTIALS_LIST_FOR_ORG_URL, method = GET, produces = APPLICATION_JSON_VALUE) public ResponseEntity<?> getAllCredentialsInOrg(@PathVariable UUID org, @RequestParam(required = true) String service) { return ccOperations.getSpaces(org).map(s -> getCredentialsInJson(service, s.getGuid())) .flatMap(json -> Observable.from(getFlattenedCredentials(json))).toList() .map(instances -> new ResponseEntity<>(instances, HttpStatus.OK)).onErrorReturn(er -> { LOG.error("Exception occurred:", er); return new ResponseEntity<>(Collections.emptyList(), HttpStatus.UNAUTHORIZED); }).toBlocking().single();//from www. ja va2 s. c o m }
From source file:org.zaizi.SensefyResourceApplicationTests.java
@Test public void testRootPathAnauthorized() { RestTemplate template = new TestRestTemplate(); ResponseEntity<String> response = template.getForEntity(baseTestServerUrl(), String.class); Assert.assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); }
From source file:ca.hec.tenjin.tool.controller.PermissionsController.java
@ExceptionHandler(AuthzPermissionException.class) @ResponseStatus(value = HttpStatus.UNAUTHORIZED) public @ResponseBody String handleAuthzPermissionException(AuthzPermissionException ex) { return "User not authorized to change specified authz group"; }
From source file:org.venice.piazza.servicecontroller.controller.TaskManagedController.java
/** * Pulls the next job off of the Service Queue. * /*from ww w . j av a2s.com*/ * @param userName * The name of the user. Used for verification. * @param serviceId * The ID of the Service * @return The information for the next Job, if one is present. */ @RequestMapping(value = { "/service/{serviceId}/task" }, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<PiazzaResponse> getNextServiceJobFromQueue( @RequestParam(value = "userName", required = true) String userName, @PathVariable(value = "serviceId") String serviceId) { try { // Log the Request piazzaLogger.log(String.format("User %s Requesting to perform Work on Next Job for %s Service Queue.", userName, serviceId), Severity.INFORMATIONAL); // Check for Access boolean canAccess = mongoAccessor.canUserAccessServiceQueue(serviceId, userName); if (!canAccess) { throw new ResourceAccessException("Service does not allow this user to access."); } // Get the Job. This will mark the Job as being processed. ExecuteServiceJob serviceJob = serviceTaskManager.getNextJobFromQueue(serviceId); // Return if (serviceJob != null) { // Return Job Information return new ResponseEntity<>(new ServiceJobResponse(serviceJob, serviceJob.getJobId()), HttpStatus.OK); } else { // No Job Found. Return Null in the Response. return new ResponseEntity<>(new ServiceJobResponse(), HttpStatus.OK); } } catch (Exception exception) { String error = String.format("Error Getting next Service Job for Service %s by User %s: %s", serviceId, userName, exception.getMessage()); LOGGER.error(error, exception); piazzaLogger.log(error, Severity.ERROR, new AuditElement(userName, "errorGettingServiceJob", serviceId)); HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR; if (exception instanceof ResourceAccessException) { status = HttpStatus.UNAUTHORIZED; } else if (exception instanceof InvalidInputException) { status = HttpStatus.NOT_FOUND; } return new ResponseEntity<>(new ErrorResponse(error, "ServiceController"), status); } }
From source file:com.alexa.oms.service.AlexaOmsSpeechlet.java
@Override public void onSessionStarted(final SessionStartedRequest request, final Session session) throws SpeechletException { String jwtToken = session.getUser().getAccessToken(); LOG.info("onSessionStarted requestId={}, sessionId={}, access_token={}, userid={}", request.getRequestId(), session.getSessionId(), jwtToken, session.getUser().getUserId()); if (jwtToken == null) { //return getResponse(RESPONSE_NOT_AUTHORIZED); throw new HttpServerErrorException(HttpStatus.UNAUTHORIZED, RESPONSE_NOT_AUTHORIZED); }/*from w w w . j a v a2 s . co m*/ try { Claims claims = getClaimsFromJWT(jwtToken); String userId = claims.getUser_name(); LOG.info("User Id ==> " + userId); Customer customer = customerRepository.findByEmail(userId); LOG.info("CustomerId ==> " + customer.getCustomerId()); if (StringUtils.isBlank(userId) || customer == null) { throw new HttpServerErrorException(HttpStatus.UNAUTHORIZED, RESPONSE_NOT_AUTHORIZED); } session.setAttribute(CUSTOMER_ID, customer.getCustomerId()); } catch (Exception e) { LOG.error("erro during cusomer identification" + e); throw new HttpServerErrorException(HttpStatus.UNAUTHORIZED, RESPONSE_NOT_AUTHORIZED); } }
From source file:org.craftercms.profile.controllers.rest.ExceptionHandlers.java
@ExceptionHandler(BadCredentialsException.class) public ResponseEntity<Object> handleBadCredentialsException(BadCredentialsException e, WebRequest request) { return handleExceptionInternal(e, HttpStatus.UNAUTHORIZED, ErrorCode.BAD_CREDENTIALS, request); }
From source file:ch.heigvd.gamification.api.PointScalesEndpoint.java
@Override @RequestMapping(value = "/{pointScaleId}", method = RequestMethod.PUT) public ResponseEntity<Void> pointScalesPointScaleIdPut( @ApiParam(value = "pointScaleId", required = true) @RequestHeader(value = "X-Gamification-Token", required = true) String xGamificationToken, @ApiParam(value = "pointScaleId", required = true) @PathVariable("pointScaleId") Long pointScaleId, @ApiParam(value = "Modification of the pointScale") @RequestBody PointScaleDTO body) { AuthenKey apiKey = authenRepository.findByAppKey(xGamificationToken); if (apiKey == null) { return new ResponseEntity("apikey not exist", HttpStatus.UNAUTHORIZED); }/* ww w . j a va2 s . c om*/ PointScale pointScale = pointscaleRepository.findByIdAndApp(pointScaleId, apiKey.getApp()); if (pointScale == null) { return new ResponseEntity(HttpStatus.NOT_FOUND); } if (!body.getDescription().equals(" ")) { pointScale.setDescription(body.getDescription()); } else { body.setDescription(pointScale.getDescription()); } if (!body.getName().equals(" ")) { pointScale.setName(body.getName()); } else { body.setName(pointScale.getName()); } pointScale.setMinpoint(body.getNbrDePoints()); pointscaleRepository.save(pointScale); return new ResponseEntity(HttpStatus.OK); }
From source file:com.yang.oa.commons.exception.DefaultRestErrorResolver.java
protected final Map<String, String> createDefaultExceptionMappingDefinitions() { Map<String, String> m = new LinkedHashMap<String, String>(); // 400// w w w . j a v a 2s . c om applyDef(m, HttpMessageNotReadableException.class, HttpStatus.BAD_REQUEST); applyDef(m, MissingServletRequestParameterException.class, HttpStatus.BAD_REQUEST); applyDef(m, TypeMismatchException.class, HttpStatus.BAD_REQUEST); applyDef(m, "javax.validation.ValidationException", HttpStatus.BAD_REQUEST); applyDef(m, JlException.class, HttpStatus.BAD_REQUEST); //401 applyDef(m, org.apache.shiro.authz.UnauthorizedException.class, HttpStatus.UNAUTHORIZED); applyDef(m, org.apache.shiro.authz.UnauthenticatedException.class, HttpStatus.UNAUTHORIZED); // 404 applyDef(m, NoSuchRequestHandlingMethodException.class, HttpStatus.NOT_FOUND); applyDef(m, "org.hibernate.ObjectNotFoundException", HttpStatus.NOT_FOUND); // 405 applyDef(m, HttpRequestMethodNotSupportedException.class, HttpStatus.METHOD_NOT_ALLOWED); // 406 applyDef(m, HttpMediaTypeNotAcceptableException.class, HttpStatus.NOT_ACCEPTABLE); // 409 //can't use the class directly here as it may not be an available dependency: applyDef(m, "org.springframework.dao.DataIntegrityViolationException", HttpStatus.CONFLICT); // 415 applyDef(m, HttpMediaTypeNotSupportedException.class, HttpStatus.UNSUPPORTED_MEDIA_TYPE); return m; }