org.springframework.http.HttpStatus.UNAUTHORIZED

Here are the examples of the java api org.springframework.http.HttpStatus.UNAUTHORIZED taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

570 Examples 7

@Override
public int getHttpErrorCode() {
    return HttpStatus.UNAUTHORIZED.value();
}

19 View Source File : JsonAuthenticationEntryPoint.java
License : Apache License 2.0
Project Creator : zlt2000

@Override
public Mono<Void> commence(ServerWebExchange exchange, AuthenticationException e) {
    return WebfluxResponseUtil.responseFailed(exchange, HttpStatus.UNAUTHORIZED.value(), e.getMessage());
}

19 View Source File : ResponseEntityPro.java
License : Apache License 2.0
Project Creator : yujunhao8831

public static <T> ResponseEnreplacedy<T> unauthorized(final T body) {
    return status(HttpStatus.UNAUTHORIZED, body);
}

19 View Source File : ResponseEntityPro.java
License : Apache License 2.0
Project Creator : yujunhao8831

public static <T> ResponseEnreplacedy<T> unauthorized(final T body, final String filterFields) {
    if (null == filterFields || WILDCARD_ALL.equals(filterFields)) {
        return notFound(body);
    }
    return status(HttpStatus.UNAUTHORIZED, body, filterFields);
}

19 View Source File : ResponseEntityPro.java
License : Apache License 2.0
Project Creator : yujunhao8831

public static ResponseEnreplacedy<String> unauthorized() {
    return status(HttpStatus.UNAUTHORIZED, HttpStatus.UNAUTHORIZED.getReasonPhrase());
}

19 View Source File : SampleSecureWebFluxCustomSecurityTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Test
public void userDefinedMappingsSecure() {
    this.webClient.get().uri("/").accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isEqualTo(HttpStatus.UNAUTHORIZED);
}

19 View Source File : SampleSecureWebFluxApplicationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Test
public void userDefinedMappingsSecureByDefault() {
    this.webClient.get().uri("/").accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isEqualTo(HttpStatus.UNAUTHORIZED);
}

19 View Source File : SampleActuatorUiApplicationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Test
public void testMetrics() {
    @SuppressWarnings("rawtypes")
    ResponseEnreplacedy<Map> enreplacedy = this.restTemplate.getForEnreplacedy("/actuator/metrics", Map.clreplaced);
    replacedertThat(enreplacedy.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}

19 View Source File : SampleActuatorUiApplicationPortTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Test
public void testMetrics() {
    @SuppressWarnings("rawtypes")
    ResponseEnreplacedy<Map> enreplacedy = new TestRestTemplate().getForEnreplacedy("http://localhost:" + this.managementPort + "/actuator/metrics", Map.clreplaced);
    replacedertThat(enreplacedy.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}

@Test
public void testSecureActuator() {
    ResponseEnreplacedy<String> enreplacedy = new TestRestTemplate().getForEnreplacedy("http://localhost:" + this.managementPort + "/management/actuator/env", String.clreplaced);
    replacedertThat(enreplacedy.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}

19 View Source File : CorsSampleActuatorApplicationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Test
public void endpointShouldReturnUnauthorized() {
    ResponseEnreplacedy<?> enreplacedy = this.testRestTemplate.getForEnreplacedy("/actuator/env", Map.clreplaced);
    replacedertThat(enreplacedy.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}

19 View Source File : ServletPathSampleActuatorApplicationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Test
public void testHomeIsSecure() {
    @SuppressWarnings("rawtypes")
    ResponseEnreplacedy<Map> enreplacedy = this.restTemplate.getForEnreplacedy("/spring/", Map.clreplaced);
    replacedertThat(enreplacedy.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
    @SuppressWarnings("unchecked")
    Map<String, Object> body = enreplacedy.getBody();
    replacedertThat(body.get("error")).isEqualTo("Unauthorized");
    replacedertThat(enreplacedy.getHeaders()).doesNotContainKey("Set-Cookie");
}

19 View Source File : ManagementPortSampleActuatorApplicationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Test
public void testMetrics() {
    // makes sure some requests have been made
    testHome();
    @SuppressWarnings("rawtypes")
    ResponseEnreplacedy<Map> enreplacedy = new TestRestTemplate().getForEnreplacedy("http://localhost:" + this.managementPort + "/actuator/metrics", Map.clreplaced);
    replacedertThat(enreplacedy.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}

@Test
public void testMetrics() {
    // makes sure some requests have been made
    testHome();
    @SuppressWarnings("rawtypes")
    ResponseEnreplacedy<Map> enreplacedy = new TestRestTemplate().getForEnreplacedy("http://localhost:" + this.managementPort + "/admin/metrics", Map.clreplaced);
    replacedertThat(enreplacedy.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}

19 View Source File : ManagementAddressActuatorApplicationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Test
public void testHome() {
    @SuppressWarnings("rawtypes")
    ResponseEnreplacedy<Map> enreplacedy = new TestRestTemplate().getForEnreplacedy("http://localhost:" + this.port, Map.clreplaced);
    replacedertThat(enreplacedy.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}

19 View Source File : AuthException.java
License : MIT License
Project Creator : wuyc

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

19 View Source File : ApiAuthFailedPastController.java
License : Apache License 2.0
Project Creator : wangguobo

@RequestMapping(Constant.AUTH_FAILED_PATH)
public Mono<ResponseModel> processIllegalRequest(ServerWebExchange exchange) {
    ErrorEnum error = (ErrorEnum) exchange.getAttributes().get(Constant.AUTH_ERROR_ATTR_NAME);
    // 根据error的枚举值,设置不同的http status Code,如400 Bad Request,401 Unauthorized
    // 这里只是演示,统一设置为401 Unauthorized
    exchange.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED);
    return Mono.just(new ResponseModel(error));
}

19 View Source File : HesperidesScenario.java
License : GNU General Public License v3.0
Project Creator : voyages-sncf-technologies

void replacedertUnauthorized() {
    replacedertEquals(HttpStatus.UNAUTHORIZED, testContext.getResponseStatusCode());
}

19 View Source File : StatusResultMatchers.java
License : MIT License
Project Creator : Vip-Augus

/**
 * replacedert the response status code is {@code HttpStatus.UNAUTHORIZED} (401).
 */
public ResultMatcher isUnauthorized() {
    return matcher(HttpStatus.UNAUTHORIZED);
}

19 View Source File : StatusAssertions.java
License : MIT License
Project Creator : Vip-Augus

/**
 * replacedert the response status code is {@code HttpStatus.UNAUTHORIZED} (401).
 */
public WebTestClient.ResponseSpec isUnauthorized() {
    return replacedertStatusAndReturn(HttpStatus.UNAUTHORIZED);
}

19 View Source File : UnauthorizedAuthenticationEntryPoint.java
License : MIT License
Project Creator : TransEmpiric

@Override
public Mono<Void> commence(final ServerWebExchange exchange, final AuthenticationException e) {
    return Mono.fromRunnable(() -> exchange.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED));
}

19 View Source File : Unauthorized.java
License : GNU General Public License v3.0
Project Creator : saltedge

@Override
public HttpStatus getErrorStatus() {
    return HttpStatus.UNAUTHORIZED;
}

19 View Source File : ExceptionHandler.java
License : GNU General Public License v3.0
Project Creator : ran-jit

@ResponseStatus(HttpStatus.BAD_REQUEST)
@org.springframework.web.bind.annotation.ExceptionHandler(value = UserAuthenticationException.clreplaced)
public Error handleBaseException() {
    return error(HttpStatus.UNAUTHORIZED, null);
}

19 View Source File : CloudErrorUtil.java
License : Apache License 2.0
Project Creator : PaaS-TA

/**
 * check 401 error due to invalid credentials
 * @param t
 * @return true if 401. False otherwise
 */
public static boolean isUnauthorisedException(Throwable t) {
    return isHttpException(t, HttpStatus.UNAUTHORIZED);
}

19 View Source File : JsonAuthenticationEntryPoint.java
License : Apache License 2.0
Project Creator : jbuider1993

@Override
public Mono<Void> commence(ServerWebExchange exchange, AuthenticationException e) {
    return ResponseUtil.responseFailed(exchange, HttpStatus.UNAUTHORIZED.value(), e.getMessage());
}

19 View Source File : VirtualAssistantAuthRestClientTest.java
License : MIT License
Project Creator : InnovateUKGitHub

@Test
public void testObtainVirtualreplacedistantAuthDetailsFailed() {
    when(restTemplate.exchange(TEST_URL, HttpMethod.GET, new HttpEnreplacedy<>(virtualreplacedistantAuthRestClient.authHeader()), String.clreplaced)).thenReturn(new ResponseEnreplacedy<>(HttpStatus.UNAUTHORIZED));
    VirtualreplacedistantModel virtualreplacedistantModel = virtualreplacedistantAuthRestClient.obtainVirtualreplacedistantAuthDetails();
    replacedertThat(virtualreplacedistantModel.isServerAvailable(), equalTo(false));
    replacedertThat(virtualreplacedistantModel.getBotId(), equalTo(NO_REMOTE_SERVER_MSG));
    replacedertThat(virtualreplacedistantModel.getClientToken(), equalTo(NO_REMOTE_SERVER_MSG));
    replacedertThat(virtualreplacedistantModel.getErrorMessage(), equalTo(String.valueOf(HttpStatus.UNAUTHORIZED.value())));
}

19 View Source File : IdentitiesEndpoint_Updating_IT.java
License : MIT License
Project Creator : InnovateUKGitHub

// 401
@Test
public void onUpdatePreplacedwordWithInvalidAuthentication() throws IOException {
    withNoAuthentication().and().put(getBaseUrl() + "/idenreplacedies/" + uuidForUpdatingPreplacedword + "/preplacedword").then().replacedertThat().statusCode(is(equalTo(HttpStatus.UNAUTHORIZED.value()))).body(isEmptyOrNullString());
    withInvalidAuthentication().and().put(getBaseUrl() + "/idenreplacedies/" + uuidForUpdatingPreplacedword + "/preplacedword").then().replacedertThat().statusCode(is(equalTo(HttpStatus.UNAUTHORIZED.value()))).body(isEmptyOrNullString());
}

19 View Source File : IdentitiesEndpoint_Updating_IT.java
License : MIT License
Project Creator : InnovateUKGitHub

// 401
@Test
public void onUpdateEmailWithInvalidAuthentication() throws IOException {
    withNoAuthentication().and().put(getBaseUrl() + "/idenreplacedies/" + uuidForUpdatingEmail + "/email").then().replacedertThat().statusCode(is(equalTo(HttpStatus.UNAUTHORIZED.value()))).body(isEmptyOrNullString());
    withInvalidAuthentication().and().put(getBaseUrl() + "/idenreplacedies/" + uuidForUpdatingEmail + "/email").then().replacedertThat().statusCode(is(equalTo(HttpStatus.UNAUTHORIZED.value()))).body(isEmptyOrNullString());
}

19 View Source File : IdentitiesEndpoint_Finding_IT.java
License : MIT License
Project Creator : InnovateUKGitHub

// 401
@Test
public void onFindWithInvalidAuthentication() throws IOException {
    withNoAuthentication().and().get(getBaseUrl() + "/idenreplacedies/" + uuidForFinding).then().replacedertThat().statusCode(is(equalTo(HttpStatus.UNAUTHORIZED.value()))).body(isEmptyOrNullString());
    withInvalidAuthentication().and().get(getBaseUrl() + "/idenreplacedies/" + uuidForFinding).then().replacedertThat().statusCode(is(equalTo(HttpStatus.UNAUTHORIZED.value()))).body(isEmptyOrNullString());
}

19 View Source File : IdentitiesEndpoint_Deleting_IT.java
License : MIT License
Project Creator : InnovateUKGitHub

// 401
@Test
public void onDeletingWithInvalidAuthentication() {
    withNoAuthentication().delete(getBaseUrl() + "/idenreplacedies/" + nonExistentIdenreplacedyUuid).then().replacedertThat().statusCode(is(equalTo(HttpStatus.UNAUTHORIZED.value()))).body(isEmptyOrNullString());
    withInvalidAuthentication().delete(getBaseUrl() + "/idenreplacedies/" + nonExistentIdenreplacedyUuid).then().replacedertThat().statusCode(is(equalTo(HttpStatus.UNAUTHORIZED.value()))).body(isEmptyOrNullString());
}

19 View Source File : IdentitiesEndpoint_Creating_IT.java
License : MIT License
Project Creator : InnovateUKGitHub

// 401
@Test
public void onCreationWithInvalidAuthentication() throws IOException {
    withNoAuthentication().and().contentType(ContentType.JSON).body(convertToJson(new NewIdenreplacedy(emailForCreate, preplacedwordForCreate))).post(getBaseUrl() + "/idenreplacedies").then().replacedertThat().statusCode(is(equalTo(HttpStatus.UNAUTHORIZED.value()))).body(isEmptyOrNullString());
    withInvalidAuthentication().and().contentType(ContentType.JSON).body(convertToJson(new NewIdenreplacedy(emailForCreate, preplacedwordForCreate))).post(getBaseUrl() + "/idenreplacedies").then().replacedertThat().statusCode(is(equalTo(HttpStatus.UNAUTHORIZED.value()))).body(isEmptyOrNullString());
}

19 View Source File : SecurityWebFilter.java
License : GNU General Public License v3.0
Project Creator : hantsy

@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
    if (!exchange.getRequest().getQueryParams().containsKey("user")) {
        exchange.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED);
    }
    return chain.filter(exchange);
}

19 View Source File : FlowableUiApplicationSecurityTest.java
License : Apache License 2.0
Project Creator : flowable

@Test
public void nonAuthenticatedShouldNotBeAbleToAccessApi() {
    String processDefinitionsUrl = "http://localhost:" + serverPort + "/flowable-ui/process-api/repository/process-definitions";
    ResponseEnreplacedy<String> result = restTemplate.getForEnreplacedy(processDefinitionsUrl, String.clreplaced);
    replacedertThat(result.getStatusCode()).as("GET API Editor models").isEqualTo(HttpStatus.UNAUTHORIZED);
}

19 View Source File : FlowableUiApplicationSecurityTest.java
License : Apache License 2.0
Project Creator : flowable

@Test
public void nonAuthenticatedUserShouldBeForbiddenToAccessAppDefinitions() {
    String appDefinitionsUrl = "http://localhost:" + serverPort + "/flowable-ui/app/rest/runtime/app-definitions";
    ResponseEnreplacedy<Object> result = restTemplate.getForEnreplacedy(appDefinitionsUrl, Object.clreplaced);
    replacedertThat(result.getStatusCode()).as("GET app definitions").isEqualTo(HttpStatus.UNAUTHORIZED);
}

19 View Source File : BasicAuthSecurityConfiguration.java
License : Eclipse Public License 1.0
Project Creator : eclipse

@Override
protected void configure(final HttpSecurity httpSec) throws Exception {
    httpSec.csrf().disable().authorizeRequests().antMatchers("/").permitAll().anyRequest().authenticated().and().httpBasic().and().exceptionHandling().authenticationEntryPoint((request, response, e) -> {
        response.addHeader("WWW-Authenticate", "Basic realm=\"Device Simulator\"");
        response.setStatus(HttpStatus.UNAUTHORIZED.value());
        response.getWriter().write(HttpStatus.UNAUTHORIZED.getReasonPhrase());
    });
}

19 View Source File : ApplicationSecurityConfig.java
License : Apache License 2.0
Project Creator : didclab

private Mono<Void> authenticationFailedHandler(ServerWebExchange serverWebExchange, AuthenticationException e) {
    return Mono.fromRunnable(() -> {
        serverWebExchange.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED);
    });
}

19 View Source File : DirectPDSAPIMonitoringStateScenario6IntTest.java
License : MIT License
Project Creator : Daimler

@Test
public void anonymous_cannot_fetch_execution_state() {
    /* execute +test */
    expectHttpFailure(() -> asPDSUser(ANONYMOUS).getMonitoringStatus(), HttpStatus.UNAUTHORIZED);
}

19 View Source File : DirectPDSAPIConfigurationScenario6IntTest.java
License : MIT License
Project Creator : Daimler

@Test
public void anonymous_cannot_fetch_server_configuration() {
    /* @formatter:off */
    /* execute + test */
    expectHttpFailure(() -> asPDSUser(ANONYMOUS).getServerConfiguration(), HttpStatus.UNAUTHORIZED);
/* @formatter:on */
}

19 View Source File : UserAdministrationScenario2IntTest.java
License : MIT License
Project Creator : Daimler

@Test
public void anynmouse_can_NOT_grant_user_admin_rights() {
    replacedertUser(ANONYMOUS).canNotGrantSuperAdminRightsTo(USER_2, HttpStatus.UNAUTHORIZED);
}

19 View Source File : UserAdministrationScenario2IntTest.java
License : MIT License
Project Creator : Daimler

@Test
public void anynmouse_can_NOT_revoke_user_admin_rights() {
    /* prepare */
    TestUser adminUser = USER_2;
    as(SUPER_ADMIN).grantSuperAdminRightsTo(adminUser);
    replacedertUser(adminUser).isSuperAdmin();
    /* execute + test*/
    replacedertUser(ANONYMOUS).canNotRevokeSuperAdminRightsFrom(adminUser, HttpStatus.UNAUTHORIZED);
}

19 View Source File : ProjectMockConfigurationScenario2IntTest.java
License : MIT License
Project Creator : Daimler

@Test
public void anonymous_cannot_set_project_mockconfiguration() {
    replacedertUser(ANONYMOUS).canNotSetMockConfiguration(PROJECT_1, mockDataEmpty, HttpStatus.UNAUTHORIZED);
}

19 View Source File : ProjectAdministrationScenario2IntTest.java
License : MIT License
Project Creator : Daimler

@Test
public void anynmouse_can_NOT_list_a_project() {
    replacedertUser(ANONYMOUS).canNotListProject(PROJECT_1, HttpStatus.UNAUTHORIZED);
}

19 View Source File : ProjectAdministrationScenario2IntTest.java
License : MIT License
Project Creator : Daimler

@Test
public void anynmouse_can_NOT_replacedign_user_to_project() {
    replacedertUser(ANONYMOUS).canNotreplacedignUserToProject(USER_1, PROJECT_1, HttpStatus.UNAUTHORIZED);
}

19 View Source File : ProjectAdministrationScenario1IntTest.java
License : MIT License
Project Creator : Daimler

@Test
public void anynomous_is_not_able_to_create_a_project() {
    replacedertUser(ANONYMOUS).cannotCreateProject(Scenario1.PROJECT_1, Scenario1.OWNER_1.getUserId(), HttpStatus.UNAUTHORIZED);
}

19 View Source File : GetServerInfoScenario1IntTest.java
License : MIT License
Project Creator : Daimler

/* +-----------------------------------------------------------------------+ */
/* +............................ Get server version .......................+ */
/* +-----------------------------------------------------------------------+ */
@Test
public void get_server_version_anonymous_not_possible_results_in_unauthorized() {
    /* execute */
    expectHttpFailure(() -> as(ANONYMOUS).getServerVersion(), HttpStatus.UNAUTHORIZED);
}

19 View Source File : SecurityTest.java
License : MIT License
Project Creator : congcoi123

@Test
public void metricsEndpoint_withoutBackendAdminCredentials_returnsUnauthorized() {
    when().get("/metrics").then().statusCode(HttpStatus.UNAUTHORIZED.value());
}

19 View Source File : SecurityTest.java
License : MIT License
Project Creator : congcoi123

@Test
public void metricsEndpoint_withInvalidBackendAdminCredentials_returnsUnauthorized() {
    String username = "test_user_2";
    String preplacedword = "InvalidPreplacedword";
    given().header(X_AUTH_USERNAME, username).header(X_AUTH_PreplacedWORD, preplacedword).when().get("/metrics").then().statusCode(HttpStatus.UNAUTHORIZED.value());
}

19 View Source File : AjaxAwareAuthenticationRedirectStrategyTest.java
License : MIT License
Project Creator : cloudogu

@Test
public void testRedirectWithAjaxRequest() throws IOException {
    when(request.getHeader(AJAX_HEADER)).thenReturn(AJAX_HEADER_VALUE);
    redirectStrategy.redirect(request, response, REDIRECT_TARGET);
    verify(response).setStatus(HttpStatus.UNAUTHORIZED.value());
    verify(response).setHeader(HttpHeaders.LOCATION, REDIRECT_TARGET);
}

19 View Source File : AuthorizationChecker.java
License : Apache License 2.0
Project Creator : cloudfoundry-incubator

private void failWithUnauthorizedStatus(String message) {
    failWithStatus(HttpStatus.UNAUTHORIZED, message);
}

19 View Source File : AuthorizationException.java
License : GNU Affero General Public License v3.0
Project Creator : ClimbAssist

@Override
public HttpStatus getHttpStatus() {
    return HttpStatus.UNAUTHORIZED;
}

See More Examples