Example usage for org.springframework.http HttpStatus UNAUTHORIZED

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

Introduction

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

Prototype

HttpStatus UNAUTHORIZED

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

Click Source Link

Document

401 Unauthorized .

Usage

From source file:io.curly.commons.config.feign.ErrorDecoderFactory.java

public static Exception create(HttpStatus httpStatus, String reason) {
    if (httpStatus.equals(HttpStatus.NOT_FOUND)) {
        return new ResourceNotFoundException(reason);
    } else if (httpStatus.equals(HttpStatus.BAD_REQUEST)) {
        return new BadRequestException(reason);
    } else if (httpStatus.equals(HttpStatus.INTERNAL_SERVER_ERROR)) {
        return new InternalServerErrorException(reason);
    } else if (httpStatus.equals(HttpStatus.UNAUTHORIZED)) {
        return new UnauthorizedException(reason);
    } else if (httpStatus.equals(HttpStatus.UNSUPPORTED_MEDIA_TYPE)) {
        return new UnsupportedMediaTypeException(reason);
    }/*from   w w w . j  a  v a  2 s.c  o m*/
    return new BadRequestException(reason);

}

From source file:hr.softwarecity.osijek.controllers.SessionController.java

/**
 * Method to send error if session is not present
 * @return HTTP 401/*from  ww w  .ja  v  a  2 s. co  m*/
 */
@RequestMapping(value = "/badrequest")
public ResponseEntity returnUnauthorized() {
    return new ResponseEntity(HttpStatus.UNAUTHORIZED);
}

From source file:com.hrofirst.exception.handler.DefaultExceptionHandler.java

/**
 * ?? //from w  w  w . j  av  a2  s.  c o m
 * <p/>
 * ??????
 */
@ExceptionHandler({ UnauthorizedException.class })
@ResponseStatus(HttpStatus.UNAUTHORIZED)
public ModelAndView processUnauthenticatedException(NativeWebRequest request, UnauthorizedException e) {
    LogUtils.logError("???", e);
    ExceptionResponse exceptionResponse = ExceptionResponse.from(e);

    ModelAndView mv = new ModelAndView();
    mv.addObject("error", exceptionResponse);
    mv.setViewName("error/exception");

    return mv;
}

From source file:com.hp.autonomy.frontend.find.hod.web.HodGlobalExceptionHandler.java

@ExceptionHandler(HodAuthenticationFailedException.class)
@ResponseStatus(HttpStatus.UNAUTHORIZED)
@ResponseBody//from w  w  w. j  a  v a  2s.c  om
public ErrorResponse authenticationFailedHandler(final HodAuthenticationFailedException exception) {
    return new ErrorResponse("TOKEN HAS EXPIRED");
}

From source file:sparklr.common.AbstractProtectedResourceTests.java

@Test
public void testHomePageIsProtected() throws Exception {
    ResponseEntity<String> response = http.getForString("/");
    assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
    assertTrue("Wrong header: " + response.getHeaders(),
            response.getHeaders().getFirst("WWW-Authenticate").startsWith("Bearer realm="));
}

From source file:com.appglu.AppGluHttpUserUnauthorizedException.java

public AppGluHttpUserUnauthorizedException(Error error) {
    super(HttpStatus.UNAUTHORIZED.value(), error);
}

From source file:com.github.pires.example.ApplicationExceptionHandler.java

@ResponseStatus(HttpStatus.UNAUTHORIZED)
@ExceptionHandler({ AuthenticationException.class, UnknownAccountException.class,
        UnauthenticatedException.class, IncorrectCredentialsException.class, UnauthorizedException.class })
public void unauthorized() {
}

From source file:io.kahu.hawaii.util.exception.AuthorisationException.java

@Override
public HttpStatus getStatus() {
    return HttpStatus.UNAUTHORIZED; // 401
}

From source file:fi.hsl.parkandride.itest.ErrorHandlingITest.java

@Test
public void unauthorized_access() {
    givenWithContent().body(new Facility()).when().post(UrlSchema.FACILITIES).then()
            .statusCode(HttpStatus.UNAUTHORIZED.value());
}

From source file:authentication.DefaultAuthenticationFailureHandler.java

/** {@inheritDoc} */
@Override/*from   w  ww .  j  a  v a  2s .  c  o  m*/
public void onAuthenticationFailure(final HttpServletRequest request, final HttpServletResponse response,
        final AuthenticationException exception) throws IOException {
    response.setContentType(MediaType.APPLICATION_JSON_VALUE);
    response.setStatus(HttpStatus.UNAUTHORIZED.value());
    response.getOutputStream()
            .print(String.format(JSON, HttpStatus.UNAUTHORIZED.value(), exception.getMessage()));
}