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:edu.sjsu.cmpe275.project.controller.AuthController.java

/** Handle Option
 * @return         void/*  w w  w  .j  a v a  2 s  . c o m*/
 */
/*
    @RequestMapping(value = "/**",method = RequestMethod.OPTIONS)
    public String getOption(HttpServletResponse response,Model model)
    {
response.setHeader("Access-Control-Allow-Origin","*");
        
response.setHeader("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE");
        
return "";
    }
*/
@RequestMapping(value = "", method = RequestMethod.GET)
public ResponseEntity<?> createUser(@RequestParam(value = "name", required = true) String name,
        @RequestParam(value = "password", required = true) String password) {

    User user = userDao.getUser(name);
    if (user == null || password == null || !password.equals(user.getPassword())) {
        return new ResponseEntity<Object>(HttpStatus.UNAUTHORIZED);
    } else {
        return new ResponseEntity<Object>(user, HttpStatus.OK);
    }
}

From source file:de.thm.arsnova.controller.SecurityExceptionControllerAdvice.java

@ResponseStatus(HttpStatus.UNAUTHORIZED)
@ExceptionHandler(UnauthorizedException.class)
public void handleUnauthorizedException(final Exception e, final HttpServletRequest request) {
}

From source file:io.github.autsia.crowly.controllers.rest.AuthenticationController.java

@RequestMapping(value = "/register", method = RequestMethod.POST)
public ResponseEntity<String> register(@RequestBody CrowlyUser user, HttpServletResponse response) {
    try {//from ww  w.j a  va2 s .c o m
        authenticationManager.addUser(user);
        return new ResponseEntity<>(HttpStatus.OK);
    } catch (Exception e) {
        logger.warn("User creation failed: " + e.getMessage());
        return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
    }
}

From source file:com.jiwhiz.rest.RestErrorHandler.java

/**
 * Return 401 Unauthorized if user account locked.
 * /*from   w  ww .j  ava  2  s.c  o m*/
 * @param ex
 */
@ExceptionHandler(BadCredentialsException.class)
@ResponseStatus(HttpStatus.UNAUTHORIZED)
public void handleBadCredentialsException(BadCredentialsException ex) {
    LOGGER.debug("User account locked.");
}

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);
    }/*from   w ww . j a  v a 2 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:org.ng200.openolympus.controller.errors.AccessDeniedExceptionHandler.java

@ResponseStatus(value = HttpStatus.UNAUTHORIZED)
@ExceptionHandler({ CookieTheftException.class })
@RequestMapping(produces = "application/json;charset=UTF-8")
@ResponseBody/*from w w w.  j a v a 2  s  . c  o m*/
public String handleCookieTheftException(CookieTheftException exception) {
    return "{\"error\":\"auth.cookieTheftException\"}";
}

From source file:com.stampit.controller.LoginController.java

@RequestMapping(value = "/authenticateCustomer", method = RequestMethod.POST, consumes = "application/json")
public ResponseEntity<String> authenticateUser(@RequestBody String authInfo, HttpServletRequest request)
        throws IOException {
    ObjectMapper objectMapper = new ObjectMapper();
    AuthInfo authInfoObject = null;/*from   www  . j a  v  a2s  .  c  o  m*/
    authInfoObject = objectMapper.readValue(authInfo, AuthInfo.class);
    Customer customer = customerRepository.findByUsernameAndPassword(authInfoObject.getUsername(),
            authInfoObject.getPassword());
    ResponseEntity<String> response = null;
    if (customer == null) {
        response = new ResponseEntity<String>(null, new HttpHeaders(), HttpStatus.UNAUTHORIZED);
    } else {
        CustomerConfirmation confirmation = customerConfirmationRepository.findOne(customer.getIdCustomer());
        if (confirmation.getConfirmed()) {
            response = new ResponseEntity<String>("{\"id\":\"" + customer.getIdCustomer() + "\"}",
                    new HttpHeaders(), HttpStatus.OK);
        } else {
            response = new ResponseEntity<String>(null, new HttpHeaders(), HttpStatus.UNAUTHORIZED);
        }
    }
    return response;
}

From source file:com.appleframework.monitor.action.UserAction.java

@RequestMapping(value = "/login", method = RequestMethod.GET)
public String login(ModelMap map, HttpServletResponse response) {
    response.setStatus(HttpStatus.UNAUTHORIZED.value());
    return "app/login";
}

From source file:com.mycompany.bootcamelrestdsl.Application.java

@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {
    return new EmbeddedServletContainerCustomizer() {
        @Override//from  w  w w.  ja  v  a 2  s.co m
        public void customize(ConfigurableEmbeddedServletContainer container) {
            ErrorPage error401Page = new ErrorPage(HttpStatus.UNAUTHORIZED, "/401.html");
            ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/404.html");
            ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500.html");

            container.addErrorPages(error401Page, error404Page, error500Page);
        }
    };
}

From source file:curly.artifactory.web.HttpSecurityAntMatchersTests.java

@Test
public void testArtifactsIsNotSecured() throws Exception {
    mvc.perform(get("/artifacts")).andExpect(status().is(not(HttpStatus.UNAUTHORIZED.value())));
}