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.resthelper.RestHelperController.java

@ExceptionHandler(NotAllowIpException.class)
@ResponseStatus(HttpStatus.UNAUTHORIZED)
public void accessDeniedException(HttpServletRequest request, NotAllowIpException e) {
    String remoteAddr = request.getHeader("X-Real-IP");
    remoteAddr = (remoteAddr != null) ? remoteAddr : request.getRemoteAddr();

    LOGGER.warn("Access Deny Ip : {}", remoteAddr);
}

From source file:io.syndesis.runtime.ConnectorsITCase.java

@Test
public void connectorsListWithoutToken() {
    ResponseEntity<JsonNode> response = restTemplate().getForEntity("/api/v1/connectors", JsonNode.class);
    assertThat(response.getStatusCode()).as("component list status code").isEqualTo(HttpStatus.UNAUTHORIZED);
}

From source file:io.syndesis.runtime.ConnectorsITCase.java

@Test
public void connectorListWithExpiredToken() {
    get("/api/v1/connectors", JsonNode.class, tokenRule.expiredToken(), HttpStatus.UNAUTHORIZED);
}

From source file:io.syndesis.runtime.EventsITCase.java

@Test
public void sseEventsWithoutToken() throws Exception {

    // TODO: define an entity model for the response message:
    // {"timestamp":1490099424012,"status":401,"error":"Unauthorized","message":"Unauthorized","path":"/api/v1/event/reservations"}

    ResponseEntity<JsonNode> response = restTemplate().postForEntity("/api/v1/event/reservations", null,
            JsonNode.class);
    assertThat(response.getStatusCode()).as("reservations post status code").isEqualTo(HttpStatus.UNAUTHORIZED);

    // lets setup an event handler that we can inspect events on..
    EventHandler handler = recorder(mock(EventHandler.class), EventHandler.class);
    List<Recordings.Invocation> invocations = recordedInvocations(handler);
    CountDownLatch countDownLatch = resetRecorderLatch(handler, 1);

    // Using a random uuid should not work either.
    String uuid = UUID.randomUUID().toString();
    URI uri = resolveURI(EventBusToServerSentEvents.DEFAULT_PATH + "/" + uuid);
    try (EventSource eventSource = new EventSource.Builder(handler, uri).build()) {
        eventSource.start();/*from  w w w .  java 2 s. c om*/

        assertThat(countDownLatch.await(1000, TimeUnit.SECONDS)).isTrue();
        assertThat(invocations.get(0).getMethod().getName()).isEqualTo("onError");
        assertThat(invocations.get(0).getArgs()[0].toString()).isEqualTo(
                "com.launchdarkly.eventsource.UnsuccessfulResponseException: Unsuccessful response code received from stream: 404");
    }
}

From source file:io.syndesis.runtime.IntegrationsITCase.java

@Test
public void integrationsListWithoutToken() {
    get("/api/v1/integrations", JsonNode.class, null, HttpStatus.UNAUTHORIZED);
}

From source file:io.syndesis.runtime.IntegrationsITCase.java

@Test
public void integrationsListWithExpiredToken() {
    get("/api/v1/integrations", JsonNode.class, tokenRule.expiredToken(), HttpStatus.UNAUTHORIZED);
}

From source file:it.smartcommunitylab.aac.apikey.APIKeyController.java

@ExceptionHandler(SecurityException.class)
@ResponseStatus(code = HttpStatus.UNAUTHORIZED, reason = "Operation not permitted")
public void unauthorized() {
}

From source file:it.smartcommunitylab.aac.controller.AdminController.java

@ExceptionHandler(AccessDeniedException.class)
@ResponseStatus(HttpStatus.UNAUTHORIZED)
@ResponseBody//  www.  j  a  v a2  s  .co  m
public Response processAccessError(AccessDeniedException ex) {
    Response result = new Response();
    result.setResponseCode(RESPONSE.ERROR);
    result.setErrorMessage(ex.getMessage());
    return result;
}

From source file:it.smartcommunitylab.aac.controller.AppController.java

@ExceptionHandler(AccessDeniedException.class)
@ResponseStatus(HttpStatus.UNAUTHORIZED)
@ResponseBody/*from www  .  j av a2s .co  m*/
public Response processAccessError(AccessDeniedException ex) {
    return Response.error(ex.getMessage());
}

From source file:lti.oauth.OAuthFilter.java

@Override
protected void doFilterInternal(HttpServletRequest req, HttpServletResponse res, FilterChain fc)
        throws ServletException, IOException {

    LaunchRequest launchRequest = new LaunchRequest(req.getParameterMap());
    SortedMap<String, String> alphaSortedMap = launchRequest.toSortedMap();
    String signature = alphaSortedMap.remove(OAuthUtil.SIGNATURE_PARAM);

    String calculatedSignature = null;
    try {//from   ww  w . jav a 2 s. c  o  m
        calculatedSignature = new OAuthMessageSigner().sign(secret,
                OAuthUtil.mapToJava(alphaSortedMap.get(OAuthUtil.SIGNATURE_METHOD_PARAM)), "POST",
                req.getRequestURL().toString(), alphaSortedMap);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        res.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value());
        return;
    }

    if (!signature.equals(calculatedSignature)) {
        // try again with http
        String recalculatedSignature = null;

        if (StringUtils.startsWithIgnoreCase(req.getRequestURL().toString(), "https:")) {
            String url = StringUtils.replaceOnce(req.getRequestURL().toString(), "https:", "http:");
            try {
                recalculatedSignature = new OAuthMessageSigner().sign(secret,
                        OAuthUtil.mapToJava(alphaSortedMap.get(OAuthUtil.SIGNATURE_METHOD_PARAM)), "POST", url,
                        alphaSortedMap);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                res.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value());
                return;
            }
        }

        if (!signature.equals(recalculatedSignature)) {
            res.sendError(HttpStatus.UNAUTHORIZED.value());
            return;
        }
    }

    fc.doFilter(req, res);
}