本文整理汇总了Java中com.auth0.jwt.exceptions.InvalidClaimException类的典型用法代码示例。如果您正苦于以下问题:Java InvalidClaimException类的具体用法?Java InvalidClaimException怎么用?Java InvalidClaimException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InvalidClaimException类属于com.auth0.jwt.exceptions包,在下文中一共展示了InvalidClaimException类的40个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: assertValidClaim
点赞 3
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
private static void assertValidClaim(Claim claim, String claimName, Object value) {
boolean isValid = false;
if (value instanceof String) {
isValid = value.equals(claim.asString());
} else if (value instanceof Integer) {
isValid = value.equals(claim.asInt());
} else if (value instanceof Long) {
isValid = value.equals(claim.asLong());
} else if (value instanceof Boolean) {
isValid = value.equals(claim.asBoolean());
} else if (value instanceof Double) {
isValid = value.equals(claim.asDouble());
} else if (value instanceof Date) {
isValid = value.equals(claim.asDate());
} else if (value instanceof Object[]) {
List<Object> claimArr = Arrays.asList(claim.as(Object[].class));
List<Object> valueArr = Arrays.asList((Object[]) value);
isValid = claimArr.containsAll(valueArr);
}
if (!isValid) {
throw new InvalidClaimException(String.format("The Claim '%s' value doesn't match the required one.", claimName));
}
}
开发者ID:GJWT,
项目名称:javaOIDCMsg,
代码行数:25,
代码来源:VerificationAndAssertion.java
示例2: testConfigurableToIncorrectNumberMultipleKeysForAudience
点赞 3
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void testConfigurableToIncorrectNumberMultipleKeysForAudience() throws Exception {
thrown.expect(InvalidClaimException.class);
thrown.expectMessage("The Claim 'aud' value doesn't contain the required audience.");
Algorithm algorithm = Algorithm.HMAC256("secret");
String[] arr = {"accounts.fake.com", "subject"};
String token = GoogleJwtCreator.build()
.withPicture(GoogleJwtCreatorTest.PICTURE)
.withEmail(GoogleJwtCreatorTest.EMAIL)
.withSubject("subject", "subject2")
.withAudience("audience", "audience2")
.withExp(exp)
.withIat(iat)
.withName(GoogleJwtCreatorTest.NAME)
.withIssuer("issuer", "issuer2")
.sign(algorithm);
GoogleVerification verification = GoogleJWT.require(algorithm);
JWT verifier = verification.createVerifierForGoogle(GoogleJwtCreatorTest.PICTURE, GoogleJwtCreatorTest.EMAIL, asList("issuer", "issuer2"), asList("audience"),
GoogleJwtCreatorTest.NAME, 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
}
开发者ID:GJWT,
项目名称:javaOIDCMsg,
代码行数:23,
代码来源:MainTestSignatures.java
示例3: testConfigurableToIncorrectValueMultipleKeysForAudience
点赞 3
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void testConfigurableToIncorrectValueMultipleKeysForAudience() throws Exception {
thrown.expect(InvalidClaimException.class);
thrown.expectMessage("The Claim 'aud' value doesn't contain the required audience.");
Algorithm algorithm = Algorithm.HMAC256("secret");
String[] arr = {"accounts.fake.com", "subject"};
String token = GoogleJwtCreator.build()
.withPicture(GoogleJwtCreatorTest.PICTURE)
.withEmail(GoogleJwtCreatorTest.EMAIL)
.withSubject("subject", "subject2")
.withAudience("audience", "audience2")
.withExp(exp)
.withIat(iat)
.withName(GoogleJwtCreatorTest.NAME)
.withIssuer("issuer", "issuer2")
.sign(algorithm);
GoogleVerification verification = GoogleJWT.require(algorithm);
JWT verifier = verification.createVerifierForGoogle(GoogleJwtCreatorTest.PICTURE, GoogleJwtCreatorTest.EMAIL, asList("issuer", "issuer2"), asList("audience", "audience3"),
GoogleJwtCreatorTest.NAME, 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
}
开发者ID:GJWT,
项目名称:javaOIDCMsg,
代码行数:23,
代码来源:MainTestSignatures.java
示例4: testScopedJwtCreatorInvalidScope
点赞 3
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void testScopedJwtCreatorInvalidScope() throws Exception {
thrown.expect(InvalidClaimException.class);
thrown.expectMessage("The Claim 'scope' value doesn't match the required one.");
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = ScopedJwtCreator.build()
.withScope("invalid")
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withExp(exp)
.withIat(iat)
.sign(algorithm);
Verification verification = ScopedJWT.require(algorithm);
JWT verifier = verification.createVerifierForScoped("scope", asList("issuer"), asList("audience"), 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
}
开发者ID:GJWT,
项目名称:javaOIDCMsg,
代码行数:18,
代码来源:ScopedJwtCreatorTest.java
示例5: testScopedJwtCreatorInvalidIssuer
点赞 3
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void testScopedJwtCreatorInvalidIssuer() throws Exception {
thrown.expect(InvalidClaimException.class);
thrown.expectMessage("The Claim 'iss' value doesn't match the required one.");
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = ScopedJwtCreator.build()
.withScope("scope")
.withIssuer("invalid")
.withSubject("subject")
.withAudience("audience")
.withExp(exp)
.withIat(iat)
.sign(algorithm);
Verification verification = ScopedJWT.require(algorithm);
JWT verifier = verification.createVerifierForScoped("scope", asList("issuer"), asList("audience"), 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
}
开发者ID:GJWT,
项目名称:javaOIDCMsg,
代码行数:18,
代码来源:ScopedJwtCreatorTest.java
示例6: testScopedJwtCreatorInvalidAudience
点赞 3
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void testScopedJwtCreatorInvalidAudience() throws Exception {
thrown.expect(InvalidClaimException.class);
thrown.expectMessage("The Claim 'aud' value doesn't contain the required audience.");
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = ScopedJwtCreator.build()
.withScope("scope")
.withIssuer("issuer")
.withSubject("subject")
.withAudience("invalid")
.withExp(exp)
.withIat(iat)
.sign(algorithm);
Verification verification = ScopedJWT.require(algorithm);
JWT verifier = verification.createVerifierForScoped("scope", asList("issuer"), asList("audience"), 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
}
开发者ID:GJWT,
项目名称:javaOIDCMsg,
代码行数:18,
代码来源:ScopedJwtCreatorTest.java
示例7: testRiscJwtCreatorInvalidIssuer
点赞 3
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void testRiscJwtCreatorInvalidIssuer() throws Exception {
thrown.expect(InvalidClaimException.class);
thrown.expectMessage("The Claim 'iss' value doesn't match the required one.");
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = RiscJwtCreator.build()
.withJWTId(jti)
.withNbf(nbf)
.withIssuer("invalid")
.withSubject("subject")
.withAudience("audience")
.withExp(exp)
.withIat(iat)
.sign(algorithm);
Verification verification = RiscJWT.require(algorithm);
JWT verifier = verification.createVerifierForRisc(jti, asList("issuer"), asList("audience"), 1, 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
}
开发者ID:GJWT,
项目名称:javaOIDCMsg,
代码行数:19,
代码来源:RiscJwtCreatorTest.java
示例8: testRiscJwtCreatorInvalidAudience
点赞 3
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void testRiscJwtCreatorInvalidAudience() throws Exception {
thrown.expect(InvalidClaimException.class);
thrown.expectMessage("The Claim 'aud' value doesn't contain the required audience.");
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = RiscJwtCreator.build()
.withJWTId(jti)
.withNbf(nbf)
.withIssuer("issuer")
.withSubject("subject")
.withAudience("invalid")
.withExp(exp)
.withIat(iat)
.sign(algorithm);
Verification verification = RiscJWT.require(algorithm);
JWT verifier = verification.createVerifierForRisc(jti, asList("issuer"), asList("audience"), 1, 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
}
开发者ID:GJWT,
项目名称:javaOIDCMsg,
代码行数:19,
代码来源:RiscJwtCreatorTest.java
示例9: testImplicitJwtCreatorInvalidIssuer
点赞 3
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void testImplicitJwtCreatorInvalidIssuer() throws Exception {
thrown.expect(InvalidClaimException.class);
thrown.expectMessage("The Claim 'iss' value doesn't match the required one.");
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = ImplicitJwtCreator.build()
.withIssuer("invalid")
.withSubject("subject")
.withAudience("audience")
.withIat(iat)
.sign(algorithm);
Verification verification = ImplicitJWT.require(algorithm);
JWT verifier = verification.createVerifierForImplicit(asList("issuer"), asList("audience"), 1).build();
DecodedJWT jwt = verifier.decode(token);
Map<String, Claim> claims = jwt.getClaims();
verifyClaims(claims);
}
开发者ID:GJWT,
项目名称:javaOIDCMsg,
代码行数:18,
代码来源:ImplicitJwtCreatorTest.java
示例10: testImplicitJwtCreatorInvalidAudience
点赞 3
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void testImplicitJwtCreatorInvalidAudience() throws Exception {
thrown.expect(InvalidClaimException.class);
thrown.expectMessage("The Claim 'aud' value doesn't contain the required audience.");
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = ImplicitJwtCreator.build()
.withIssuer("issuer")
.withSubject("subject")
.withAudience("invalid")
.withIat(iat)
.sign(algorithm);
Verification verification = ImplicitJWT.require(algorithm);
JWT verifier = verification.createVerifierForImplicit(asList("issuer"), asList("audience"), 1).build();
DecodedJWT jwt = verifier.decode(token);
Map<String, Claim> claims = jwt.getClaims();
verifyClaims(claims);
}
开发者ID:GJWT,
项目名称:javaOIDCMsg,
代码行数:18,
代码来源:ImplicitJwtCreatorTest.java
示例11: testGoogleJwtCreatorInvalidIssuer
点赞 3
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void testGoogleJwtCreatorInvalidIssuer() throws Exception {
thrown.expect(InvalidClaimException.class);
thrown.expectMessage("The Claim 'iss' value doesn't match the required one.");
Algorithm algorithm = Algorithm.none();
String token = GoogleJwtCreator.build()
.withPicture(PICTURE)
.withEmail(EMAIL)
.withIssuer("invalid")
.withSubject("subject")
.withAudience("audience")
.withExp(exp)
.withIat(iat)
.setIsNoneAlgorithmAllowed(true)
.withName(NAME)
.sign(algorithm);
GoogleVerification verification = GoogleJWT.require(algorithm);
JWT verifier = verification.createVerifierForGoogle(PICTURE, EMAIL, asList("issuer"), asList("audience"),
NAME, 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
}
开发者ID:GJWT,
项目名称:javaOIDCMsg,
代码行数:24,
代码来源:GoogleJwtCreatorTest.java
示例12: testGoogleJwtCreatorInvalidAudience
点赞 3
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void testGoogleJwtCreatorInvalidAudience() throws Exception {
thrown.expect(InvalidClaimException.class);
thrown.expectMessage("The Claim 'aud' value doesn't contain the required audience.");
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = GoogleJwtCreator.build()
.withPicture(PICTURE)
.withEmail(EMAIL)
.withIssuer("issuer")
.withSubject("subject")
.withAudience("invalid")
.withExp(exp)
.withIat(iat)
.withName(NAME)
.sign(algorithm);
GoogleVerification verification = GoogleJWT.require(algorithm);
JWT verifier = verification.createVerifierForGoogle(PICTURE, EMAIL, asList("issuer"), asList("audience"),
NAME, 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
}
开发者ID:GJWT,
项目名称:javaOIDCMsg,
代码行数:23,
代码来源:GoogleJwtCreatorTest.java
示例13: testGoogleJwtCreatorInvalidPicture
点赞 3
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void testGoogleJwtCreatorInvalidPicture() throws Exception {
thrown.expect(InvalidClaimException.class);
thrown.expectMessage("The Claim 'picture' value doesn't match the required one.");
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = GoogleJwtCreator.build()
.withPicture("invalid")
.withEmail(EMAIL)
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withExp(exp)
.withIat(iat)
.withName(NAME)
.sign(algorithm);
GoogleVerification verification = GoogleJWT.require(algorithm);
JWT verifier = verification.createVerifierForGoogle(PICTURE, EMAIL, asList("issuer"), asList("audience"),
NAME, 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
}
开发者ID:GJWT,
项目名称:javaOIDCMsg,
代码行数:23,
代码来源:GoogleJwtCreatorTest.java
示例14: testGoogleJwtCreatorInvalidEmail
点赞 3
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void testGoogleJwtCreatorInvalidEmail() throws Exception {
thrown.expect(InvalidClaimException.class);
thrown.expectMessage("The Claim 'email' value doesn't match the required one.");
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = GoogleJwtCreator.build()
.withPicture(PICTURE)
.withEmail("invalid")
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withExp(exp)
.withIat(iat)
.withName(NAME)
.sign(algorithm);
GoogleVerification verification = GoogleJWT.require(algorithm);
JWT verifier = verification.createVerifierForGoogle(PICTURE, EMAIL, asList("issuer"), asList("audience"),
NAME, 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
}
开发者ID:GJWT,
项目名称:javaOIDCMsg,
代码行数:23,
代码来源:GoogleJwtCreatorTest.java
示例15: testGoogleJwtCreatorInvalidName
点赞 3
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void testGoogleJwtCreatorInvalidName() throws Exception {
thrown.expect(InvalidClaimException.class);
thrown.expectMessage("The Claim 'name' value doesn't match the required one.");
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = GoogleJwtCreator.build()
.withPicture(PICTURE)
.withEmail(EMAIL)
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withExp(exp)
.withIat(iat)
.withName("invalid")
.sign(algorithm);
GoogleVerification verification = GoogleJWT.require(algorithm);
JWT verifier = verification.createVerifierForGoogle(PICTURE, EMAIL, asList("issuer"), asList("audience"),
NAME, 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
}
开发者ID:GJWT,
项目名称:javaOIDCMsg,
代码行数:23,
代码来源:GoogleJwtCreatorTest.java
示例16: testAccessJwtCreatorInvalidIssuer
点赞 3
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void testAccessJwtCreatorInvalidIssuer() throws Exception {
thrown.expect(InvalidClaimException.class);
thrown.expectMessage("The Claim 'iss' value doesn't match the required one.");
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = AccessJwtCreator.build()
.withIssuer("invalid")
.withSubject("subject")
.withAudience("audience")
.withExp(exp)
.withIat(iat)
.sign(algorithm);
Verification verification = AccessJWT.require(algorithm);
JWT verifier = verification.createVerifierForAccess(asList("issuer"), asList("audience"), 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
}
开发者ID:GJWT,
项目名称:javaOIDCMsg,
代码行数:17,
代码来源:AccessJwtCreatorTest.java
示例17: testAccessJwtCreatorInvalidAudience
点赞 3
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void testAccessJwtCreatorInvalidAudience() throws Exception {
thrown.expect(InvalidClaimException.class);
thrown.expectMessage("The Claim 'aud' value doesn't contain the required audience.");
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = AccessJwtCreator.build()
.withIssuer("issuer")
.withSubject("subject")
.withAudience("invalid")
.withExp(exp)
.withIat(iat)
.sign(algorithm);
Verification verification = AccessJWT.require(algorithm);
JWT verifier = verification.createVerifierForAccess(asList("issuer"), asList("audience"), 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
}
开发者ID:GJWT,
项目名称:javaOIDCMsg,
代码行数:17,
代码来源:AccessJwtCreatorTest.java
示例18: testExtendedJwtCreatorInvalidIssuer
点赞 3
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void testExtendedJwtCreatorInvalidIssuer() throws Exception {
thrown.expect(InvalidClaimException.class);
thrown.expectMessage("The Claim 'iss' value doesn't match the required one.");
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = ExtendedJwtCreator.build()
.withNbf(nbf) //this must be called first since ExtendedJwtCreator.build() returns an instance of ExtendedJwtCreator
.withPicture(PICTURE)
.withEmail(EMAIL)
.withIssuer("invalid")
.withSubject("subject")
.withAudience("audience")
.withExp(exp)
.withIat(iat)
.withName(NAME)
.sign(algorithm);
GoogleVerification verification = ExtendedJWT.require(algorithm);
JWT verifier = verification.createVerifierForExtended(PICTURE, EMAIL, asList("issuer"), asList("audience"),
NAME, 1, 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
}
开发者ID:GJWT,
项目名称:javaOIDCMsg,
代码行数:22,
代码来源:ExtendedJwtCreatorTest.java
示例19: testExtendedJwtCreatorInvalidPicture
点赞 3
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void testExtendedJwtCreatorInvalidPicture() throws Exception {
thrown.expect(InvalidClaimException.class);
thrown.expectMessage("The Claim 'picture' value doesn't match the required one.");
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = ExtendedJwtCreator.build()
.withNbf(nbf) //this must be called first since ExtendedJwtCreator.build() returns an instance of ExtendedJwtCreator
.withPicture("invalid")
.withEmail(EMAIL)
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withExp(exp)
.withIat(iat)
.withName(NAME)
.sign(algorithm);
GoogleVerification verification = ExtendedJWT.require(algorithm);
JWT verifier = verification.createVerifierForExtended(PICTURE, EMAIL, asList("issuer"), asList("audience"),
NAME, 1, 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
}
开发者ID:GJWT,
项目名称:javaOIDCMsg,
代码行数:22,
代码来源:ExtendedJwtCreatorTest.java
示例20: testExtendedJwtCreatorInvalidEmail
点赞 3
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void testExtendedJwtCreatorInvalidEmail() throws Exception {
thrown.expect(InvalidClaimException.class);
thrown.expectMessage("The Claim 'email' value doesn't match the required one.");
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = ExtendedJwtCreator.build()
.withNbf(nbf) //this must be called first since ExtendedJwtCreator.build() returns an instance of ExtendedJwtCreator
.withPicture(PICTURE)
.withEmail("invalid")
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withExp(exp)
.withIat(iat)
.withName(NAME)
.sign(algorithm);
GoogleVerification verification = ExtendedJWT.require(algorithm);
JWT verifier = verification.createVerifierForExtended(PICTURE, EMAIL, asList("issuer"), asList("audience"),
NAME, 1, 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
Map<String, Claim> claims = jwt.getClaims();
verifyClaims(claims, exp);
}
开发者ID:GJWT,
项目名称:javaOIDCMsg,
代码行数:24,
代码来源:ExtendedJwtCreatorTest.java
示例21: testExtendedJwtCreatorInvalidAudience
点赞 3
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void testExtendedJwtCreatorInvalidAudience() throws Exception {
thrown.expect(InvalidClaimException.class);
thrown.expectMessage("The Claim 'aud' value doesn't contain the required audience.");
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = ExtendedJwtCreator.build()
.withNbf(nbf) //this must be called first since ExtendedJwtCreator.build() returns an instance of ExtendedJwtCreator
.withPicture(PICTURE)
.withEmail(EMAIL)
.withIssuer("issuer")
.withSubject("subject")
.withAudience("invalid")
.withExp(exp)
.withIat(iat)
.withName(NAME)
.sign(algorithm);
GoogleVerification verification = ExtendedJWT.require(algorithm);
JWT verifier = verification.createVerifierForExtended(PICTURE, EMAIL, asList("issuer"), asList("audience"),
NAME, 1, 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
Map<String, Claim> claims = jwt.getClaims();
verifyClaims(claims, exp);
}
开发者ID:GJWT,
项目名称:javaOIDCMsg,
代码行数:24,
代码来源:ExtendedJwtCreatorTest.java
示例22: testExtendedJwtCreatorInvalidName
点赞 3
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void testExtendedJwtCreatorInvalidName() throws Exception {
thrown.expect(InvalidClaimException.class);
thrown.expectMessage("The Claim 'name' value doesn't match the required one.");
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = ExtendedJwtCreator.build()
.withNbf(nbf) //this must be called first since ExtendedJwtCreator.build() returns an instance of ExtendedJwtCreator
.withPicture(PICTURE)
.withEmail(EMAIL)
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withExp(exp)
.withIat(iat)
.withName("invalid")
.sign(algorithm);
GoogleVerification verification = ExtendedJWT.require(algorithm);
JWT verifier = verification.createVerifierForExtended(PICTURE, EMAIL, asList("issuer"), asList("audience"),
NAME, 1, 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
Map<String, Claim> claims = jwt.getClaims();
verifyClaims(claims, exp);
}
开发者ID:GJWT,
项目名称:javaOIDCMsg,
代码行数:24,
代码来源:ExtendedJwtCreatorTest.java
示例23: shouldFailToAuthenticateUsingJWKIfMissingAudienceClaim
点赞 3
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void shouldFailToAuthenticateUsingJWKIfMissingAudienceClaim() throws Exception {
Jwk jwk = mock(Jwk.class);
JwkProvider jwkProvider = mock(JwkProvider.class);
KeyPair keyPair = RSAKeyPair();
when(jwkProvider.get(eq("key-id"))).thenReturn(jwk);
when(jwk.getPublicKey()).thenReturn(keyPair.getPublic());
JwtAuthenticationProvider provider = new JwtAuthenticationProvider(jwkProvider, "issuer", "audience");
Map<String, Object> keyIdHeader = Collections.singletonMap("kid", (Object) "key-id");
String token = JWT.create()
.withIssuer("issuer")
.withHeader(keyIdHeader)
.sign(Algorithm.RSA256((RSAKey) keyPair.getPrivate()));
Authentication authentication = PreAuthenticatedAuthenticationJsonWebToken.usingToken(token);
exception.expect(BadCredentialsException.class);
exception.expectMessage("Not a valid token");
exception.expectCause(Matchers.<Throwable>instanceOf(InvalidClaimException.class));
provider.authenticate(authentication);
}
开发者ID:auth0,
项目名称:auth0-spring-security-api,
代码行数:23,
代码来源:JwtAuthenticationProviderTest.java
示例24: shouldFailToAuthenticateUsingJWKIfMissingIssuerClaim
点赞 3
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void shouldFailToAuthenticateUsingJWKIfMissingIssuerClaim() throws Exception {
Jwk jwk = mock(Jwk.class);
JwkProvider jwkProvider = mock(JwkProvider.class);
KeyPair keyPair = RSAKeyPair();
when(jwkProvider.get(eq("key-id"))).thenReturn(jwk);
when(jwk.getPublicKey()).thenReturn(keyPair.getPublic());
JwtAuthenticationProvider provider = new JwtAuthenticationProvider(jwkProvider, "issuer", "audience");
Map<String, Object> keyIdHeader = Collections.singletonMap("kid", (Object) "key-id");
String token = JWT.create()
.withAudience("audience")
.withHeader(keyIdHeader)
.sign(Algorithm.RSA256((RSAKey) keyPair.getPrivate()));
Authentication authentication = PreAuthenticatedAuthenticationJsonWebToken.usingToken(token);
exception.expect(BadCredentialsException.class);
exception.expectMessage("Not a valid token");
exception.expectCause(Matchers.<Throwable>instanceOf(InvalidClaimException.class));
provider.authenticate(authentication);
}
开发者ID:auth0,
项目名称:auth0-spring-security-api,
代码行数:23,
代码来源:JwtAuthenticationProviderTest.java
示例25: shouldFailToAuthenticateUsingJWKIfIssuerClaimDoesNotMatch
点赞 3
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void shouldFailToAuthenticateUsingJWKIfIssuerClaimDoesNotMatch() throws Exception {
Jwk jwk = mock(Jwk.class);
JwkProvider jwkProvider = mock(JwkProvider.class);
KeyPair keyPair = RSAKeyPair();
when(jwkProvider.get(eq("key-id"))).thenReturn(jwk);
when(jwk.getPublicKey()).thenReturn(keyPair.getPublic());
JwtAuthenticationProvider provider = new JwtAuthenticationProvider(jwkProvider, "issuer", "audience");
Map<String, Object> keyIdHeader = Collections.singletonMap("kid", (Object) "key-id");
String token = JWT.create()
.withAudience("audience")
.withIssuer("some")
.withHeader(keyIdHeader)
.sign(Algorithm.RSA256((RSAKey) keyPair.getPrivate()));
Authentication authentication = PreAuthenticatedAuthenticationJsonWebToken.usingToken(token);
exception.expect(BadCredentialsException.class);
exception.expectMessage("Not a valid token");
exception.expectCause(Matchers.<Throwable>instanceOf(InvalidClaimException.class));
provider.authenticate(authentication);
}
开发者ID:auth0,
项目名称:auth0-spring-security-api,
代码行数:24,
代码来源:JwtAuthenticationProviderTest.java
示例26: shouldFailToAuthenticateUsingJWKIfAudienceClaimDoesNotMatch
点赞 3
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void shouldFailToAuthenticateUsingJWKIfAudienceClaimDoesNotMatch() throws Exception {
Jwk jwk = mock(Jwk.class);
JwkProvider jwkProvider = mock(JwkProvider.class);
KeyPair keyPair = RSAKeyPair();
when(jwkProvider.get(eq("key-id"))).thenReturn(jwk);
when(jwk.getPublicKey()).thenReturn(keyPair.getPublic());
JwtAuthenticationProvider provider = new JwtAuthenticationProvider(jwkProvider, "issuer", "audience");
Map<String, Object> keyIdHeader = Collections.singletonMap("kid", (Object) "key-id");
String token = JWT.create()
.withAudience("some")
.withIssuer("issuer")
.withHeader(keyIdHeader)
.sign(Algorithm.RSA256((RSAKey) keyPair.getPrivate()));
Authentication authentication = PreAuthenticatedAuthenticationJsonWebToken.usingToken(token);
exception.expect(BadCredentialsException.class);
exception.expectMessage("Not a valid token");
exception.expectCause(Matchers.<Throwable>instanceOf(InvalidClaimException.class));
provider.authenticate(authentication);
}
开发者ID:auth0,
项目名称:auth0-spring-security-api,
代码行数:24,
代码来源:JwtAuthenticationProviderTest.java
示例27: verifyClaims
点赞 2
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
public static void verifyClaims(Clock clock, DecodedJWT jwt, Map<String, Object> claims) throws TokenExpiredException, InvalidClaimException {
for (Map.Entry<String, Object> entry : claims.entrySet()) {
switch (entry.getKey()) {
case PublicClaims.AUDIENCE:
//noinspection unchecked
VerificationAndAssertion.assertValidAudienceClaim(jwt.getAudience(), (List<String>) entry.getValue());
break;
case PublicClaims.EXPIRES_AT:
assertValidDateClaim(clock, jwt.getExpiresAt(), (Long) entry.getValue(), true);
break;
case PublicClaims.ISSUED_AT:
assertValidDateClaim(clock, jwt.getIssuedAt(), (Long) entry.getValue(), false);
break;
case PublicClaims.NOT_BEFORE:
assertValidDateClaim(clock, jwt.getNotBefore(), (Long) entry.getValue(), false);
break;
case PublicClaims.ISSUER:
VerificationAndAssertion.assertValidIssuerClaim(jwt.getIssuer(), (List<String>) entry.getValue());
break;
case PublicClaims.JWT_ID:
VerificationAndAssertion.assertValidStringClaim(entry.getKey(), jwt.getId(), (String) entry.getValue());
break;
default:
VerificationAndAssertion.assertValidClaim(jwt.getClaim(entry.getKey()), entry.getKey(), entry.getValue());
break;
}
}
}
开发者ID:GJWT,
项目名称:javaOIDCMsg,
代码行数:29,
代码来源:VerificationAndAssertion.java
示例28: testFbJwtCreatorInvalidUserId
点赞 2
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void testFbJwtCreatorInvalidUserId() throws Exception {
thrown.expect(InvalidClaimException.class);
thrown.expectMessage("The Claim 'userId' value doesn't match the required one.");
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = FbJwtCreator.build()
.withExp(exp)
.withIat(iat)
.withUserId("invalid")
.withAppId(APP_ID)
.sign(algorithm);
Verification verification = FbJWT.require(algorithm);
JWT verifier = verification.createVerifierForFb(USER_ID, APP_ID).build();
DecodedJWT jwt = verifier.decode(token);
}
开发者ID:GJWT,
项目名称:javaOIDCMsg,
代码行数:16,
代码来源:FbJwtCreatorTest.java
示例29: testFbJwtCreatorInvalidAppId
点赞 2
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void testFbJwtCreatorInvalidAppId() throws Exception {
thrown.expect(InvalidClaimException.class);
thrown.expectMessage("The Claim 'appId' value doesn't match the required one.");
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = FbJwtCreator.build()
.withExp(exp)
.withIat(iat)
.withUserId(USER_ID)
.withAppId("invalid")
.sign(algorithm);
Verification verification = FbJWT.require(algorithm);
JWT verifier = verification.createVerifierForFb(USER_ID, APP_ID).build();
DecodedJWT jwt = verifier.decode(token);
}
开发者ID:GJWT,
项目名称:javaOIDCMsg,
代码行数:16,
代码来源:FbJwtCreatorTest.java
示例30: testGoogleJwtCreatorTokenCantBeUsedBefore
点赞 2
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void testGoogleJwtCreatorTokenCantBeUsedBefore() throws Exception {
thrown.expect(InvalidClaimException.class);
thrown.expectMessage("The Token can't be used before Mon Oct 29 00:00:00 PDT 2018.");
String myDate = "2018/10/29";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
Date date = sdf.parse(myDate);
long expLong = date.getTime();
Date iatDate = new Date(expLong);
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = GoogleJwtCreator.build()
.withPicture(PICTURE)
.withEmail(EMAIL)
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withExp(exp)
.withIat(iatDate)
.withName(NAME)
.sign(algorithm);
GoogleVerification verification = GoogleJWT.require(algorithm);
JWT verifier = verification.createVerifierForGoogle(PICTURE, EMAIL, asList("issuer"), asList("audience"),
NAME, 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
}
开发者ID:GJWT,
项目名称:javaOIDCMsg,
代码行数:28,
代码来源:GoogleJwtCreatorTest.java
示例31: shouldFailToAuthenticateUsingSecretIfMissingAudienceClaim
点赞 2
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void shouldFailToAuthenticateUsingSecretIfMissingAudienceClaim() throws Exception {
JwtAuthenticationProvider provider = new JwtAuthenticationProvider("secret".getBytes(), "issuer", "audience");
String token = JWT.create()
.withIssuer("issuer")
.sign(Algorithm.HMAC256("secret"));
Authentication authentication = PreAuthenticatedAuthenticationJsonWebToken.usingToken(token);
exception.expect(BadCredentialsException.class);
exception.expectMessage("Not a valid token");
exception.expectCause(Matchers.<Throwable>instanceOf(InvalidClaimException.class));
provider.authenticate(authentication);
}
开发者ID:auth0,
项目名称:auth0-spring-security-api,
代码行数:14,
代码来源:JwtAuthenticationProviderTest.java
示例32: shouldFailToAuthenticateUsingSecretIfMissingIssuerClaim
点赞 2
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void shouldFailToAuthenticateUsingSecretIfMissingIssuerClaim() throws Exception {
JwtAuthenticationProvider provider = new JwtAuthenticationProvider("secret".getBytes(), "issuer", "audience");
String token = JWT.create()
.withAudience("audience")
.sign(Algorithm.HMAC256("secret"));
Authentication authentication = PreAuthenticatedAuthenticationJsonWebToken.usingToken(token);
exception.expect(BadCredentialsException.class);
exception.expectMessage("Not a valid token");
exception.expectCause(Matchers.<Throwable>instanceOf(InvalidClaimException.class));
provider.authenticate(authentication);
}
开发者ID:auth0,
项目名称:auth0-spring-security-api,
代码行数:14,
代码来源:JwtAuthenticationProviderTest.java
示例33: shouldFailToAuthenticateUsingSecretIfIssuerClaimDoesNotMatch
点赞 2
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void shouldFailToAuthenticateUsingSecretIfIssuerClaimDoesNotMatch() throws Exception {
JwtAuthenticationProvider provider = new JwtAuthenticationProvider("secret".getBytes(), "issuer", "audience");
String token = JWT.create()
.withAudience("audience")
.withIssuer("some")
.sign(Algorithm.HMAC256("secret"));
Authentication authentication = PreAuthenticatedAuthenticationJsonWebToken.usingToken(token);
exception.expect(BadCredentialsException.class);
exception.expectMessage("Not a valid token");
exception.expectCause(Matchers.<Throwable>instanceOf(InvalidClaimException.class));
provider.authenticate(authentication);
}
开发者ID:auth0,
项目名称:auth0-spring-security-api,
代码行数:15,
代码来源:JwtAuthenticationProviderTest.java
示例34: shouldFailToAuthenticateUsingSecretIfAudienceClaimDoesNotMatch
点赞 2
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void shouldFailToAuthenticateUsingSecretIfAudienceClaimDoesNotMatch() throws Exception {
JwtAuthenticationProvider provider = new JwtAuthenticationProvider("secret".getBytes(), "issuer", "audience");
String token = JWT.create()
.withAudience("some")
.withIssuer("issuer")
.sign(Algorithm.HMAC256("secret"));
Authentication authentication = PreAuthenticatedAuthenticationJsonWebToken.usingToken(token);
exception.expect(BadCredentialsException.class);
exception.expectMessage("Not a valid token");
exception.expectCause(Matchers.<Throwable>instanceOf(InvalidClaimException.class));
provider.authenticate(authentication);
}
开发者ID:auth0,
项目名称:auth0-spring-security-api,
代码行数:15,
代码来源:JwtAuthenticationProviderTest.java
示例35: shouldThrowOnInvalidIssuer
点赞 2
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void shouldThrowOnInvalidIssuer() throws Exception {
exception.expect(InvalidClaimException.class);
exception.expectMessage("The Claim 'iss' value doesn't match the required one.");
String token = "eyJhbGciOiJIUzI1NiIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.mZ0m_N1J4PgeqWmi903JuUoDRZDBPB7HwkS4nVyWH1M";
JWTVerifier.init(Algorithm.HMAC256("secret"))
.withIssuer("invalid")
.build()
.verify(token);
}
开发者ID:auth0,
项目名称:java-jwt,
代码行数:11,
代码来源:JWTVerifierTest.java
示例36: shouldThrowOnInvalidSubject
点赞 2
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void shouldThrowOnInvalidSubject() throws Exception {
exception.expect(InvalidClaimException.class);
exception.expectMessage("The Claim 'sub' value doesn't match the required one.");
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.Rq8IxqeX7eA6GgYxlcHdPFVRNFFZc5rEI3MQTZZbK3I";
JWTVerifier.init(Algorithm.HMAC256("secret"))
.withSubject("invalid")
.build()
.verify(token);
}
开发者ID:auth0,
项目名称:java-jwt,
代码行数:11,
代码来源:JWTVerifierTest.java
示例37: shouldThrowOnInvalidAudience
点赞 2
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void shouldThrowOnInvalidAudience() throws Exception {
exception.expect(InvalidClaimException.class);
exception.expectMessage("The Claim 'aud' value doesn't contain the required audience.");
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.Rq8IxqeX7eA6GgYxlcHdPFVRNFFZc5rEI3MQTZZbK3I";
JWTVerifier.init(Algorithm.HMAC256("secret"))
.withAudience("nope")
.build()
.verify(token);
}
开发者ID:auth0,
项目名称:java-jwt,
代码行数:11,
代码来源:JWTVerifierTest.java
示例38: shouldThrowOnInvalidCustomClaimValueOfTypeString
点赞 2
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void shouldThrowOnInvalidCustomClaimValueOfTypeString() throws Exception {
exception.expect(InvalidClaimException.class);
exception.expectMessage("The Claim 'name' value doesn't match the required one.");
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjpbInNvbWV0aGluZyJdfQ.3ENLez6tU_fG0SVFrGmISltZPiXLSHaz_dyn-XFTEGQ";
JWTVerifier.init(Algorithm.HMAC256("secret"))
.withClaim("name", "value")
.build()
.verify(token);
}
开发者ID:auth0,
项目名称:java-jwt,
代码行数:11,
代码来源:JWTVerifierTest.java
示例39: shouldThrowOnInvalidCustomClaimValueOfTypeInteger
点赞 2
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void shouldThrowOnInvalidCustomClaimValueOfTypeInteger() throws Exception {
exception.expect(InvalidClaimException.class);
exception.expectMessage("The Claim 'name' value doesn't match the required one.");
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjpbInNvbWV0aGluZyJdfQ.3ENLez6tU_fG0SVFrGmISltZPiXLSHaz_dyn-XFTEGQ";
JWTVerifier.init(Algorithm.HMAC256("secret"))
.withClaim("name", 123)
.build()
.verify(token);
}
开发者ID:auth0,
项目名称:java-jwt,
代码行数:11,
代码来源:JWTVerifierTest.java
示例40: shouldThrowOnInvalidCustomClaimValueOfTypeDouble
点赞 2
import com.auth0.jwt.exceptions.InvalidClaimException; //导入依赖的package包/类
@Test
public void shouldThrowOnInvalidCustomClaimValueOfTypeDouble() throws Exception {
exception.expect(InvalidClaimException.class);
exception.expectMessage("The Claim 'name' value doesn't match the required one.");
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjpbInNvbWV0aGluZyJdfQ.3ENLez6tU_fG0SVFrGmISltZPiXLSHaz_dyn-XFTEGQ";
JWTVerifier.init(Algorithm.HMAC256("secret"))
.withClaim("name", 23.45)
.build()
.verify(token);
}
开发者ID:auth0,
项目名称:java-jwt,
代码行数:11,
代码来源:JWTVerifierTest.java