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


Java JwtAuthenticator类代码示例

本文整理汇总了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;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:21,代码来源:TokenAuthenticationHandler.java

示例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);
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:17,代码来源:JwtTests.java

示例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());
}
 
开发者ID:daflockinger,项目名称:spongeblog,代码行数:21,代码来源:Secured.java

示例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());
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:10,代码来源:JwtTests.java

示例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());
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:8,代码来源:JwtTests.java

示例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));
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:11,代码来源:JwtTests.java

示例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));
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:11,代码来源:JwtTests.java

示例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)");
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:8,代码来源:JwtTests.java

示例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);
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:11,代码来源:JwtTests.java

示例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));
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:10,代码来源:JwtTests.java

示例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);
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:15,代码来源:JwtTests.java

示例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"));
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:11,代码来源:JwtTests.java

示例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:"));
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:11,代码来源:JwtTests.java

示例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:"));
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:12,代码来源:JwtTests.java

示例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));
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:9,代码来源:JwtTests.java


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