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.cloudbees.jenkins.plugins.demo.actuator.ManagementAddressActuatorApplicationTests.java

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

From source file:ar.com.aleatoria.ue.rest.SimpleClientHttpResponse.java

@Override
public HttpStatus getStatusCode() throws IOException {
    try {/*  w  ww  .  ja  va 2  s. co  m*/
        return HttpStatus.valueOf(getRawStatusCode());
    } catch (IOException ex) {
        /* 
         * If credentials are incorrect or not provided for Basic Auth, then 
         * Android throws this exception when an HTTP 401 is received. Checking 
         * for this response and returning the proper status.
         */
        if (ex.getLocalizedMessage().equals(AUTHENTICATION_ERROR)) {
            return HttpStatus.UNAUTHORIZED;
        } else {
            throw ex;
        }
    }
}

From source file:org.cloudfoundry.identity.uaa.integration.VarzEndpointIntegrationTests.java

/**
 * tests a unauthorized flow of the <code>/varz</code> endpoint
 *///from  ww  w  .  j a v  a2s .  c o m
@Test
public void testUnauthorized() throws Exception {

    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", String.format("Basic %s", new String(Base64.encode("varz:bogus".getBytes()))));
    ResponseEntity<String> response = serverRunning.getForString("/varz", headers);
    assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());

    String map = response.getBody();
    // System.err.println(map);
    assertTrue(map.contains("{\"error\""));

}

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

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

From source file:com.abdin.noorsingles.web.AdminController.java

@RequestMapping(value = "/isAuthenticated", method = RequestMethod.GET)
public ResponseEntity isAuthenticated(HttpSession session) {

    if (adminService.isAuthenticated(session)) {
        return new ResponseEntity(HttpStatus.OK);
    } else {//w w  w.j a  va2s.  c o  m
        return new ResponseEntity(HttpStatus.UNAUTHORIZED);
    }
}

From source file:com.nicusa.controller.DrugControllerTest.java

@Test
public void testCreateDrugAsAnonymousUser() {
    DrugResource drugResource = new DrugResource();
    when(securityController.getAuthenticatedUserProfileId())
            .thenReturn(UserProfileResource.ANONYMOUS_USER_PROFILE_ID);
    ResponseEntity<?> responseEntity = drugController.create(drugResource);
    assertThat(responseEntity.getStatusCode(), is(HttpStatus.UNAUTHORIZED));
}

From source file:comsat.sample.actuator.ui.SampleActuatorUiApplicationPortTests.java

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

From source file:org.slc.sli.dashboard.security.mock.Mocker.java

public static RestTemplate mockRest() {
    RestTemplate rest = mock(RestTemplate.class);

    ResponseEntity<String> validationOK = new ResponseEntity<String>("boolean=true", HttpStatus.OK);
    ResponseEntity<String> validationFail = new ResponseEntity<String>("boolean=true", HttpStatus.UNAUTHORIZED);
    ResponseEntity<String> attributesOK = new ResponseEntity<String>(PAYLOAD, HttpStatus.OK);

    when(rest.getForEntity(MOCK_URL + "/identity/isTokenValid?tokenid=" + VALID_TOKEN, String.class,
            Collections.<String, Object>emptyMap())).thenReturn(validationOK);
    when(rest.getForEntity(MOCK_URL + "/identity/isTokenValid?tokenid=" + INVALID_TOKEN, String.class,
            Collections.<String, Object>emptyMap())).thenReturn(validationFail);
    when(rest.getForEntity(MOCK_URL + "/identity/attributes?subjectid=" + VALID_TOKEN, String.class,
            Collections.<String, Object>emptyMap())).thenReturn(attributesOK);

    return rest;//from   w  w w.j  av  a2  s.  c om

}

From source file:org.createnet.raptor.auth.service.controller.TokenController.java

@PreAuthorize("isAuthenticated()")
@RequestMapping("/token/{uuid}")
public ResponseEntity<?> getTokens(@AuthenticationPrincipal User user, @PathVariable String uuid) {
    // TODO add ACL checks
    if (!user.getUuid().equals(uuid) && !user.isSuperAdmin()) {
        return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
                .body(new JsonErrorResponse(HttpStatus.UNAUTHORIZED.value(), "Not authorized"));
    }//from   w ww  . ja  v a2s  . co m

    return ResponseEntity.ok(tokenService.list(uuid));
}

From source file:com.springsource.greenhouse.AbstractGreenhouseActivity.java

protected void processException(Exception e) {
    if (e != null) {
        if (e instanceof ResourceAccessException) {
            displayNetworkError();/*  ww w . j  a  va2s. c  o m*/
        } else if (e instanceof HttpClientErrorException) {
            HttpClientErrorException httpError = (HttpClientErrorException) e;
            if (httpError.getStatusCode() == HttpStatus.UNAUTHORIZED) {
                displayAuthorizationError();
            }
        }
    }
}