本文整理汇总了Java中org.pac4j.jwt.credentials.authenticator.JwtAuthenticator类的典型用法代码示例。如果您正苦于以下问题:Java JwtAuthenticator类的具体用法?Java JwtAuthenticator怎么用?Java JwtAuthenticator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JwtAuthenticator类属于org.pac4j.jwt.credentials.authenticator包,在下文中一共展示了JwtAuthenticator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAuthenticator
import org.pac4j.jwt.credentials.authenticator.JwtAuthenticator; //导入依赖的package包/类
@Override
protected Authenticator getAuthenticator(final Credential credential) {
final TokenCredential tokenCredential = (TokenCredential) credential;
logger.debug("Locating token secret for service [{}]", tokenCredential.getService());
final RegisteredService service = this.servicesManager.findServiceBy(tokenCredential.getService());
final String signingSecret = getRegisteredServiceJwtSigningSecret(service);
final String encryptionSecret = getRegisteredServiceJwtEncryptionSecret(service);
if (StringUtils.isNotBlank(signingSecret)) {
if (StringUtils.isBlank(encryptionSecret)) {
logger.warn("JWT authentication is configured to share a single key for both signing/encryption");
return new JwtAuthenticator(signingSecret);
}
return new JwtAuthenticator(signingSecret, encryptionSecret);
}
logger.warn("No token signing secret is defined for service [{}]. Ensure [{}] property is defined for service",
service.getServiceId(), TokenConstants.PROPERTY_NAME_TOKEN_SECRET_SIGNING);
return null;
}
示例2: testGenerateAuthenticateClaims
import org.pac4j.jwt.credentials.authenticator.JwtAuthenticator; //导入依赖的package包/类
@Test
public void testGenerateAuthenticateClaims() throws HttpAction {
final JwtGenerator<JwtProfile> generator = new JwtGenerator<>(new SecretSignatureConfiguration(MAC_SECRET), new SecretEncryptionConfiguration(MAC_SECRET));
final Map<String, Object> claims = new HashMap<>();
claims.put(JwtClaims.SUBJECT, VALUE);
final Date tomorrow = tomorrow();
claims.put(JwtClaims.EXPIRATION_TIME, tomorrow);
final String token = generator.generate(claims);
final JwtAuthenticator jwtAuthenticator = new JwtAuthenticator(new SecretSignatureConfiguration(MAC_SECRET), new SecretEncryptionConfiguration(MAC_SECRET));
final JwtProfile profile = (JwtProfile) jwtAuthenticator.validateToken(token);
assertEquals(VALUE, profile.getSubject());
assertEquals(tomorrow.getTime() / 1000, profile.getExpirationDate().getTime() / 1000);
final Map<String, Object> claims2 = jwtAuthenticator.validateTokenAndGetClaims(token);
assertEquals(VALUE, claims2.get(JwtClaims.SUBJECT));
assertEquals(tomorrow.getTime() / 1000, ((Date) claims2.get(JwtClaims.EXPIRATION_TIME)).getTime() / 1000);
}
示例3: configure
import org.pac4j.jwt.credentials.authenticator.JwtAuthenticator; //导入依赖的package包/类
@Override
protected void configure() {// go for JWT!!!
bind(PlaySessionStore.class).to(PlayCacheStore.class);
JwtAuthenticator auth = new JwtAuthenticator();
/*auth.setSignatureConfigurations(
signingSecrets.stream().map(secret -> new SecretSignatureConfiguration(secret))
.collect(Collectors.toList()));
auth.setEncryptionConfigurations(
signingSecrets.stream().map(secret -> new SecretEncryptionConfiguration(secret))
.collect(Collectors.toList()));*/
ParameterClient parameterClient = new ParameterClient("token", auth);
parameterClient.setSupportGetRequest(true);
parameterClient.setSupportPostRequest(false);
// final IndirectBasicAuthClient indirectBasicAuthClient = new
// IndirectBasicAuthClient(new
// SimpleTestUsernamePasswordAuthenticator());
}
示例4: testGenericJwt
import org.pac4j.jwt.credentials.authenticator.JwtAuthenticator; //导入依赖的package包/类
@Test
public void testGenericJwt() throws HttpAction {
final String token = "eyJjdHkiOiJKV1QiLCJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiZGlyIn0..NTvhJXwZ_sN4zYBK.exyLJWkOclCVcffz58CE-3XWWV24aYyGWR5HVrfm4HLQi1xgmwglLlEIiFlOSTOSZ_LeAwl2Z3VFh-5EidocjwGkAPGQA_4_KCLbK8Im7M25ZZvDzCJ1kKN1JrDIIrBWCcuI4Mbw0O_YGb8TfIECPkpeG7wEgBG30sb1kH-F_vg9yjYfB4MiJCSFmY7cRqN9-9O23tz3wYv3b-eJh5ACr2CGSVNj2KcMsOMJ6bbALgz6pzQTIWk_fhcE9QSfaSY7RuZ8cRTV-UTjYgZk1gbd1LskgchS.ijMQmfPlObJv7oaPG8LCEg";
final TokenCredentials credentials = new TokenCredentials(token, JwtAuthenticator.class.getName());
final JwtAuthenticator authenticator = new JwtAuthenticator(new SecretSignatureConfiguration(MAC_SECRET), new SecretEncryptionConfiguration(MAC_SECRET));
authenticator.validate(credentials, null);
assertNotNull(credentials.getUserProfile());
}
示例5: testPlainJwtWithoutSignatureConfigurations
import org.pac4j.jwt.credentials.authenticator.JwtAuthenticator; //导入依赖的package包/类
@Test
public void testPlainJwtWithoutSignatureConfigurations() throws HttpAction {
final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>();
final FacebookProfile profile = createProfile();
final String token = generator.generate(profile);
assertToken(profile, token, new JwtAuthenticator());
}
示例6: testPlainJwtNotExpired
import org.pac4j.jwt.credentials.authenticator.JwtAuthenticator; //导入依赖的package包/类
@Test
public void testPlainJwtNotExpired() throws HttpAction {
final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>();
Map<String, Object> claims = new HashMap<>();
claims.put(JwtClaims.SUBJECT, ID);
claims.put(JwtClaims.EXPIRATION_TIME, tomorrow());
final String token = generator.generate(claims);
JwtAuthenticator authenticator = new JwtAuthenticator();
assertNotNull(authenticator.validateToken(token));
}
示例7: testPlainJwtExpired
import org.pac4j.jwt.credentials.authenticator.JwtAuthenticator; //导入依赖的package包/类
@Test
public void testPlainJwtExpired() throws HttpAction {
final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>();
Map<String, Object> claims = new HashMap<>();
claims.put(JwtClaims.SUBJECT, ID);
claims.put(JwtClaims.EXPIRATION_TIME, yesterday());
final String token = generator.generate(claims);
JwtAuthenticator authenticator = new JwtAuthenticator();
assertNull(authenticator.validateToken(token));
}
示例8: testPlainJwtNoSubject
import org.pac4j.jwt.credentials.authenticator.JwtAuthenticator; //导入依赖的package包/类
@Test
public void testPlainJwtNoSubject() throws HttpAction {
final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>();
final String token = generator.generate(new HashMap<>());
JwtAuthenticator authenticator = new JwtAuthenticator();
TestsHelper.expectException(() -> authenticator.validateToken(token), TechnicalException.class, "JWT must contain a subject ('sub' claim)");
}
示例9: testPemJwt
import org.pac4j.jwt.credentials.authenticator.JwtAuthenticator; //导入依赖的package包/类
@Test
public void testPemJwt() throws Exception {
final FacebookProfile profile = createProfile();
final ECSignatureConfiguration signatureConfiguration = buildECSignatureConfiguration();
final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>(signatureConfiguration);
final String token = generator.generate(profile);
final JwtAuthenticator authenticator = new JwtAuthenticator();
authenticator.addSignatureConfiguration(signatureConfiguration);
assertToken(profile, token, authenticator);
}
示例10: testGenerateAuthenticateDifferentSecrets
import org.pac4j.jwt.credentials.authenticator.JwtAuthenticator; //导入依赖的package包/类
@Test
public void testGenerateAuthenticateDifferentSecrets() throws HttpAction {
final SignatureConfiguration signatureConfiguration = new SecretSignatureConfiguration(MAC_SECRET);
final EncryptionConfiguration encryptionConfiguration = new SecretEncryptionConfiguration(KEY2);
final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>(signatureConfiguration, encryptionConfiguration);
final FacebookProfile profile = createProfile();
final String token = generator.generate(profile);
assertToken(profile, token, new JwtAuthenticator(signatureConfiguration, encryptionConfiguration));
}
示例11: testGenerateAuthenticateUselessSignatureConfiguration
import org.pac4j.jwt.credentials.authenticator.JwtAuthenticator; //导入依赖的package包/类
@Test
public void testGenerateAuthenticateUselessSignatureConfiguration() throws HttpAction {
final SignatureConfiguration signatureConfiguration = new SecretSignatureConfiguration(KEY2);
final SignatureConfiguration signatureConfiguration2 = new SecretSignatureConfiguration(MAC_SECRET);
final EncryptionConfiguration encryptionConfiguration = new SecretEncryptionConfiguration(MAC_SECRET);
final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>(signatureConfiguration, encryptionConfiguration);
final FacebookProfile profile = createProfile();
final String token = generator.generate(profile);
final JwtAuthenticator jwtAuthenticator = new JwtAuthenticator();
jwtAuthenticator.addSignatureConfiguration(signatureConfiguration);
jwtAuthenticator.addSignatureConfiguration(signatureConfiguration2);
jwtAuthenticator.setEncryptionConfiguration(encryptionConfiguration);
assertToken(profile, token, jwtAuthenticator);
}
示例12: testGenerateAuthenticateSlightlyDifferentSignatureConfiguration
import org.pac4j.jwt.credentials.authenticator.JwtAuthenticator; //导入依赖的package包/类
@Test
public void testGenerateAuthenticateSlightlyDifferentSignatureConfiguration() throws HttpAction {
final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>(new SecretSignatureConfiguration(KEY2));
final FacebookProfile profile = createProfile();
final String token = generator.generate(profile);
final JwtAuthenticator jwtAuthenticator = new JwtAuthenticator();
jwtAuthenticator.addSignatureConfiguration(new SecretSignatureConfiguration(MAC_SECRET));
final Exception e = TestsHelper.expectException(() -> assertToken(profile, token, jwtAuthenticator));
assertTrue(e.getMessage().startsWith("JWT verification failed"));
}
示例13: testGenerateAuthenticateDifferentSignatureConfiguration
import org.pac4j.jwt.credentials.authenticator.JwtAuthenticator; //导入依赖的package包/类
@Test
public void testGenerateAuthenticateDifferentSignatureConfiguration() throws Exception {
final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>(new SecretSignatureConfiguration(KEY2));
final FacebookProfile profile = createProfile();
final String token = generator.generate(profile);
final JwtAuthenticator jwtAuthenticator = new JwtAuthenticator();
jwtAuthenticator.addSignatureConfiguration(buildECSignatureConfiguration());
final Exception e = TestsHelper.expectException(() -> assertToken(profile, token, jwtAuthenticator));
assertTrue(e.getMessage().startsWith("No signature algorithm found for JWT:"));
}
示例14: testGenerateAuthenticateDifferentEncryptionConfiguration
import org.pac4j.jwt.credentials.authenticator.JwtAuthenticator; //导入依赖的package包/类
@Test
public void testGenerateAuthenticateDifferentEncryptionConfiguration() throws HttpAction {
final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>();
generator.setEncryptionConfiguration(new SecretEncryptionConfiguration(KEY2));
final FacebookProfile profile = createProfile();
final String token = generator.generate(profile);
final JwtAuthenticator jwtAuthenticator = new JwtAuthenticator();
jwtAuthenticator.addEncryptionConfiguration(new SecretEncryptionConfiguration(MAC_SECRET));
final Exception e = TestsHelper.expectException(() -> assertToken(profile, token, jwtAuthenticator));
assertTrue(e.getMessage().startsWith("No encryption algorithm found for JWT:"));
}
示例15: testGenerateAuthenticateAndEncrypted
import org.pac4j.jwt.credentials.authenticator.JwtAuthenticator; //导入依赖的package包/类
@Deprecated
@Test
public void testGenerateAuthenticateAndEncrypted() throws HttpAction {
final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>(MAC_SECRET, MAC_SECRET);
final FacebookProfile profile = createProfile();
final String token = generator.generate(profile);
assertToken(profile, token, new JwtAuthenticator(MAC_SECRET, MAC_SECRET));
}