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


Java AUTH.WWW_AUTH属性代码示例

本文整理汇总了Java中org.apache.http.auth.AUTH.WWW_AUTH属性的典型用法代码示例。如果您正苦于以下问题:Java AUTH.WWW_AUTH属性的具体用法?Java AUTH.WWW_AUTH怎么用?Java AUTH.WWW_AUTH使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.apache.http.auth.AUTH的用法示例。


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

示例1: testDigestAuthenticationQopAuthInt

@Test
public void testDigestAuthenticationQopAuthInt() throws Exception {
    final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " +
            "qop=\"auth,auth-int\"";
    final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
    final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("Post", "/");
    request.setEntity(new StringEntity("abc\u00e4\u00f6\u00fcabc", HTTP.DEF_CONTENT_CHARSET));
    final Credentials cred = new UsernamePasswordCredentials("username","password");
    final DigestScheme authscheme = new DigestScheme();
    final HttpContext context = new BasicHttpContext();
    authscheme.processChallenge(authChallenge);
    final Header authResponse = authscheme.authenticate(cred, request, context);

    Assert.assertEquals("Post:/:acd2b59cd01c7737d8069015584c6cac", authscheme.getA2());

    final Map<String, String> table = parseAuthResponse(authResponse);
    Assert.assertEquals("username", table.get("username"));
    Assert.assertEquals("realm1", table.get("realm"));
    Assert.assertEquals("/", table.get("uri"));
    Assert.assertEquals("auth-int", table.get("qop"));
    Assert.assertEquals("f2a3f18799759d4f1a1c068b92b573cb", table.get("nonce"));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:22,代码来源:TestDigestScheme.java

示例2: testProcessChallenge

@Test
public void testProcessChallenge() throws Exception {
    final TestAuthScheme authscheme = new TestAuthScheme();
    final Header header = new BasicHeader(
            AUTH.WWW_AUTH,
            "Test realm=\"realm1\", test, test1 =  stuff, test2 =  \"stuff, stuff\", test3=\"crap");

    authscheme.processChallenge(header);

    Assert.assertEquals("test", authscheme.getSchemeName());
    Assert.assertEquals("TEST", authscheme.toString());
    Assert.assertEquals("realm1", authscheme.getParameter("realm"));
    Assert.assertEquals(null, authscheme.getParameter("test"));
    Assert.assertEquals("stuff", authscheme.getParameter("test1"));
    Assert.assertEquals("stuff, stuff", authscheme.getParameter("test2"));
    Assert.assertEquals("crap", authscheme.getParameter("test3"));
    Assert.assertEquals(null, authscheme.getParameter(null));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:18,代码来源:TestRFC2617Scheme.java

示例3: testSerialization

@Test
public void testSerialization() throws Exception {
    final Header challenge = new BasicHeader(AUTH.WWW_AUTH, "test realm=\"test\", blah=blah, yada=\"yada yada\"");

    final TestAuthScheme testScheme = new TestAuthScheme(Consts.ISO_8859_1);
    testScheme.processChallenge(challenge);

    final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    final ObjectOutputStream out = new ObjectOutputStream(buffer);
    out.writeObject(testScheme);
    out.flush();
    final byte[] raw = buffer.toByteArray();
    final ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(raw));
    final TestAuthScheme authScheme = (TestAuthScheme) in.readObject();

    Assert.assertEquals(Consts.ISO_8859_1, authScheme.getCredentialsCharset());
    Assert.assertEquals("test", authScheme.getParameter("realm"));
    Assert.assertEquals("blah", authScheme.getParameter("blah"));
    Assert.assertEquals("yada yada", authScheme.getParameter("yada"));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:20,代码来源:TestRFC2617Scheme.java

示例4: testSerialization

@Test
public void testSerialization() throws Exception {
    final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " +
            "qop=\"auth,auth-int\"";
    final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
    final DigestScheme digestScheme = new DigestScheme();
    digestScheme.processChallenge(authChallenge);

    final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    final ObjectOutputStream out = new ObjectOutputStream(buffer);
    out.writeObject(digestScheme);
    out.flush();
    final byte[] raw = buffer.toByteArray();
    final ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(raw));
    final DigestScheme authScheme = (DigestScheme) in.readObject();

    Assert.assertEquals(digestScheme.getSchemeName(), authScheme.getSchemeName());
    Assert.assertEquals(digestScheme.getRealm(), authScheme.getRealm());
    Assert.assertEquals(digestScheme.isComplete(), authScheme.isComplete());
    Assert.assertEquals(digestScheme.getA1(), authScheme.getA1());
    Assert.assertEquals(digestScheme.getA2(), authScheme.getA2());
    Assert.assertEquals(digestScheme.getCnonce(), authScheme.getCnonce());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:23,代码来源:TestDigestScheme.java

示例5: testDigestAuthenticationQopAuthOrAuthIntNonRepeatableEntity

@Test
public void testDigestAuthenticationQopAuthOrAuthIntNonRepeatableEntity() throws Exception {
    final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " +
            "qop=\"auth,auth-int\"";
    final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
    final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("Post", "/");
    request.setEntity(new InputStreamEntity(new ByteArrayInputStream(new byte[] {'a'}), -1));
    final Credentials cred = new UsernamePasswordCredentials("username","password");
    final DigestScheme authscheme = new DigestScheme();
    final HttpContext context = new BasicHttpContext();
    authscheme.processChallenge(authChallenge);
    final Header authResponse = authscheme.authenticate(cred, request, context);

    Assert.assertEquals("Post:/", authscheme.getA2());

    final Map<String, String> table = parseAuthResponse(authResponse);
    Assert.assertEquals("username", table.get("username"));
    Assert.assertEquals("realm1", table.get("realm"));
    Assert.assertEquals("/", table.get("uri"));
    Assert.assertEquals("auth", table.get("qop"));
    Assert.assertEquals("f2a3f18799759d4f1a1c068b92b573cb", table.get("nonce"));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:22,代码来源:TestDigestScheme.java

示例6: testDigestAuthenticationOverrideParameter

@Test
public void testDigestAuthenticationOverrideParameter() throws Exception {
    final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\"";
    final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
    final HttpRequest request = new BasicHttpRequest("Simple", "/");
    final Credentials cred = new UsernamePasswordCredentials("username","password");
    final DigestScheme authscheme = new DigestScheme();
    final HttpContext context = new BasicHttpContext();
    authscheme.processChallenge(authChallenge);
    authscheme.overrideParamter("realm", "other realm");
    final Header authResponse = authscheme.authenticate(cred, request, context);

    final Map<String, String> table = parseAuthResponse(authResponse);
    Assert.assertEquals("username", table.get("username"));
    Assert.assertEquals("other realm", table.get("realm"));
    Assert.assertEquals("/", table.get("uri"));
    Assert.assertEquals("f2a3f18799759d4f1a1c068b92b573cb", table.get("nonce"));
    Assert.assertEquals("3f211de10463cbd055ab4cd9c5158eac", table.get("response"));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:19,代码来源:TestDigestScheme.java

示例7: testDigestAuthenticationWithSHA

@Test
public void testDigestAuthenticationWithSHA() throws Exception {
    final String challenge = "Digest realm=\"realm1\", " +
            "nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " +
            "algorithm=SHA";
    final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
    final HttpRequest request = new BasicHttpRequest("Simple", "/");
    final Credentials cred = new UsernamePasswordCredentials("username","password");
    final HttpContext context = new BasicHttpContext();
    final DigestScheme authscheme = new DigestScheme();
    authscheme.processChallenge(authChallenge);
    final Header authResponse = authscheme.authenticate(cred, request, context);

    final Map<String, String> table = parseAuthResponse(authResponse);
    Assert.assertEquals("username", table.get("username"));
    Assert.assertEquals("realm1", table.get("realm"));
    Assert.assertEquals("/", table.get("uri"));
    Assert.assertEquals("f2a3f18799759d4f1a1c068b92b573cb", table.get("nonce"));
    Assert.assertEquals("8769e82e4e28ecc040b969562b9050580c6d186d", table.get("response"));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:20,代码来源:TestDigestScheme.java

示例8: testDigestAuthenticationWithQueryStringInDigestURI

@Test
public void testDigestAuthenticationWithQueryStringInDigestURI() throws Exception {
    final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\"";
    final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
    final HttpRequest request = new BasicHttpRequest("Simple", "/?param=value");
    final Credentials cred = new UsernamePasswordCredentials("username","password");
    final HttpContext context = new BasicHttpContext();
    final DigestScheme authscheme = new DigestScheme();
    authscheme.processChallenge(authChallenge);
    final Header authResponse = authscheme.authenticate(cred, request, context);

    final Map<String, String> table = parseAuthResponse(authResponse);
    Assert.assertEquals("username", table.get("username"));
    Assert.assertEquals("realm1", table.get("realm"));
    Assert.assertEquals("/?param=value", table.get("uri"));
    Assert.assertEquals("f2a3f18799759d4f1a1c068b92b573cb", table.get("nonce"));
    Assert.assertEquals("a847f58f5fef0bc087bcb9c3eb30e042", table.get("response"));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:18,代码来源:TestDigestScheme.java

示例9: testBasicAuthenticationEmptyChallenge

@Test
public void testBasicAuthenticationEmptyChallenge() throws Exception {
    final String challenge = "Basic";
    final Header header = new BasicHeader(AUTH.WWW_AUTH, challenge);
    final AuthScheme authscheme = new BasicScheme();
    authscheme.processChallenge(header);
    Assert.assertNull(authscheme.getRealm());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:8,代码来源:TestBasicScheme.java

示例10: testDigestAuthenticationWithMultipleRealms

@Test
public void testDigestAuthenticationWithMultipleRealms() throws Exception {
    final String challenge1 = "Digest realm=\"realm1\", nonce=\"abcde\"";
    final String challenge2 = "Digest realm=\"realm2\", nonce=\"123546\"";
    final Credentials cred = new UsernamePasswordCredentials("username","password");
    final Credentials cred2 = new UsernamePasswordCredentials("uname2","password2");

    Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge1);
    final HttpRequest request = new BasicHttpRequest("Simple", "/");
    final HttpContext context = new BasicHttpContext();
    final DigestScheme authscheme = new DigestScheme();
    authscheme.processChallenge(authChallenge);
    Header authResponse = authscheme.authenticate(cred, request, context);

    Map<String, String> table = parseAuthResponse(authResponse);
    Assert.assertEquals("username", table.get("username"));
    Assert.assertEquals("realm1", table.get("realm"));
    Assert.assertEquals("/", table.get("uri"));
    Assert.assertEquals("abcde", table.get("nonce"));
    Assert.assertEquals("786f500303eac1478f3c2865e676ed68", table.get("response"));

    authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge2);
    final DigestScheme authscheme2 = new DigestScheme();
    authscheme2.processChallenge(authChallenge);
    authResponse = authscheme2.authenticate(cred2, request, context);

    table = parseAuthResponse(authResponse);
    Assert.assertEquals("uname2", table.get("username"));
    Assert.assertEquals("realm2", table.get("realm"));
    Assert.assertEquals("/", table.get("uri"));
    Assert.assertEquals("123546", table.get("nonce"));
    Assert.assertEquals("0283edd9ef06a38b378b3b74661391e9", table.get("response"));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:33,代码来源:TestDigestScheme.java

示例11: testDigestAuthenticationNoRealm

@Test(expected=AuthenticationException.class)
public void testDigestAuthenticationNoRealm() throws Exception {
    final String challenge = "Digest no-realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\"";
    final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
    final HttpContext context = new BasicHttpContext();
    final DigestScheme authscheme = new DigestScheme();
    authscheme.processChallenge(authChallenge);

    final Credentials cred = new UsernamePasswordCredentials("username","password");
    final HttpRequest request = new BasicHttpRequest("Simple", "/");
    authscheme.authenticate(cred, request, context);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:12,代码来源:TestDigestScheme.java

示例12: testDigestAuthenticationQopIntOnlyNonRepeatableEntity

@Test(expected=AuthenticationException.class)
public void testDigestAuthenticationQopIntOnlyNonRepeatableEntity() throws Exception {
    final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " +
            "qop=\"auth-int\"";
    final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
    final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("Post", "/");
    request.setEntity(new InputStreamEntity(new ByteArrayInputStream(new byte[] {'a'}), -1));
    final Credentials cred = new UsernamePasswordCredentials("username","password");
    final DigestScheme authscheme = new DigestScheme();
    final HttpContext context = new BasicHttpContext();
    authscheme.processChallenge(authChallenge);
    authscheme.authenticate(cred, request, context);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:13,代码来源:TestDigestScheme.java

示例13: testDigestAuthenticationMD5SessNoQop

/**
 * Test digest authentication using the MD5-sess algorithm.
 */
@Test
public void testDigestAuthenticationMD5SessNoQop() throws Exception {
    // Example using Digest auth with MD5-sess

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

    final String challenge="Digest realm=\"" + realm + "\", "
        + "nonce=\"" + nonce + "\", "
        + "opaque=\"SomeString\", "
        + "stale=false, "
        + "algorithm=MD5-sess";

    final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);

    final Credentials cred = new UsernamePasswordCredentials(username, password);

    final HttpRequest request = new BasicHttpRequest("Simple", "/");
    final HttpContext context = new BasicHttpContext();

    final DigestScheme authscheme = new DigestScheme();
    authscheme.processChallenge(authChallenge);
    final Header authResponse = authscheme.authenticate(cred, request, context);

    final Map<String, String> table = parseAuthResponse(authResponse);
    Assert.assertEquals(username, table.get("username"));
    Assert.assertEquals(realm, table.get("realm"));
    Assert.assertEquals("MD5-sess", table.get("algorithm"));
    Assert.assertEquals("/", table.get("uri"));
    Assert.assertEquals(nonce, table.get("nonce"));
    Assert.assertTrue(null == table.get("nc"));
    Assert.assertEquals("SomeString", table.get("opaque"));
    Assert.assertTrue(null == table.get("qop"));
    //@TODO: add better check
    Assert.assertTrue(null != table.get("response"));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:41,代码来源:TestDigestScheme.java

示例14: testDigestNouceCount

@Test
public void testDigestNouceCount() throws Exception {
    final String challenge1 = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", qop=auth";
    final Header authChallenge1 = new BasicHeader(AUTH.WWW_AUTH, challenge1);
    final HttpRequest request = new BasicHttpRequest("GET", "/");
    final Credentials cred = new UsernamePasswordCredentials("username","password");
    final HttpContext context = new BasicHttpContext();
    final DigestScheme authscheme = new DigestScheme();
    authscheme.processChallenge(authChallenge1);
    final Header authResponse1 = authscheme.authenticate(cred, request, context);
    final Map<String, String> table1 = parseAuthResponse(authResponse1);
    Assert.assertEquals("00000001", table1.get("nc"));
    final Header authResponse2 = authscheme.authenticate(cred, request, context);
    final Map<String, String> table2 = parseAuthResponse(authResponse2);
    Assert.assertEquals("00000002", table2.get("nc"));
    final String challenge2 = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", qop=auth";
    final Header authChallenge2 = new BasicHeader(AUTH.WWW_AUTH, challenge2);
    authscheme.processChallenge(authChallenge2);
    final Header authResponse3 = authscheme.authenticate(cred, request, context);
    final Map<String, String> table3 = parseAuthResponse(authResponse3);
    Assert.assertEquals("00000003", table3.get("nc"));
    final String challenge3 = "Digest realm=\"realm1\", nonce=\"e273f1776275974f1a120d8b92c5b3cb\", qop=auth";
    final Header authChallenge3 = new BasicHeader(AUTH.WWW_AUTH, challenge3);
    authscheme.processChallenge(authChallenge3);
    final Header authResponse4 = authscheme.authenticate(cred, request, context);
    final Map<String, String> table4 = parseAuthResponse(authResponse4);
    Assert.assertEquals("00000001", table4.get("nc"));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:28,代码来源:TestDigestScheme.java

示例15: testDigestAuthenticationUnknownAlgo

/**
 * Test digest authentication with unknown qop value
 */
@Test(expected=AuthenticationException.class)
public void testDigestAuthenticationUnknownAlgo() throws Exception {
    // Example using Digest auth with MD5-sess

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

    final String challenge="Digest realm=\"" + realm + "\", "
        + "nonce=\"" + nonce + "\", "
        + "opaque=\"SomeString\", "
        + "stale=false, "
        + "algorithm=stuff, "
        + "qop=\"auth\"";

    final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);

    final DigestScheme authscheme = new DigestScheme();
    authscheme.processChallenge(authChallenge);

    final Credentials cred = new UsernamePasswordCredentials(username, password);
    final HttpRequest request = new BasicHttpRequest("Simple", "/");
    final HttpContext context = new BasicHttpContext();
    authscheme.authenticate(cred, request, context);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:29,代码来源:TestDigestScheme.java


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