本文整理汇总了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());
});
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}
示例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());
});
}
示例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());
});
}
示例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());
}
示例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());
});
}
示例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());
}
示例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());
});
}
示例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());
});
}
示例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());
});
}
示例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());
}
示例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());
}