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:org.xwiki.test.rest.AttachmentsResourceTest.java

@Test
public void testPUTAttachmentNoRights() throws Exception {
    String attachmentName = String.format("%s.txt", UUID.randomUUID());
    String attachmentURI = buildURIForThisPage(AttachmentResource.class, attachmentName);

    String content = "ATTACHMENT CONTENT";

    GetMethod getMethod = executeGet(attachmentURI);
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_NOT_FOUND, getMethod.getStatusCode());

    PutMethod putMethod = executePut(attachmentURI, content, MediaType.TEXT_PLAIN);
    Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_UNAUTHORIZED, putMethod.getStatusCode());
}

From source file:org.xwiki.test.rest.AttachmentsResourceTest.java

@Test
public void testDELETEAttachmentNoRights() throws Exception {
    String attachmentName = String.format("%d.txt", System.currentTimeMillis());
    String attachmentURI = buildURIForThisPage(AttachmentResource.class, attachmentName);

    String content = "ATTACHMENT CONTENT";

    PutMethod putMethod = executePut(attachmentURI, content, MediaType.TEXT_PLAIN,
            TestUtils.ADMIN_CREDENTIALS.getUserName(), TestUtils.ADMIN_CREDENTIALS.getPassword());
    Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_CREATED, putMethod.getStatusCode());

    DeleteMethod deleteMethod = executeDelete(attachmentURI);
    Assert.assertEquals(getHttpMethodInfo(deleteMethod), HttpStatus.SC_UNAUTHORIZED,
            deleteMethod.getStatusCode());

    GetMethod getMethod = executeGet(attachmentURI);
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
}

From source file:org.xwiki.test.rest.framework.AbstractHttpTest.java

protected void checkLinks(LinkCollection linkCollection) throws Exception {
    if (linkCollection.getLinks() != null) {
        for (Link link : linkCollection.getLinks()) {
            GetMethod getMethod = executeGet(link.getHref());
            if (getMethod.getStatusCode() != HttpStatus.SC_UNAUTHORIZED) {
                Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
            }/*from w  w  w  . j a  va 2  s. c o  m*/
        }
    }
}

From source file:org.xwiki.test.rest.ObjectsResourceTest.java

@Test
public void testPOSTObjectNotAuthorized() throws Exception {
    final String TAG_VALUE = "TAG";

    Property property = new Property();
    property.setName("tags");
    property.setValue(TAG_VALUE);//  www  .  jav  a 2s.c  om
    Object object = objectFactory.createObject();
    object.setClassName("XWiki.TagClass");
    object.getProperties().add(property);

    PostMethod postMethod = executePostXml(
            buildURI(ObjectsResource.class, getWiki(), MAIN_SPACE, "WebHome").toString(), object);
    Assert.assertEquals(getHttpMethodInfo(postMethod), HttpStatus.SC_UNAUTHORIZED, postMethod.getStatusCode());
}

From source file:org.xwiki.test.rest.ObjectsResourceTest.java

@Test
public void testPUTObjectUnauthorized() throws Exception {
    final String TAG_VALUE = UUID.randomUUID().toString();

    Object objectToBePut = createObjectIfDoesNotExists("XWiki.TagClass", MAIN_SPACE, "WebHome");

    GetMethod getMethod = executeGet(buildURI(ObjectResource.class, getWiki(), MAIN_SPACE, "WebHome",
            objectToBePut.getClassName(), objectToBePut.getNumber()).toString());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());

    Object object = (Object) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    String originalTagValue = getProperty(object, "tags").getValue();
    getProperty(object, "tags").setValue(TAG_VALUE);

    PutMethod putMethod = executePutXml(buildURI(ObjectResource.class, getWiki(), MAIN_SPACE, "WebHome",
            objectToBePut.getClassName(), objectToBePut.getNumber()).toString(), object);
    Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_UNAUTHORIZED, putMethod.getStatusCode());

    getMethod = executeGet(buildURI(ObjectResource.class, getWiki(), MAIN_SPACE, "WebHome",
            objectToBePut.getClassName(), objectToBePut.getNumber()).toString());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());

    object = (Object) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());

    Assert.assertEquals(originalTagValue, getProperty(object, "tags").getValue());
}

From source file:org.xwiki.test.rest.ObjectsResourceTest.java

@Test
public void testDELETEObjectUnAuthorized() throws Exception {
    Object objectToBeDeleted = createObjectIfDoesNotExists("XWiki.TagClass", MAIN_SPACE, "WebHome");

    DeleteMethod deleteMethod = executeDelete(buildURI(ObjectResource.class, getWiki(), MAIN_SPACE, "WebHome",
            objectToBeDeleted.getClassName(), objectToBeDeleted.getNumber()).toString());
    Assert.assertEquals(getHttpMethodInfo(deleteMethod), HttpStatus.SC_UNAUTHORIZED,
            deleteMethod.getStatusCode());

    GetMethod getMethod = executeGet(buildURI(ObjectResource.class, getWiki(), MAIN_SPACE, "WebHome",
            objectToBeDeleted.getClassName(), objectToBeDeleted.getNumber()).toString());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
}

From source file:org.xwiki.test.rest.PageResourceTest.java

@Test
public void testPUTPageUnauthorized() throws Exception {
    Page page = getFirstPage();/*  w  w w  .  j  a va 2 s  . c o m*/
    page.setContent("New content");

    Link link = getFirstLinkByRelation(page, Relations.SELF);
    Assert.assertNotNull(link);

    PutMethod putMethod = executePutXml(link.getHref(), page);
    Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_UNAUTHORIZED, putMethod.getStatusCode());
}

From source file:org.xwiki.test.rest.PageResourceTest.java

@Test
public void testDELETEPageNoRights() throws Exception {
    final String pageName = String.format("Test-%d", random.nextLong());

    createPageIfDoesntExist(TestConstants.TEST_SPACE_NAME, pageName, "Test page");

    DeleteMethod deleteMethod = executeDelete(
            buildURI(PageResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, pageName).toString());
    Assert.assertEquals(getHttpMethodInfo(deleteMethod), HttpStatus.SC_UNAUTHORIZED,
            deleteMethod.getStatusCode());

    GetMethod getMethod = executeGet(/*from www  .  j a va 2  s .  co  m*/
            buildURI(PageResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, pageName).toString());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
}

From source file:slash.navigation.rest.HttpRequest.java

public boolean isUnAuthorized() throws IOException {
    return getResult() == HttpStatus.SC_UNAUTHORIZED;
}