當前位置: 首頁>>代碼示例>>Java>>正文


Java Authenticator.authenticate方法代碼示例

本文整理匯總了Java中io.dropwizard.auth.Authenticator.authenticate方法的典型用法代碼示例。如果您正苦於以下問題:Java Authenticator.authenticate方法的具體用法?Java Authenticator.authenticate怎麽用?Java Authenticator.authenticate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.dropwizard.auth.Authenticator的用法示例。


在下文中一共展示了Authenticator.authenticate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testAuthenticate

import io.dropwizard.auth.Authenticator; //導入方法依賴的package包/類
@Test
public void testAuthenticate() throws AuthenticationException {
    final Authenticator<BasicCredentials, Principal> authenticator = new BasicAuthenticator(getAuthFile());
    final BasicCredentials credentials = new BasicCredentials("acoburn", "secret");

    final Optional<Principal> res = authenticator.authenticate(credentials);
    assertTrue(res.isPresent());
    res.ifPresent(p -> {
        assertEquals("https://acoburn.people.amherst.edu/", p.getName());
    });
}
 
開發者ID:trellis-ldp,項目名稱:trellis-rosid,代碼行數:12,代碼來源:BasicAuthenticatorTest.java

示例2: testAuthenticateNoWebid

import io.dropwizard.auth.Authenticator; //導入方法依賴的package包/類
@Test
public void testAuthenticateNoWebid() throws AuthenticationException {
    final Authenticator<BasicCredentials, Principal> authenticator = new BasicAuthenticator(getAuthFile());
    final BasicCredentials credentials = new BasicCredentials("other", "pass");

    final Optional<Principal> res = authenticator.authenticate(credentials);
    assertFalse(res.isPresent());
}
 
開發者ID:trellis-ldp,項目名稱:trellis-rosid,代碼行數:9,代碼來源:BasicAuthenticatorTest.java

示例3: testAuthenticateInvalid

import io.dropwizard.auth.Authenticator; //導入方法依賴的package包/類
@Test
public void testAuthenticateInvalid() throws AuthenticationException {
    final Authenticator<BasicCredentials, Principal> authenticator = new BasicAuthenticator(getAuthFile());
    final BasicCredentials credentials = new BasicCredentials("acoburn", "incorrect");

    final Optional<Principal> res = authenticator.authenticate(credentials);
    assertFalse(res.isPresent());
}
 
開發者ID:trellis-ldp,項目名稱:trellis-rosid,代碼行數:9,代碼來源:BasicAuthenticatorTest.java

示例4: testAuthenticateInvalidFile

import io.dropwizard.auth.Authenticator; //導入方法依賴的package包/類
@Test
public void testAuthenticateInvalidFile() throws AuthenticationException {
    final Authenticator<BasicCredentials, Principal> authenticator = new BasicAuthenticator(
            getAuthFile() + "missing");
    final BasicCredentials credentials = new BasicCredentials("acoburn", "incorrect");

    final Optional<Principal> res = authenticator.authenticate(credentials);
    assertFalse(res.isPresent());
}
 
開發者ID:trellis-ldp,項目名稱:trellis-rosid,代碼行數:10,代碼來源:BasicAuthenticatorTest.java

示例5: testAuthenticateUnreadableFile

import io.dropwizard.auth.Authenticator; //導入方法依賴的package包/類
@Test
public void testAuthenticateUnreadableFile() throws AuthenticationException {
    final Authenticator<BasicCredentials, Principal> authenticator = new BasicAuthenticator(getAuthFile());
    final BasicCredentials credentials = new BasicCredentials("acoburn", "secret");

    final File userFile = new File(getAuthFile());
    assumeTrue(userFile.setReadable(false));

    final Optional<Principal> res = authenticator.authenticate(credentials);
    assertFalse(res.isPresent());
    userFile.setReadable(true);
}
 
開發者ID:trellis-ldp,項目名稱:trellis-rosid,代碼行數:13,代碼來源:BasicAuthenticatorTest.java

示例6: testAuthenticate

import io.dropwizard.auth.Authenticator; //導入方法依賴的package包/類
@Test
public void testAuthenticate() throws AuthenticationException {
    final Authenticator<String, Principal> authenticator = new AnonymousAuthenticator();

    final Optional<Principal> res = authenticator.authenticate("blahblah");
    assertTrue(res.isPresent());
    res.ifPresent(p -> {
        assertEquals(Trellis.AnonymousAgent.getIRIString(), p.getName());
    });
}
 
開發者ID:trellis-ldp,項目名稱:trellis-rosid,代碼行數:11,代碼來源:AnonymousAuthenticatorTest.java

示例7: testAuthenticate

import io.dropwizard.auth.Authenticator; //導入方法依賴的package包/類
@Test
public void testAuthenticate() throws AuthenticationException {
     final String key = "c2VjcmV0";
     final String token = Jwts.builder().setSubject("https://acoburn.people.amherst.edu")
         .signWith(SignatureAlgorithm.HS512, key).compact();

    final Authenticator<String, Principal> authenticator = new JwtAuthenticator(key, true);

    final Optional<Principal> result = authenticator.authenticate(token);
    assertTrue(result.isPresent());
    result.ifPresent(p -> {
        assertEquals("https://acoburn.people.amherst.edu", p.getName());
    });
}
 
開發者ID:trellis-ldp,項目名稱:trellis-rosid,代碼行數:15,代碼來源:JwtAuthenticatorTest.java

示例8: testAuthenticateNoSub

import io.dropwizard.auth.Authenticator; //導入方法依賴的package包/類
@Test
public void testAuthenticateNoSub() throws AuthenticationException {
     final String key = "c2VjcmV0";
     final String token = Jwts.builder().setIssuer("http://localhost")
         .signWith(SignatureAlgorithm.HS512, key).compact();

    final Authenticator<String, Principal> authenticator = new JwtAuthenticator(key, true);

    final Optional<Principal> result = authenticator.authenticate(token);
    assertFalse(result.isPresent());
}
 
開發者ID:trellis-ldp,項目名稱:trellis-rosid,代碼行數:12,代碼來源:JwtAuthenticatorTest.java

示例9: testAuthenticateSubIss

import io.dropwizard.auth.Authenticator; //導入方法依賴的package包/類
@Test
public void testAuthenticateSubIss() throws AuthenticationException {
     final String key = "c2VjcmV0";
     final String token = Jwts.builder().setSubject("acoburn").setIssuer("http://localhost")
         .signWith(SignatureAlgorithm.HS512, key).compact();

    final Authenticator<String, Principal> authenticator = new JwtAuthenticator(key, true);

    final Optional<Principal> result = authenticator.authenticate(token);
    assertTrue(result.isPresent());
    result.ifPresent(p -> {
        assertEquals("http://localhost/acoburn", p.getName());
    });
}
 
開發者ID:trellis-ldp,項目名稱:trellis-rosid,代碼行數:15,代碼來源:JwtAuthenticatorTest.java

示例10: testAuthenticateSubNoWebIss

import io.dropwizard.auth.Authenticator; //導入方法依賴的package包/類
@Test
public void testAuthenticateSubNoWebIss() throws AuthenticationException {
     final String key = "c2VjcmV0";
     final String token = Jwts.builder().setSubject("acoburn").setIssuer("some org")
         .signWith(SignatureAlgorithm.HS512, key).compact();

    final Authenticator<String, Principal> authenticator = new JwtAuthenticator(key, true);

    final Optional<Principal> result = authenticator.authenticate(token);
    assertFalse(result.isPresent());
}
 
開發者ID:trellis-ldp,項目名稱:trellis-rosid,代碼行數:12,代碼來源:JwtAuthenticatorTest.java

示例11: testAuthenticateToken

import io.dropwizard.auth.Authenticator; //導入方法依賴的package包/類
@Test
public void testAuthenticateToken() throws AuthenticationException {
    final String key = "secret";
    final String token = "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJodHRwczovL2Fjb2J1cm4ucGVvcGxlLmFtaGVyc3QuZWR1In0." +
        "ct-fzDrpgxqQVjqclpYgCoqZgysjGZFqM0nEjERwIgboC0SGq43cemyZILdeaJpp0tGPE2kHUzAWPDcZsQWPkw";

    final Authenticator<String, Principal> authenticator = new JwtAuthenticator(key, false);

    final Optional<Principal> result = authenticator.authenticate(token);
    assertTrue(result.isPresent());
    result.ifPresent(p -> {
        assertEquals("https://acoburn.people.amherst.edu", p.getName());
    });
}
 
開發者ID:trellis-ldp,項目名稱:trellis-rosid,代碼行數:15,代碼來源:JwtAuthenticatorTest.java

示例12: testAuthenticateTokenIssSub

import io.dropwizard.auth.Authenticator; //導入方法依賴的package包/類
@Test
public void testAuthenticateTokenIssSub() throws AuthenticationException {
    final String key = "secret";
    final String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhY29idXJuIiwibmFtZSI6IkFhcm9" +
        "uIENvYnVybiIsImlzcyI6Imh0dHA6Ly9leGFtcGxlLm9yZy8ifQ.DPb_i9vfI5um2X_g_df2y1uFktThGdDBo-Q7AMqjaWc";

    final Authenticator<String, Principal> authenticator = new JwtAuthenticator(key, false);

    final Optional<Principal> result = authenticator.authenticate(token);
    assertTrue(result.isPresent());
    result.ifPresent(p -> {
        assertEquals("http://example.org/acoburn", p.getName());
    });
}
 
開發者ID:trellis-ldp,項目名稱:trellis-rosid,代碼行數:15,代碼來源:JwtAuthenticatorTest.java

示例13: testAuthenticationTokenWebid

import io.dropwizard.auth.Authenticator; //導入方法依賴的package包/類
@Test
public void testAuthenticationTokenWebid() throws AuthenticationException {
    final String key = "secret";
    final String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ3ZWJpZCI6Imh0dHBzOi8vYWNvYnVybi5wZW9w" +
        "bGUuYW1oZXJzdC5lZHUvIiwic3ViIjoiYWNvYnVybiIsIm5hbWUiOiJBYXJvbiBDb2J1cm4iLCJpc3MiOiJodHRwOi8vZX" +
        "hhbXBsZS5vcmcvIn0.X-7_VfEuLGzH5ZEqzpkHWp1bo3tMzBiyDcNUwwdLeqw";

    final Authenticator<String, Principal> authenticator = new JwtAuthenticator(key, false);

    final Optional<Principal> result = authenticator.authenticate(token);
    assertTrue(result.isPresent());
    result.ifPresent(p -> {
        assertEquals("https://acoburn.people.amherst.edu/", p.getName());
    });
}
 
開發者ID:trellis-ldp,項目名稱:trellis-rosid,代碼行數:16,代碼來源:JwtAuthenticatorTest.java

示例14: testAuthenticationTokenWebidBadKey

import io.dropwizard.auth.Authenticator; //導入方法依賴的package包/類
@Test
public void testAuthenticationTokenWebidBadKey() throws AuthenticationException {
    final String key = "incorrect";
    final String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ3ZWJpZCI6Imh0dHBzOi8vYWNvYnVybi5wZW9w" +
        "bGUuYW1oZXJzdC5lZHUvIiwic3ViIjoiYWNvYnVybiIsIm5hbWUiOiJBYXJvbiBDb2J1cm4iLCJpc3MiOiJodHRwOi8vZX" +
        "hhbXBsZS5vcmcvIn0.X-7_VfEuLGzH5ZEqzpkHWp1bo3tMzBiyDcNUwwdLeqw";

    final Authenticator<String, Principal> authenticator = new JwtAuthenticator(key, false);

    final Optional<Principal> result = authenticator.authenticate(token);
    assertFalse(result.isPresent());
}
 
開發者ID:trellis-ldp,項目名稱:trellis-rosid,代碼行數:13,代碼來源:JwtAuthenticatorTest.java

示例15: testAuthenticationNoPrincipal

import io.dropwizard.auth.Authenticator; //導入方法依賴的package包/類
@Test
public void testAuthenticationNoPrincipal() throws AuthenticationException {
    final String key = "secret";
    final String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhY29idXJuIiwibmFtZSI" +
        "6IkFhcm9uIENvYnVybiJ9.IMuzkEyDDHaLi8wps_W3F6wJkIVwocK4DFb8OFYaADA";

    final Authenticator<String, Principal> authenticator = new JwtAuthenticator(key, false);

    final Optional<Principal> result = authenticator.authenticate(token);
    assertFalse(result.isPresent());
}
 
開發者ID:trellis-ldp,項目名稱:trellis-rosid,代碼行數:12,代碼來源:JwtAuthenticatorTest.java


注:本文中的io.dropwizard.auth.Authenticator.authenticate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。