Example usage for org.apache.commons.httpclient NameValuePair NameValuePair

List of usage examples for org.apache.commons.httpclient NameValuePair NameValuePair

Introduction

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

Prototype

public NameValuePair(String name, String value) 

Source Link

Document

Constructor.

Usage

From source file:org.apache.oodt.security.sso.opensso.SSOProxy.java

public IdentityDetails readIdentity(String username, String token) throws IOException, SingleSignOnException {
    HttpClient httpClient = new HttpClient();
    PostMethod post = new PostMethod(IDENT_READ_ENDPOINT);
    LOG.log(Level.INFO, "Obtaining identity: username: [" + username + "]: token: [" + token + "]: REST url: ["
            + IDENT_READ_ENDPOINT + "]");
    NameValuePair[] data = { new NameValuePair("name", username), new NameValuePair("admin", token) };

    post.setRequestBody(data);/* ww  w  .j a v  a 2 s  .c o m*/

    httpClient.executeMethod(post);
    if (post.getStatusCode() != HttpStatus.SC_OK) {
        throw new SingleSignOnException(post.getStatusLine().toString());
    }

    return parseIdentityDetails(post.getResponseBodyAsString().trim());

}

From source file:org.apache.oodt.security.sso.opensso.SSOProxy.java

public UserDetails getUserAttributes(String token) throws IOException, SingleSignOnException {
    HttpClient httpClient = new HttpClient();
    PostMethod post = new PostMethod(IDENT_ATTR_ENDPOINT);
    LOG.log(Level.INFO,// ww w .ja va  2 s .  c o m
            "Obtaining user attributes: token: [" + token + "]: REST url: [" + IDENT_ATTR_ENDPOINT + "]");
    NameValuePair[] data = { new NameValuePair("subjectid", token) };

    post.setRequestBody(data);

    httpClient.executeMethod(post);
    if (post.getStatusCode() != HttpStatus.SC_OK) {
        throw new SingleSignOnException(post.getStatusLine().toString());
    }

    return parseUserDetails(post.getResponseBodyAsString().trim());

}

From source file:org.apache.oodt.security.sso.opensso.SSOProxy.java

public void logout(String token) {
    HttpClient httpClient = new HttpClient();
    PostMethod post = new PostMethod(LOG_ENDPOINT);
    LOG.log(Level.INFO, "Logging out: token: [" + token + "]: REST url: [" + LOG_ENDPOINT + "]");
    NameValuePair[] data = { new NameValuePair("subjectid", token) };
    post.setRequestBody(data);//  ww w . ja  v  a2  s  .c  om

    try {
        httpClient.executeMethod(post);
        if (post.getStatusCode() != HttpStatus.SC_OK) {
            throw new HttpException(post.getStatusLine().toString());
        }
    } catch (HttpException e) {
        // TODO Auto-generated catch block
        LOG.log(Level.SEVERE, e.getMessage());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        LOG.log(Level.SEVERE, e.getMessage());
    } finally {
        post.releaseConnection();
    }
}

From source file:org.apache.sling.launchpad.webapp.integrationtest.accessManager.AbstractAccessManagerTest.java

protected String createTestUser() throws IOException {
    String postUrl = HTTP_BASE_URL + "/system/userManager/user.create.html";

    String testUserId = "testUser" + (counter++);
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair(":name", testUserId));
    postParams.add(new NameValuePair("pwd", "testPwd"));
    postParams.add(new NameValuePair("pwdConfirm", "testPwd"));
    assertPostStatus(postUrl, HttpServletResponse.SC_OK, postParams, null);

    return testUserId;
}

From source file:org.apache.sling.launchpad.webapp.integrationtest.accessManager.AbstractAccessManagerTest.java

protected String createTestGroup() throws IOException {
    String postUrl = HTTP_BASE_URL + "/system/userManager/group.create.html";

    String testGroupId = "testGroup" + (counter++);
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair(":name", testGroupId));

    //success would be a redirect to the welcome page of the webapp
    Credentials creds = new UsernamePasswordCredentials("admin", "admin");
    assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);

    return testGroupId;
}

From source file:org.apache.sling.launchpad.webapp.integrationtest.accessManager.AccessPrivilegesInfoTest.java

@After
public void cleanup() throws Exception {
    H.tearDown();/*from   www  .  j  a  va 2s. c o m*/

    Credentials creds = new UsernamePasswordCredentials("admin", "admin");

    if (testFolderUrl != null) {
        //remove the test user if it exists.
        String postUrl = testFolderUrl;
        List<NameValuePair> postParams = new ArrayList<NameValuePair>();
        postParams.add(new NameValuePair(":operation", "delete"));
        H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
    }
    if (testGroupId != null) {
        //remove the test user if it exists.
        String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".delete.html";
        List<NameValuePair> postParams = new ArrayList<NameValuePair>();
        H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
    }
    if (testUserId != null) {
        //remove the test user if it exists.
        String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".delete.html";
        List<NameValuePair> postParams = new ArrayList<NameValuePair>();
        H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
    }

    for (String script : toDelete) {
        H.getTestClient().delete(script);
    }
}

From source file:org.apache.sling.launchpad.webapp.integrationtest.accessManager.AccessPrivilegesInfoTest.java

@Test
public void testDeniedWriteForUser() throws IOException, JSONException {
    testUserId = H.createTestUser();//from   ww  w  . j a  v a  2  s.co m
    testFolderUrl = H.createTestFolder();

    //assign some privileges
    String postUrl = testFolderUrl + ".modifyAce.html";

    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair("principalId", testUserId));
    postParams.add(new NameValuePair("privilege@jcr:read", "granted"));
    postParams.add(new NameValuePair("privilege@jcr:readAccessControl", "granted"));
    postParams.add(new NameValuePair("privilege@jcr:write", "denied"));

    Credentials adminCreds = new UsernamePasswordCredentials("admin", "admin");
    H.assertAuthenticatedPostStatus(adminCreds, postUrl, HttpServletResponse.SC_OK, postParams, null);

    String getUrl = testFolderUrl + ".privileges-info.json";

    //fetch the JSON for the test page to verify the settings.
    Credentials testUserCreds = new UsernamePasswordCredentials(testUserId, "testPwd");

    String json = H.getAuthenticatedContent(testUserCreds, getUrl, HttpTest.CONTENT_TYPE_JSON, null,
            HttpServletResponse.SC_OK);
    assertNotNull(json);
    JSONObject jsonObj = new JSONObject(json);

    assertEquals(false, jsonObj.getBoolean("canAddChildren"));
    assertEquals(false, jsonObj.getBoolean("canDeleteChildren"));
    assertEquals(false, jsonObj.getBoolean("canDelete"));
    assertEquals(false, jsonObj.getBoolean("canModifyProperties"));
    assertEquals(true, jsonObj.getBoolean("canReadAccessControl"));
    assertEquals(false, jsonObj.getBoolean("canModifyAccessControl"));
}

From source file:org.apache.sling.launchpad.webapp.integrationtest.accessManager.AccessPrivilegesInfoTest.java

@Test
public void testGrantedWriteForUser() throws IOException, JSONException {
    testUserId = H.createTestUser();/* w  ww.  j  ava 2s  .c o  m*/
    testFolderUrl = H.createTestFolder();

    //assign some privileges
    String postUrl = testFolderUrl + ".modifyAce.html";

    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair("principalId", testUserId));
    postParams.add(new NameValuePair("privilege@jcr:read", "granted"));
    postParams.add(new NameValuePair("privilege@jcr:write", "granted"));
    postParams.add(new NameValuePair("privilege@jcr:readAccessControl", "granted"));
    postParams.add(new NameValuePair("privilege@jcr:modifyAccessControl", "granted"));

    Credentials adminCreds = new UsernamePasswordCredentials("admin", "admin");
    H.assertAuthenticatedPostStatus(adminCreds, postUrl, HttpServletResponse.SC_OK, postParams, null);

    String getUrl = testFolderUrl + ".privileges-info.json";

    //fetch the JSON for the test page to verify the settings.
    Credentials testUserCreds = new UsernamePasswordCredentials(testUserId, "testPwd");

    String json = H.getAuthenticatedContent(testUserCreds, getUrl, HttpTest.CONTENT_TYPE_JSON, null,
            HttpServletResponse.SC_OK);
    assertNotNull(json);
    JSONObject jsonObj = new JSONObject(json);

    assertEquals(true, jsonObj.getBoolean("canAddChildren"));
    assertEquals(true, jsonObj.getBoolean("canDeleteChildren"));
    //the parent node must also have jcr:removeChildren granted for 'canDelete' to be true
    assertEquals(false, jsonObj.getBoolean("canDelete"));
    assertEquals(true, jsonObj.getBoolean("canModifyProperties"));
    assertEquals(true, jsonObj.getBoolean("canReadAccessControl"));
    assertEquals(true, jsonObj.getBoolean("canModifyAccessControl"));

    //add a child node to verify the 'canDelete' use case
    String childFolderUrl = H.getTestClient().createNode(
            testFolderUrl + "/testFolder" + random.nextInt() + SlingPostConstants.DEFAULT_CREATE_SUFFIX, null);
    String childPostUrl = childFolderUrl + ".modifyAce.html";

    postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair("principalId", testUserId));
    postParams.add(new NameValuePair("privilege@jcr:read", "granted"));
    postParams.add(new NameValuePair("privilege@jcr:removeNode", "granted"));
    H.assertAuthenticatedPostStatus(adminCreds, childPostUrl, HttpServletResponse.SC_OK, postParams, null);

    String childGetUrl = childFolderUrl + ".privileges-info.json";
    String childJson = H.getAuthenticatedContent(testUserCreds, childGetUrl, HttpTest.CONTENT_TYPE_JSON, null,
            HttpServletResponse.SC_OK);
    assertNotNull(childJson);
    JSONObject childJsonObj = new JSONObject(childJson);
    assertEquals(true, childJsonObj.getBoolean("canDelete"));
}

From source file:org.apache.sling.launchpad.webapp.integrationtest.accessManager.AccessPrivilegesInfoTest.java

@Test
public void testDeniedWriteForGroup() throws IOException, JSONException {
    testGroupId = H.createTestGroup();//from w  w w  . j a va2 s .  co  m
    testUserId = H.createTestUser();
    testFolderUrl = H.createTestFolder();

    Credentials adminCreds = new UsernamePasswordCredentials("admin", "admin");

    //add testUserId to testGroup
    String groupPostUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".update.html";
    List<NameValuePair> groupPostParams = new ArrayList<NameValuePair>();
    groupPostParams.add(new NameValuePair(":member", testUserId));
    H.assertAuthenticatedPostStatus(adminCreds, groupPostUrl, HttpServletResponse.SC_OK, groupPostParams, null);

    //assign some privileges
    String postUrl = testFolderUrl + ".modifyAce.html";

    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair("principalId", testGroupId));
    postParams.add(new NameValuePair("privilege@jcr:read", "granted"));
    postParams.add(new NameValuePair("privilege@jcr:readAccessControl", "granted"));
    postParams.add(new NameValuePair("privilege@jcr:write", "denied"));

    H.assertAuthenticatedPostStatus(adminCreds, postUrl, HttpServletResponse.SC_OK, postParams, null);

    String getUrl = testFolderUrl + ".privileges-info.json";

    //fetch the JSON for the test page to verify the settings.
    Credentials testUserCreds = new UsernamePasswordCredentials(testUserId, "testPwd");

    String json = H.getAuthenticatedContent(testUserCreds, getUrl, HttpTest.CONTENT_TYPE_JSON, null,
            HttpServletResponse.SC_OK);
    assertNotNull(json);
    JSONObject jsonObj = new JSONObject(json);

    assertEquals(false, jsonObj.getBoolean("canAddChildren"));
    assertEquals(false, jsonObj.getBoolean("canDeleteChildren"));
    assertEquals(false, jsonObj.getBoolean("canDelete"));
    assertEquals(false, jsonObj.getBoolean("canModifyProperties"));
    assertEquals(true, jsonObj.getBoolean("canReadAccessControl"));
    assertEquals(false, jsonObj.getBoolean("canModifyAccessControl"));
}

From source file:org.apache.sling.launchpad.webapp.integrationtest.accessManager.AccessPrivilegesInfoTest.java

@Test
public void testGrantedWriteForGroup() throws IOException, JSONException {
    testGroupId = H.createTestGroup();//from   w  w w.j  a v a  2s. c o m
    testUserId = H.createTestUser();
    testFolderUrl = H.createTestFolder();

    Credentials adminCreds = new UsernamePasswordCredentials("admin", "admin");

    //add testUserId to testGroup
    String groupPostUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".update.html";
    List<NameValuePair> groupPostParams = new ArrayList<NameValuePair>();
    groupPostParams.add(new NameValuePair(":member", testUserId));
    H.assertAuthenticatedPostStatus(adminCreds, groupPostUrl, HttpServletResponse.SC_OK, groupPostParams, null);

    //assign some privileges
    String postUrl = testFolderUrl + ".modifyAce.html";

    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair("principalId", testGroupId));
    postParams.add(new NameValuePair("privilege@jcr:read", "granted"));
    postParams.add(new NameValuePair("privilege@jcr:write", "granted"));
    postParams.add(new NameValuePair("privilege@jcr:readAccessControl", "granted"));
    postParams.add(new NameValuePair("privilege@jcr:modifyAccessControl", "granted"));

    H.assertAuthenticatedPostStatus(adminCreds, postUrl, HttpServletResponse.SC_OK, postParams, null);

    String getUrl = testFolderUrl + ".privileges-info.json";

    //fetch the JSON for the test page to verify the settings.
    Credentials testUserCreds = new UsernamePasswordCredentials(testUserId, "testPwd");

    String json = H.getAuthenticatedContent(testUserCreds, getUrl, HttpTest.CONTENT_TYPE_JSON, null,
            HttpServletResponse.SC_OK);
    assertNotNull(json);
    JSONObject jsonObj = new JSONObject(json);

    assertEquals(true, jsonObj.getBoolean("canAddChildren"));
    assertEquals(true, jsonObj.getBoolean("canDeleteChildren"));
    //the parent node must also have jcr:removeChildren granted for 'canDelete' to be true
    assertEquals(false, jsonObj.getBoolean("canDelete"));
    assertEquals(true, jsonObj.getBoolean("canModifyProperties"));
    assertEquals(true, jsonObj.getBoolean("canReadAccessControl"));
    assertEquals(true, jsonObj.getBoolean("canModifyAccessControl"));

    //add a child node to verify the 'canDelete' use case
    String childFolderUrl = H.getTestClient().createNode(
            testFolderUrl + "/testFolder" + random.nextInt() + SlingPostConstants.DEFAULT_CREATE_SUFFIX, null);
    String childPostUrl = childFolderUrl + ".modifyAce.html";

    postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair("principalId", testGroupId));
    postParams.add(new NameValuePair("privilege@jcr:read", "granted"));
    postParams.add(new NameValuePair("privilege@jcr:removeNode", "granted"));
    H.assertAuthenticatedPostStatus(adminCreds, childPostUrl, HttpServletResponse.SC_OK, postParams, null);

    String childGetUrl = childFolderUrl + ".privileges-info.json";
    String childJson = H.getAuthenticatedContent(testUserCreds, childGetUrl, HttpTest.CONTENT_TYPE_JSON, null,
            HttpServletResponse.SC_OK);
    assertNotNull(childJson);
    JSONObject childJsonObj = new JSONObject(childJson);
    assertEquals(true, childJsonObj.getBoolean("canDelete"));
}