当前位置: 首页>>代码示例>>Java>>正文


Java UsernamePasswordCredentials类代码示例

本文整理汇总了Java中org.apache.commons.httpclient.UsernamePasswordCredentials的典型用法代码示例。如果您正苦于以下问题:Java UsernamePasswordCredentials类的具体用法?Java UsernamePasswordCredentials怎么用?Java UsernamePasswordCredentials使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


UsernamePasswordCredentials类属于org.apache.commons.httpclient包,在下文中一共展示了UsernamePasswordCredentials类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getUrlContent

import org.apache.commons.httpclient.UsernamePasswordCredentials; //导入依赖的package包/类
/**
 * Retrieves the content under the given URL with username and passwort
 * authentication.
 * 
 * @param url
 *            the URL to read
 * @param username
 * @param password
 * @return the read content.
 * @throws IOException
 *             if an I/O exception occurs.
 */
private static byte[] getUrlContent(URL url, String username,
        String password) throws IOException {
    final HttpClient client = new HttpClient();

    // Set credentials:
    client.getParams().setAuthenticationPreemptive(true);
    final Credentials credentials = new UsernamePasswordCredentials(
            username, password);
    client.getState()
            .setCredentials(
                    new AuthScope(url.getHost(), url.getPort(),
                            AuthScope.ANY_REALM), credentials);

    // Retrieve content:
    final GetMethod method = new GetMethod(url.toString());
    final int status = client.executeMethod(method);
    if (status != HttpStatus.SC_OK) {
        throw new IOException("Error " + status + " while retrieving "
                + url);
    }
    return method.getResponseBody();
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:35,代码来源:BasicAuthLoader.java

示例2: testAddRequest

import org.apache.commons.httpclient.UsernamePasswordCredentials; //导入依赖的package包/类
public void testAddRequest() throws Exception
{
    AuthenticatedUrl url = new AuthenticatedUrl(this.getJrpipUrl(), new UsernamePasswordCredentials("username"));
    Cookie cookie1 = new Cookie("domain", "cookie1", "val1", "/", 1000, false);
    Cookie cookie2 = new Cookie("domain", "cookie2", "val2", "/", 1000, false);
    Cookie cookie3 = new Cookie("domain", "cookie3", "val3", "/", 1000, false);
    ThankYouWriter thankYouWriter = ThankYouWriter.getINSTANCE();
    thankYouWriter.stopThankYouThread();
    thankYouWriter.addRequest(url, new Cookie[]{cookie1, cookie2, cookie3}, new RequestId(1));
    thankYouWriter.addRequest(url, new Cookie[]{cookie1, cookie2, cookie3}, new RequestId(2));  // same combination
    thankYouWriter.addRequest(url, new Cookie[]{cookie3, cookie2, cookie1}, new RequestId(3)); // cookie order changed
    thankYouWriter.addRequest(url, new Cookie[]{cookie3}, new RequestId(4)); // mismatch cookies
    thankYouWriter.addRequest(url, new Cookie[]{}, new RequestId(5)); // no cookies
    thankYouWriter.addRequest(url, null, new RequestId(6)); // null cookies

    assertEquals(3, thankYouWriter.getPendingRequests());
}
 
开发者ID:goldmansachs,项目名称:jrpip,代码行数:18,代码来源:ThankYouWriterTest.java

示例3: addOrUpdateAce

import org.apache.commons.httpclient.UsernamePasswordCredentials; //导入依赖的package包/类
/**
 * Helper to add or update an ace for testing
 */
private void addOrUpdateAce(String folderUrl, String principalId, boolean readGranted, String order) throws IOException, JsonException {
       String postUrl = folderUrl + ".modifyAce.html";

	//1. create an initial set of privileges
	List<NameValuePair> postParams = new ArrayList<NameValuePair>();
	postParams.add(new NameValuePair("principalId", principalId));
	postParams.add(new NameValuePair("[email protected]:read", readGranted ? "granted" : "denied"));
	postParams.add(new NameValuePair("[email protected]:write", "denied"));
	if (order != null) {
		postParams.add(new NameValuePair("order", order));
	}
	
	Credentials creds = new UsernamePasswordCredentials("admin", "admin");
	H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:19,代码来源:ModifyAceTest.java

示例4: testModifyAceResponseAsJSON

import org.apache.commons.httpclient.UsernamePasswordCredentials; //导入依赖的package包/类
/**
 * Test for SLING-1677
 */
@Test 
public void testModifyAceResponseAsJSON() throws IOException, JsonException {
	testUserId = H.createTestUser();
	
	testFolderUrl = H.createTestFolder();
	
       String postUrl = testFolderUrl + ".modifyAce.json";

	List<NameValuePair> postParams = new ArrayList<NameValuePair>();
	postParams.add(new NameValuePair("principalId", testUserId));
	postParams.add(new NameValuePair("[email protected]:read", "granted"));
	postParams.add(new NameValuePair("[email protected]:write", "denied"));
	postParams.add(new NameValuePair("[email protected]:modifyAccessControl", "bogus")); //invalid value should be ignored.
	
	Credentials creds = new UsernamePasswordCredentials("admin", "admin");
	String json = H.getAuthenticatedPostContent(creds, postUrl, HttpTest.CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);

       //make sure the json response can be parsed as a JSON object
       JsonObject jsonObject = JsonUtil.parseObject(json);
	assertNotNull(jsonObject);
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:25,代码来源:ModifyAceTest.java

示例5: testRemoveAce

import org.apache.commons.httpclient.UsernamePasswordCredentials; //导入依赖的package包/类
public void testRemoveAce() throws IOException, JsonException {
	String folderUrl = createFolderWithAces(false);
	
	//remove the ace for the testUser principal
	String postUrl = folderUrl + ".deleteAce.html"; 
	List<NameValuePair> postParams = new ArrayList<NameValuePair>();
	postParams.add(new NameValuePair(":applyTo", testUserId));
       Credentials creds = new UsernamePasswordCredentials("admin", "admin");
	assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);

	//fetch the JSON for the acl to verify the settings.
	String getUrl = folderUrl + ".acl.json";

	String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
	assertNotNull(json);

	JsonObject jsonObject = JsonUtil.parseObject(json);
	assertNotNull(jsonObject);
	assertEquals(0, jsonObject.size());
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:21,代码来源:RemoveAcesTest.java

示例6: testRemoveAces

import org.apache.commons.httpclient.UsernamePasswordCredentials; //导入依赖的package包/类
public void testRemoveAces() throws IOException, JsonException {
	String folderUrl = createFolderWithAces(true);
	
	//remove the ace for the testUser principal
	String postUrl = folderUrl + ".deleteAce.html"; 
	List<NameValuePair> postParams = new ArrayList<NameValuePair>();
	postParams.add(new NameValuePair(":applyTo", testUserId));
	postParams.add(new NameValuePair(":applyTo", testGroupId));
       Credentials creds = new UsernamePasswordCredentials("admin", "admin");
	assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);

	//fetch the JSON for the acl to verify the settings.
	String getUrl = folderUrl + ".acl.json";

	String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
	assertNotNull(json);

	JsonObject jsonObject = JsonUtil.parseObject(json);
	assertNotNull(jsonObject);
	assertEquals(0, jsonObject.size());
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:22,代码来源:RemoveAcesTest.java

示例7: testRemoveAcesResponseAsJSON

import org.apache.commons.httpclient.UsernamePasswordCredentials; //导入依赖的package包/类
/**
 * Test for SLING-1677
 */
public void testRemoveAcesResponseAsJSON() throws IOException, JsonException {
	String folderUrl = createFolderWithAces(true);
	
	//remove the ace for the testUser principal
	String postUrl = folderUrl + ".deleteAce.json"; 
	List<NameValuePair> postParams = new ArrayList<NameValuePair>();
	postParams.add(new NameValuePair(":applyTo", testUserId));
	postParams.add(new NameValuePair(":applyTo", testGroupId));
       Credentials creds = new UsernamePasswordCredentials("admin", "admin");
       String json = getAuthenticatedPostContent(creds, postUrl, CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);

       //make sure the json response can be parsed as a JSON object
       JsonObject jsonObject = JsonUtil.parseObject(json);
	assertNotNull(jsonObject);
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:19,代码来源:RemoveAcesTest.java

示例8: testAnonymousContent

import org.apache.commons.httpclient.UsernamePasswordCredentials; //导入依赖的package包/类
public void testAnonymousContent() throws Exception {
    // disable credentials -> anonymous session
    final URL url = new URL(HTTP_BASE_URL);
    final AuthScope scope = new AuthScope(url.getHost(), url.getPort(), AuthScope.ANY_REALM);
    httpClient.getParams().setAuthenticationPreemptive(false);
    httpClient.getState().setCredentials(scope, null);
    
    try {
        assertContent();
    } finally {
        // re-enable credentials -> admin session
        httpClient.getParams().setAuthenticationPreemptive(true);
        Credentials defaultcreds = new UsernamePasswordCredentials("admin", "admin");
        httpClient.getState().setCredentials(scope, defaultcreds);
    }
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:17,代码来源:AnonymousAccessTest.java

示例9: testValidatingIncorrectHttpBasicCredentials

import org.apache.commons.httpclient.UsernamePasswordCredentials; //导入依赖的package包/类
@Test
public void testValidatingIncorrectHttpBasicCredentials() throws Exception {

    // assume http and webdav are on the same host + port
    URL url = new URL(HttpTest.HTTP_BASE_URL);
    Credentials defaultcreds = new UsernamePasswordCredentials("garbage", "garbage");
    H.getHttpClient().getState()
            .setCredentials(new AuthScope(url.getHost(), url.getPort(), AuthScope.ANY_REALM), defaultcreds);

    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new NameValuePair("j_validate", "true"));
    HttpMethod post = H.assertPostStatus(HttpTest.HTTP_BASE_URL + "/j_security_check",
            HttpServletResponse.SC_FORBIDDEN, params, null);
    assertXReason(post);

    HttpMethod get = H.assertHttpStatus(HttpTest.HTTP_BASE_URL + "/?j_validate=true",
            HttpServletResponse.SC_FORBIDDEN);
    assertXReason(get);
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:20,代码来源:AuthenticationResponseCodeTest.java

示例10: testPreventLoopIncorrectHttpBasicCredentials

import org.apache.commons.httpclient.UsernamePasswordCredentials; //导入依赖的package包/类
@Test
public void testPreventLoopIncorrectHttpBasicCredentials() throws Exception {

    // assume http and webdav are on the same host + port
    URL url = new URL(HttpTest.HTTP_BASE_URL);
    Credentials defaultcreds = new UsernamePasswordCredentials("garbage", "garbage");
    H.getHttpClient().getState()
            .setCredentials(new AuthScope(url.getHost(), url.getPort(), AuthScope.ANY_REALM), defaultcreds);

    final String requestUrl = HttpTest.HTTP_BASE_URL + "/junk?param1=1";
    HttpMethod get = new GetMethod(requestUrl);
    get.setRequestHeader("Referer", requestUrl);
    get.setRequestHeader("User-Agent", "Mozilla/5.0 Sling Integration Test");
    int status = H.getHttpClient().executeMethod(get);
    assertEquals(HttpServletResponse.SC_UNAUTHORIZED, status);
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:17,代码来源:AuthenticationResponseCodeTest.java

示例11: testDigestAuthenticationMD5SessInvalidQop

import org.apache.commons.httpclient.UsernamePasswordCredentials; //导入依赖的package包/类
/** 
 * Test digest authentication with invalud qop value
 */
public void testDigestAuthenticationMD5SessInvalidQop() throws Exception {
    // Example using Digest auth with MD5-sess

    String realm="realm";
    String username="username";
    String password="password";
    String nonce="e273f1776275974f1a120d8b92c5b3cb";

    String challenge="Digest realm=\"" + realm + "\", "
        + "nonce=\"" + nonce + "\", "
        + "opaque=\"SomeString\", "
        + "stale=false, "
        + "algorithm=MD5-sess, "
        + "qop=\"jakarta\""; // jakarta is an invalid qop value

    UsernamePasswordCredentials cred =
        new UsernamePasswordCredentials(username, password);
    try {
        AuthScheme authscheme = new DigestScheme();
        authscheme.processChallenge(challenge);
        fail("MalformedChallengeException exception expected due to invalid qop value");
    } catch(MalformedChallengeException e) {
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:28,代码来源:TestDigestAuth.java

示例12: createTestUser

import org.apache.commons.httpclient.UsernamePasswordCredentials; //导入依赖的package包/类
public String createTestUser() throws IOException {
      String postUrl = HTTP_BASE_URL + "/system/userManager/user.create.html";

      String testUserId = "testUser" + getNextInt();
      List<NameValuePair> postParams = new ArrayList<NameValuePair>();
      postParams.add(new NameValuePair(":name", testUserId));
      postParams.add(new NameValuePair("pwd", "testPwd"));
      postParams.add(new NameValuePair("pwdConfirm", "testPwd"));
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
final String msg = "Unexpected status while attempting to create test user at " + postUrl; 
      assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, msg);
      
      final String sessionInfoUrl = HTTP_BASE_URL + "/system/sling/info.sessionInfo.json";
      assertAuthenticatedHttpStatus(creds, sessionInfoUrl, HttpServletResponse.SC_OK, 
              "session info failed for user " + testUserId);

      return testUserId;
  }
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:19,代码来源:AuthenticatedTestUtil.java

示例13: testCreateUserResponseAsJSON

import org.apache.commons.httpclient.UsernamePasswordCredentials; //导入依赖的package包/类
/**
 * Test for SLING-1677
 */
@Test 
public void testCreateUserResponseAsJSON() throws IOException, JsonException {
       String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user.create.json";

	testUserId = "testUser" + random.nextInt();
	List<NameValuePair> postParams = new ArrayList<NameValuePair>();
	postParams.add(new NameValuePair(":name", testUserId));
	postParams.add(new NameValuePair("marker", testUserId));
	postParams.add(new NameValuePair("pwd", "testPwd"));
	postParams.add(new NameValuePair("pwdConfirm", "testPwd"));
	Credentials creds = new UsernamePasswordCredentials("admin", "admin");
	String json = H.getAuthenticatedPostContent(creds, postUrl, HttpTest.CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);

	//make sure the json response can be parsed as a JSON object
	JsonObject jsonObj = JsonUtil.parseObject(json);
	assertNotNull(jsonObj);
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:21,代码来源:CreateUserTest.java

示例14: testUpdateUserResponseAsJSON

import org.apache.commons.httpclient.UsernamePasswordCredentials; //导入依赖的package包/类
/**
 * Test for SLING-1677
 */
@Test 
public void testUpdateUserResponseAsJSON() throws IOException, JsonException {
	testUserId = H.createTestUser();
	
       String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".update.json";

	List<NameValuePair> postParams = new ArrayList<NameValuePair>();
	postParams.add(new NameValuePair("displayName", "My Updated Test User"));
	postParams.add(new NameValuePair("url", "http://www.apache.org/updated"));
	Credentials creds = new UsernamePasswordCredentials(testUserId, "testPwd");
	String json = H.getAuthenticatedPostContent(creds, postUrl, HttpTest.CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);

	//make sure the json response can be parsed as a JSON object
	JsonObject jsonObj = JsonUtil.parseObject(json);
	assertNotNull(jsonObj);
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:20,代码来源:UpdateUserTest.java

示例15: testCanAddUser

import org.apache.commons.httpclient.UsernamePasswordCredentials; //导入依赖的package包/类
/**
 * Checks whether the current user has been granted privileges
 * to add a new user.
 */
@Test 
public void testCanAddUser() throws JsonException, IOException {
	testUserId = H.createTestUser();

	String getUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".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 = JsonUtil.parseObject(json);
	
	assertEquals(false, jsonObj.getBoolean("canAddUser"));
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:20,代码来源:UserPrivilegesInfoTest.java


注:本文中的org.apache.commons.httpclient.UsernamePasswordCredentials类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。