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:com.hp.autonomy.frontend.find.core.beanconfiguration.AppConfiguration.java

@SuppressWarnings("ReturnOfInnerClass")
@Bean/*  w  w w  . j  a v  a  2s  . c  o  m*/
public EmbeddedServletContainerCustomizer containerCustomizer() {

    return new EmbeddedServletContainerCustomizer() {
        @Override
        public void customize(final ConfigurableEmbeddedServletContainer container) {

            final ErrorPage error401Page = new ErrorPage(HttpStatus.UNAUTHORIZED,
                    DispatcherServletConfiguration.AUTHENTICATION_ERROR_PATH);
            final ErrorPage error403Page = new ErrorPage(HttpStatus.FORBIDDEN,
                    DispatcherServletConfiguration.AUTHENTICATION_ERROR_PATH);
            final ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND,
                    DispatcherServletConfiguration.NOT_FOUND_ERROR_PATH);
            final ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR,
                    DispatcherServletConfiguration.SERVER_ERROR_PATH);

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

From source file:com.crazyacking.learn.spring.actuator.SampleActuatorApplicationTests.java

@Test
public void testMetricsIsSecure() {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = this.restTemplate.getForEntity("/metrics", Map.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
    entity = this.restTemplate.getForEntity("/metrics/", Map.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
    entity = this.restTemplate.getForEntity("/metrics/foo", Map.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
    entity = this.restTemplate.getForEntity("/metrics.json", Map.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}

From source file:ch.heigvd.gamification.api.AuthEndpoint.java

@Override
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity authenticateApplicationAndGetToken(
        @ApiParam(value = "The info required to authenticate an application", required = true) @RequestBody Credentials body) {

    Application app1 = applicationsRepository.findByName(body.getApplicationName());

    if (app1 != null) {

        String password = body.getPassword();

        try {/* www  .  ja  va  2 s . c  om*/
            password = Application.doHash(password, app1.getSel());

        } catch (UnsupportedEncodingException | NoSuchAlgorithmException ex) {
            Logger.getLogger(AuthEndpoint.class.getName()).log(Level.SEVERE, null, ex);
        }

        Application app = applicationsRepository.findByPassword(password);

        if (app != null) {
            Token token = new Token();
            AuthenKey appKey = authenrepository.findByApp(app);
            token.setApplicationName(appKey.getAppKey());
            return ResponseEntity.ok(token);
        } else {

            return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();

        }

    }

    return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();

}

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

@RequestMapping(value = SSO_PAGE, method = RequestMethod.GET, params = HOD_SSO_ERROR_PARAM)
public ModelAndView ssoError(final HttpServletRequest request, final HttpServletResponse response)
        throws HodErrorException {
    response.setStatus(HttpStatus.UNAUTHORIZED.value());
    return hodErrorController.authenticationErrorPage(request, response);
}

From source file:com.tikal.tallerWeb.rest.util.CustomRestErrorHandler.java

@Override
public void handleError(ClientHttpResponse response) throws IOException {
    HttpStatus statusCode = getHttpStatusCode(response);
    if (statusCode == HttpStatus.UNAUTHORIZED) {
        loginController.start(this);
    } else {/*from   w w w. java 2 s. com*/
        super.handleError(response);
    }
}

From source file:spring.AbstractAuthorizationCodeProviderTests.java

@Test
@OAuth2ContextConfiguration(resource = MyTrustedClient.class, initialize = false)
public void testUnauthenticatedAuthorizationRespondsUnauthorized() throws Exception {

    AccessTokenRequest request = context.getAccessTokenRequest();
    request.setCurrentUri("http://anywhere");
    request.add(OAuth2Utils.USER_OAUTH_APPROVAL, "true");

    try {//from   w  w w. j  a  v  a2 s  .  c  om
        String code = getAccessTokenProvider().obtainAuthorizationCode(context.getResource(), request);
        assertNotNull(code);
        fail("Expected UserRedirectRequiredException");
    } catch (HttpClientErrorException e) {
        assertEquals(HttpStatus.UNAUTHORIZED, e.getStatusCode());
    }

}

From source file:com.alcatel.hello.actuator.ui.SampleActuatorUIApplicationTests.java

@Test
public void testMetrics() throws Exception {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate()
            .getForEntity("http://localhost:" + this.port + "/metrics", Map.class);
    assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
}

From source file:com.cloudbees.jenkins.plugins.demo.actuator.ManagementPortSampleActuatorApplicationTests.java

@Test
public void testMetrics() throws Exception {
    testHome(); // makes sure some requests have been made
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate()
            .getForEntity("http://localhost:" + this.managementPort + "/metrics", Map.class);
    assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
}

From source file:io.curly.advisor.web.HttpSecurityAntMatchersTests.java

@Test
public void testReviewsByArtifactIsNotSecure() throws Exception {
    mvc.perform(get("/reviews/artifact/{artifact}", ObjectId.get().toHexString()))
            .andExpect(status().is(not(HttpStatus.UNAUTHORIZED.value())));
}

From source file:comsat.sample.actuator.SampleActuatorApplicationTests.java

private void testHomeIsSecure(final String path) throws Exception {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate()
            .getForEntity("http://localhost:" + this.port + "/" + emptyIfNull(path), Map.class);
    assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
    @SuppressWarnings("unchecked")
    Map<String, Object> body = entity.getBody();
    assertEquals("Wrong body: " + body, "Unauthorized", body.get("error"));
    assertFalse("Wrong headers: " + entity.getHeaders(), entity.getHeaders().containsKey("Set-Cookie"));
}