Example usage for org.apache.commons.httpclient HttpStatus SC_UNAUTHORIZED

List of usage examples for org.apache.commons.httpclient HttpStatus SC_UNAUTHORIZED

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpStatus SC_UNAUTHORIZED.

Prototype

int SC_UNAUTHORIZED

To view the source code for org.apache.commons.httpclient HttpStatus SC_UNAUTHORIZED.

Click Source Link

Document

<tt>401 Unauthorized</tt> (HTTP/1.0 - RFC 1945)

Usage

From source file:net.bryansaunders.jee6divelog.service.rest.SecurityApiIT.java

/**
 * Test Identify./*from   ww  w. java 2  s  .co  m*/
 */
@Test
public void ifNotLoggedInThenIdentifyUnauthorized() {
    given().headers(RestApi.PUBLIC_KEY_HEADER, "sdfsdfs", RestApi.SIGNATURE_HEADER, "seese").expect()
            .statusCode(HttpStatus.SC_UNAUTHORIZED).when().get(RestApiTest.URL_ROOT + "/security/identify");
}

From source file:com.thoughtworks.twist.mingle.core.MingleClient.java

public boolean validate() {
    HttpMethod method = getMethod(loginUrl());
    try {/* w w  w .j  ava2  s  . com*/
        int httpStatus = executeMethod(method);
        switch (httpStatus) {
        case HttpStatus.SC_OK:
            return true;
        case HttpStatus.SC_UNAUTHORIZED:
            throw new MingleAuthenticationException();
        }
    } finally {
        if (method != null)
            method.releaseConnection();
    }
    return false;
}

From source file:com.thoughtworks.go.server.service.ScheduleServiceSecurityTest.java

@Test
public void shouldReturnAppropriateHttpResultIfUserDoesNotHaveOperatePermission() throws Exception {
    configHelper.addSecurityWithAdminConfig();
    configHelper.setOperatePermissionForGroup("defaultGroup", "jez");
    Pipeline pipeline = fixture.createPipelineWithFirstStagePassedAndSecondStageRunning();
    Username anonymous = new Username(new CaseInsensitiveString("anonymous"));
    HttpLocalizedOperationResult operationResult = new HttpLocalizedOperationResult();
    Stage resultStage = scheduleService.cancelAndTriggerRelevantStages(
            pipeline.getStages().byName(fixture.ftStage).getId(), anonymous, operationResult);

    assertThat(resultStage, is(nullValue()));
    assertThat(operationResult.isSuccessful(), is(false));
    assertThat(operationResult.httpCode(), is(HttpStatus.SC_UNAUTHORIZED));
}

From source file:edu.internet2.middleware.shibboleth.idp.StatusServlet.java

/** {@inheritDoc} */
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (!isAuthenticated(request)) {
        response.sendError(HttpStatus.SC_UNAUTHORIZED);
        return;/* ww w .java2  s.c  o m*/
    }

    response.setContentType("text/plain");
    PrintWriter output = response.getWriter();

    printOperatingEnvironmentInformation(output);
    output.println();
    printIdPInformation(output);
    output.println();
    printRelyingPartyConfigurationsInformation(output, request.getParameter("relyingParty"));

    output.flush();
}

From source file:net.bryansaunders.jee6divelog.service.rest.SecurityApiIT.java

/**
 * Test Logout./*from w w w. j a v a  2  s.  c  om*/
 */
@Test
public void ifNotLoggedInThenLogoutUnauthorized() {
    given().headers(RestApi.PUBLIC_KEY_HEADER, "sdfsdfs", RestApi.SIGNATURE_HEADER, "seese").expect()
            .statusCode(HttpStatus.SC_UNAUTHORIZED).when().post(RestApiTest.URL_ROOT + "/security/logout");
}

From source file:jetbrains.buildServer.symbols.DownloadSymbolsControllerTest.java

@Test
public void request_pdb_unauthorized() throws Exception {
    myFixture.getLoginConfiguration().setGuestLoginAllowed(false);
    myRequest.setRequestURI("mock", getRegisterPdbUrl("secur32.pdb", "8EF4E863187C45E78F4632152CC82FEB"));
    doGet();/*from   w  w  w  .  j  a v  a 2s  . c  om*/
    assertEquals(HttpStatus.SC_UNAUTHORIZED, myResponse.getStatus());
}

From source file:com.kagilum.intellij.icescrum.IceScrumRepository.java

private void checkServerStatus(int code) throws IOException {
    switch (code) {
    case HttpStatus.SC_SERVICE_UNAVAILABLE:
        throw new IOException("Web services aren't activated on your project...");
    case HttpStatus.SC_UNAUTHORIZED:
        throw new IOException("Wrong login/pass...");
    case HttpStatus.SC_FORBIDDEN:
        throw new IOException("You haven't access to this project...");
    case HttpStatus.SC_NOT_FOUND:
        throw new IOException("No project or iceScrum server found...");
    default://  w w w.j  a  v  a  2  s  .  c o m
        throw new IOException("Server error (" + HttpStatus.getStatusText(code) + ")");
    }
}

From source file:com.cerema.cloud2.lib.common.operations.RemoteOperationResult.java

private RemoteOperationResult(boolean success, int httpCode) {
    mSuccess = success;//from w w w  .j  a  va2s . co m
    mHttpCode = httpCode;

    if (success) {
        mCode = ResultCode.OK;

    } else if (httpCode > 0) {
        switch (httpCode) {
        case HttpStatus.SC_UNAUTHORIZED:
            mCode = ResultCode.UNAUTHORIZED;
            break;
        case HttpStatus.SC_NOT_FOUND:
            mCode = ResultCode.FILE_NOT_FOUND;
            break;
        case HttpStatus.SC_INTERNAL_SERVER_ERROR:
            mCode = ResultCode.INSTANCE_NOT_CONFIGURED;
            break;
        case HttpStatus.SC_CONFLICT:
            mCode = ResultCode.CONFLICT;
            break;
        case HttpStatus.SC_INSUFFICIENT_STORAGE:
            mCode = ResultCode.QUOTA_EXCEEDED;
            break;
        case HttpStatus.SC_FORBIDDEN:
            mCode = ResultCode.FORBIDDEN;
            break;
        default:
            mCode = ResultCode.UNHANDLED_HTTP_CODE;
            Log_OC.d(TAG, "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " + httpCode);
        }
    }
}

From source file:jetbrains.buildServer.symbols.DownloadSymbolsControllerTest.java

@Test
public void request_pdb_no_permissions_granted() throws Exception {
    myRequest.setRequestURI("mock", getRegisterPdbUrl("secur32.pdb", "8EF4E863187C45E78F4632152CC82FEB"));
    doGet();//from   w  ww . j a  v  a2 s.  c o  m
    assertEquals(HttpStatus.SC_UNAUTHORIZED, myResponse.getStatus());
}

From source file:com.zimbra.qa.unittest.TestCollectConfigServletsAccess.java

/**
 * Verify that delegated admin canNOT access servlet at /service/collectconfig/
 * @throws Exception//from www . ja  va  2 s  .c  o  m
 */
@Test
public void testConfigDelegatedAdmin() throws Exception {
    ZAuthToken at = TestUtil.getAdminSoapTransport(TEST_ADMIN_NAME, PASSWORD).getAuthToken();
    URI servletURI = new URI(getConfigServletUrl());
    HttpState initialState = HttpClientUtil.newHttpState(at, servletURI.getHost(), true);
    HttpClient restClient = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
    restClient.setState(initialState);
    restClient.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
    GetMethod get = new GetMethod(servletURI.toString());
    int statusCode = HttpClientUtil.executeMethod(restClient, get);
    assertEquals("This request should NOT succeed. Getting status code " + statusCode,
            HttpStatus.SC_UNAUTHORIZED, statusCode);
}