本文整理汇总了Java中org.pac4j.jwt.credentials.authenticator.JwtAuthenticator类的典型用法代码示例。如果您正苦于以下问题:Java JwtAuthenticator类的具体用法?Java JwtAuthenticator怎么用?Java JwtAuthenticator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JwtAuthenticator类属于org.pac4j.jwt.credentials.authenticator包,在下文中一共展示了JwtAuthenticator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: testGenerateAuthenticateAndEncryptedDifferentKeys
import org.pac4j.jwt.credentials.authenticator.JwtAuthenticator; //导入依赖的package包/类
@Deprecated
@Test
public void testGenerateAuthenticateAndEncryptedDifferentKeys() throws HttpAction {
final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>(MAC_SECRET, KEY2);
final FacebookProfile profile = createProfile();
final String token = generator.generate(profile);
assertToken(profile, token, new JwtAuthenticator(MAC_SECRET, KEY2));
}
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:9,代码来源:JwtTests.java
示例17: assertToken
import org.pac4j.jwt.credentials.authenticator.JwtAuthenticator; //导入依赖的package包/类
private CommonProfile assertToken(FacebookProfile profile, String token, JwtAuthenticator authenticator) throws HttpAction {
final TokenCredentials credentials = new TokenCredentials(token, CLIENT_NAME);
authenticator.validate(credentials, null);
final CommonProfile profile2 = credentials.getUserProfile();
assertTrue(profile2 instanceof FacebookProfile);
final FacebookProfile fbProfile = (FacebookProfile) profile2;
assertEquals(profile.getTypedId(), fbProfile.getTypedId());
assertEquals(profile.getFirstName(), fbProfile.getFirstName());
assertEquals(profile.getDisplayName(), fbProfile.getDisplayName());
assertEquals(profile.getFamilyName(), fbProfile.getFamilyName());
assertEquals(profile.getVerified(), fbProfile.getVerified());
return profile2;
}
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:14,代码来源:JwtTests.java
示例18: getAuthenticator
import org.pac4j.jwt.credentials.authenticator.JwtAuthenticator; //导入依赖的package包/类
@Override
protected Authenticator<TokenCredentials> 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);
final String signingSecretAlg =
StringUtils.defaultString(getRegisteredServiceJwtSecret(service, TokenConstants.PROPERTY_NAME_TOKEN_SECRET_SIGNING_ALG),
JWSAlgorithm.HS256.getName());
final String encryptionSecretAlg =
StringUtils.defaultString(getRegisteredServiceJwtSecret(service, TokenConstants.PROPERTY_NAME_TOKEN_SECRET_ENCRYPTION_ALG),
JWEAlgorithm.DIR.getName());
final String encryptionSecretMethod =
StringUtils.defaultString(getRegisteredServiceJwtSecret(service, TokenConstants.PROPERTY_NAME_TOKEN_SECRET_ENCRYPTION_METHOD),
EncryptionMethod.A192CBC_HS384.getName());
if (StringUtils.isNotBlank(signingSecret)) {
Set<Algorithm> sets = new HashSet<>();
sets.addAll(JWSAlgorithm.Family.EC);
sets.addAll(JWSAlgorithm.Family.HMAC_SHA);
sets.addAll(JWSAlgorithm.Family.RSA);
sets.addAll(JWSAlgorithm.Family.SIGNATURE);
final JWSAlgorithm signingAlg = findAlgorithmFamily(sets, signingSecretAlg);
final JwtAuthenticator a = new JwtAuthenticator();
a.setSignatureConfiguration(new SecretSignatureConfiguration(signingSecret, signingAlg));
if (StringUtils.isNotBlank(encryptionSecret)) {
sets = new HashSet<>();
sets.addAll(JWEAlgorithm.Family.AES_GCM_KW);
sets.addAll(JWEAlgorithm.Family.AES_KW);
sets.addAll(JWEAlgorithm.Family.ASYMMETRIC);
sets.addAll(JWEAlgorithm.Family.ECDH_ES);
sets.addAll(JWEAlgorithm.Family.PBES2);
sets.addAll(JWEAlgorithm.Family.RSA);
sets.addAll(JWEAlgorithm.Family.SYMMETRIC);
final JWEAlgorithm encAlg = findAlgorithmFamily(sets, encryptionSecretAlg);
sets = new HashSet<>();
sets.addAll(EncryptionMethod.Family.AES_CBC_HMAC_SHA);
sets.addAll(EncryptionMethod.Family.AES_GCM);
final EncryptionMethod encMethod = findAlgorithmFamily(sets, encryptionSecretMethod);
a.setEncryptionConfiguration(new SecretEncryptionConfiguration(encryptionSecret, encAlg, encMethod));
} else {
LOGGER.warn("JWT authentication is configured to share a single key for both signing/encryption");
}
return a;
}
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:mrluo735,项目名称:cas-5.1.0,代码行数:61,代码来源:TokenAuthenticationHandler.java
示例19: testAuthenticateFailed
import org.pac4j.jwt.credentials.authenticator.JwtAuthenticator; //导入依赖的package包/类
@Test(expected = TechnicalException.class)
public void testAuthenticateFailed() throws HttpAction {
final JwtAuthenticator authenticator = new JwtAuthenticator(new SecretSignatureConfiguration(MAC_SECRET), new SecretEncryptionConfiguration(MAC_SECRET));
final TokenCredentials credentials = new TokenCredentials("fakeToken", CLIENT_NAME);
authenticator.validate(credentials, null);
}
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:7,代码来源:JwtTests.java
示例20: build
import org.pac4j.jwt.credentials.authenticator.JwtAuthenticator; //导入依赖的package包/类
public Config build() {
final OidcClient oidcClient = new OidcClient();
oidcClient.setClientID("343992089165-sp0l1km383i8cbm2j5nn20kbk5dk8hor.apps.googleusercontent.com");
oidcClient.setSecret("uR3D8ej1kIRPbqAFaxIE3HWh");
oidcClient.setDiscoveryURI("https://accounts.google.com/.well-known/openid-configuration");
oidcClient.setUseNonce(true);
//oidcClient.setPreferredJwsAlgorithm(JWSAlgorithm.RS256);
oidcClient.addCustomParam("prompt", "consent");
oidcClient.setAuthorizationGenerator(profile -> profile.addRole("ROLE_ADMIN"));
final SAML2ClientConfiguration cfg = new SAML2ClientConfiguration("resource:samlKeystore.jks",
"pac4j-demo-passwd",
"pac4j-demo-passwd",
"resource:metadata-okta.xml");
cfg.setMaximumAuthenticationLifetime(3600);
cfg.setServiceProviderEntityId("http://localhost:8080/callback?client_name=SAML2Client");
cfg.setServiceProviderMetadataPath("sp-metadata.xml");
final SAML2Client saml2Client = new SAML2Client(cfg);
final FacebookClient facebookClient = new FacebookClient("145278422258960", "be21409ba8f39b5dae2a7de525484da8");
final TwitterClient twitterClient = new TwitterClient("CoxUiYwQOSFDReZYdjigBA", "2kAzunH5Btc4gRSaMr7D7MkyoJ5u1VzbOOzE8rBofs");
// HTTP
final FormClient formClient = new FormClient("http://localhost:8080/loginForm.html", new SimpleTestUsernamePasswordAuthenticator());
final IndirectBasicAuthClient indirectBasicAuthClient = new IndirectBasicAuthClient(new SimpleTestUsernamePasswordAuthenticator());
// CAS
final CasClient casClient = new CasClient("https://casserverpac4j.herokuapp.com/login");
// REST authent with JWT for a token passed in the url as the token parameter
ParameterClient parameterClient = new ParameterClient("token", new JwtAuthenticator(DemoServer.JWT_SALT));
parameterClient.setSupportGetRequest(true);
parameterClient.setSupportPostRequest(false);
// basic auth
final DirectBasicAuthClient directBasicAuthClient = new DirectBasicAuthClient(new SimpleTestUsernamePasswordAuthenticator());
final AnonymousClient anonymousClient = new AnonymousClient();
final Clients clients = new Clients("http://localhost:8080/callback", saml2Client, facebookClient, twitterClient,
formClient, indirectBasicAuthClient, casClient, parameterClient, directBasicAuthClient, oidcClient, anonymousClient);
final Config config = new Config(clients);
config.addAuthorizer("admin", new RequireAnyRoleAuthorizer("ROLE_ADMIN"));
config.addAuthorizer("custom", new CustomAuthorizer());
return config;
}
开发者ID:pac4j,项目名称:undertow-pac4j-demo,代码行数:47,代码来源:DemoConfigFactory.java
注:本文中的org.pac4j.jwt.credentials.authenticator.JwtAuthenticator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论