本文整理汇总了Java中io.jsonwebtoken.JwtParser类的典型用法代码示例。如果您正苦于以下问题:Java JwtParser类的具体用法?Java JwtParser怎么用?Java JwtParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JwtParser类属于io.jsonwebtoken包,在下文中一共展示了JwtParser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: apply
import io.jsonwebtoken.JwtParser; //导入依赖的package包/类
@SuppressWarnings("Duplicates")
@Override
public Claims apply(String headerValue) {
JwtParser parser = Jwts.parser();
if (signingKeyBytes != null) {
parser.setSigningKey(signingKeyBytes);
} else if (signingKey != null) {
parser.setSigningKey(signingKey);
} else if (signingKeyResolver != null) {
parser.setSigningKeyResolver(signingKeyResolver);
}
if (this.allowedClockSkewSeconds != null) {
parser.setAllowedClockSkewSeconds(this.allowedClockSkewSeconds);
}
return parser.parseClaimsJws(headerValue).getBody();
}
开发者ID:juiser,项目名称:juiser,代码行数:20,代码来源:JwsClaimsExtractor.java
示例2: testLoginGood
import io.jsonwebtoken.JwtParser; //导入依赖的package包/类
@Test
public void testLoginGood() {
final CredentialsEntity entity = getCredentialsEntity();
when(credentialsRepository.findByUsername(eq(entity.getUsername()))).thenReturn(entity);
when(passwordEncoder.matches(eq(entity.getPassword()), eq(entity.getPassword()))).thenReturn(true);
final Authorization authorization = authenticationService.login(entity.getUsername(), entity.getPassword());
assertThat(authorization.getId()).isEqualTo(entity.getId());
assertThat(authorization.getToken()).isNotNull();
final JwtParser parser = Jwts.parser().setSigningKey(apiKey);
final Claims body = parser.parseClaimsJws(authorization.getToken()).getBody();
assertThat(body.getSubject()).isNotNull().isEqualTo(entity.getId());
assertThat(body.getIssuer()).isNotNull().isEqualTo(AuthenticationService.class.getName());
assertThat(body.getIssuedAt()).isNotNull();
assertThat(body.getNotBefore()).isNotNull();
assertThat(body.getExpiration()).isNotNull();
assertThat(body.get("roles")).isNotNull();
assertThat(body.get("roles").toString().trim()).isEqualTo(entity.getRoles().toString().trim());
}
开发者ID:nus-ncl,项目名称:services-in-one,代码行数:22,代码来源:AuthenticationServiceTest.java
示例3: Can_fail_parse_a_jwt_token
import io.jsonwebtoken.JwtParser; //导入依赖的package包/类
@Test
public void Can_fail_parse_a_jwt_token() throws JwtInvalidTokenException {
final String token = someString();
final JwtParser parser = mock(JwtParser.class);
final JwtParser secretParser = mock(JwtParser.class);
final JwtException exception = new JwtException(someString());
// Given
given(parserFactory.create()).willReturn(parser);
given(parser.setSigningKey(publicKey)).willReturn(secretParser);
given(secretParser.parseClaimsJws(token)).willThrow(exception);
expectedException.expect(JwtInvalidTokenException.class);
expectedException.expectCause(is(exception));
// When
decryptor.decrypt(token, Object.class);
}
开发者ID:shiver-me-timbers,项目名称:smt-spring-security-parent,代码行数:21,代码来源:JJwtDecryptorTest.java
示例4: Can_fail_to_parse_an_empty_jwt_token
import io.jsonwebtoken.JwtParser; //导入依赖的package包/类
@Test
public void Can_fail_to_parse_an_empty_jwt_token() throws JwtInvalidTokenException {
final JwtParser parser = mock(JwtParser.class);
final JwtParser secretParser = mock(JwtParser.class);
final IllegalArgumentException exception = new IllegalArgumentException();
// Given
given(parserFactory.create()).willReturn(parser);
given(parser.setSigningKey(publicKey)).willReturn(secretParser);
given(secretParser.parseClaimsJws("")).willThrow(exception);
expectedException.expect(JwtInvalidTokenException.class);
expectedException.expectCause(is(exception));
// When
decryptor.decrypt("", Object.class);
}
开发者ID:shiver-me-timbers,项目名称:smt-spring-security-parent,代码行数:19,代码来源:JJwtDecryptorTest.java
示例5: verifyParser
import io.jsonwebtoken.JwtParser; //导入依赖的package包/类
/**
* <p>
* 验证签名并解析
* </p>
*/
public static JwtParser verifyParser() {
try {
SSOConfig config = SSOConfig.getInstance();
SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.forName(config.getSignAlgorithm());
if (SSOConstants.SIGN_RSA.equals(signatureAlgorithm.getFamilyName())) {
ClassPathResource resource = new ClassPathResource(config.getRsaCertstore());
String publicKey = new String(FileCopyUtils.copyToByteArray(resource.getInputStream()));
// RSA 签名验证
return Jwts.parser().setSigningKey(RsaKeyHelper.parsePublicKey(publicKey));
}
// 普通签名验证
return Jwts.parser().setSigningKey(config.getSignkey());
} catch (Exception e) {
throw new KissoException("verifyParser error.", e);
}
}
开发者ID:baomidou,项目名称:kisso,代码行数:22,代码来源:JwtHelper.java
示例6: verifyJwt
import io.jsonwebtoken.JwtParser; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public boolean verifyJwt(String jwt) {
boolean verified = false;
try {
Assert.hasText(jwt, "JWT can't be null or empty!!");
JwtParser jwtParser = Jwts.parser().requireIssuer(this.jwtConfig.issuer());
this.setSigningKey(jwtParser);
Jws<Claims> claimsJws = jwtParser.parseClaimsJws(jwt);
verified = !this.jwtConfig.validateClaims() ||
this.claimsValidator != null && this.claimsValidator.validate(claimsJws.getBody());
} catch (RuntimeException ex) {
// For reducing noise in the logs, set this config to false.
if (this.jwtConfig.printJwtExceptionTrace()) {
LOGGER.error(ex.getMessage(), ex);
} else {
LOGGER.error(ex.getMessage());
}
}
return verified;
}
开发者ID:AdeptJ,项目名称:adeptj-modules,代码行数:24,代码来源:JwtServiceImpl.java
示例7: filter
import io.jsonwebtoken.JwtParser; //导入依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
try {
String authorizationHeader = requestContext.getHeaderString(HttpHeaders.AUTHORIZATION);
String token = authorizationHeader.substring("Bearer".length()).trim();
final Key key = KeyGenerator.getKey(deskDroidService.getApplicationContext());
final JwtParser jwtParser = Jwts.parser().setSigningKey(key);
jwtParser.parseClaimsJws(token);
} catch (Exception e) {
requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED).build());
}
}
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:13,代码来源:SecureFilter.java
示例8: testJwtParser
import io.jsonwebtoken.JwtParser; //导入依赖的package包/类
@Test
public void testJwtParser() throws Exception {
final Key key = mock(Key.class);
final JwtParser jwtParser = configuration.jwtParser(key);
assertThat(jwtParser).isNotNull();
}
开发者ID:nus-ncl,项目名称:services-in-one,代码行数:9,代码来源:JwtAutoConfigurationTest.java
示例9: Can_parse_a_jwt_token
import io.jsonwebtoken.JwtParser; //导入依赖的package包/类
@Test
public void Can_parse_a_jwt_token() throws IOException {
final String token = someString();
final Class<Object> type = Object.class;
final JwtParser parser = mock(JwtParser.class);
final JwtParser secretParser = mock(JwtParser.class);
@SuppressWarnings("unchecked")
final Jws<Claims> jws = mock(Jws.class);
final Claims claims = mock(Claims.class);
final Map map = mock(Map.class);
final Object expected = new Object();
// Given
given(parserFactory.create()).willReturn(parser);
given(parser.setSigningKey(publicKey)).willReturn(secretParser);
given(secretParser.parseClaimsJws(token)).willReturn(jws);
given(jws.getBody()).willReturn(claims);
given(claims.get(PRINCIPAL, Map.class)).willReturn(map);
given(objectMapper.convertValue(map, type)).willReturn(expected);
// When
final Object actual = decryptor.decrypt(token, type);
// Then
assertThat(actual, is(expected));
}
开发者ID:shiver-me-timbers,项目名称:smt-spring-security-parent,代码行数:30,代码来源:JJwtDecryptorTest.java
示例10: Can_create_a_jwt_parser
import io.jsonwebtoken.JwtParser; //导入依赖的package包/类
@Test
public void Can_create_a_jwt_parser() {
// When
final JwtParser actual = new JJwtParserFactory().create();
// Then
assertThat(actual, not(nullValue()));
}
开发者ID:shiver-me-timbers,项目名称:smt-spring-security-parent,代码行数:10,代码来源:JJwtParserFactoryTest.java
示例11: test
import io.jsonwebtoken.JwtParser; //导入依赖的package包/类
@Test
public void test() throws Exception {
ClassPathResource resource = new ClassPathResource("jwt.jks");
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
keystore.load(resource.getInputStream(), "letkisso".toCharArray());
Key key = keystore.getKey("jwtkey", "keypassword".toCharArray());
Map<String, Object> claims = new HashMap<>();
claims.put("user", "cope");
String jwtToken = Jwts.builder()
.setClaims(claims)
.setIssuedAt(new Date())
.signWith(SignatureAlgorithm.RS512, key)
.compact();
System.out.println(jwtToken);
ClassPathResource resourcePk = new ClassPathResource("public.cert");
String publicKey;
try {
publicKey = new String(FileCopyUtils.copyToByteArray(resourcePk.getInputStream()));
} catch (IOException e) {
throw new RuntimeException(e);
}
JwtParser jwtParser = Jwts.parser().setSigningKey(RsaKeyHelper.parsePublicKey(publicKey));
Claims claimsPk = jwtParser.parseClaimsJws(jwtToken).getBody();
Assert.assertNotNull(claimsPk);
Assert.assertEquals(claimsPk.get("user"), "cope");
}
开发者ID:baomidou,项目名称:kisso,代码行数:28,代码来源:TestRsakey.java
示例12: setSigningKey
import io.jsonwebtoken.JwtParser; //导入依赖的package包/类
private void setSigningKey(JwtParser jwtParser) {
if (this.rsaPrivateKey == null) {
jwtParser.setSigningKey(this.hmacSecretKey);
} else {
jwtParser.setSigningKey(this.rsaPrivateKey);
}
}
开发者ID:AdeptJ,项目名称:adeptj-modules,代码行数:8,代码来源:JwtServiceImpl.java
示例13: validateJwt
import io.jsonwebtoken.JwtParser; //导入依赖的package包/类
private Map<String, Object> validateJwt(String token, ApiRequest request, JWTPolicyBean config)
throws ExpiredJwtException, PrematureJwtException, MalformedJwtException, SignatureException, InvalidClaimException {
JwtParser parser = Jwts.parser()
.setSigningKey(config.getSigningKey())
.setAllowedClockSkewSeconds(config.getAllowedClockSkew());
// Set all claims
config.getRequiredClaims().stream() // TODO add type variable to allow dates, etc
.forEach(requiredClaim -> parser.require(requiredClaim.getClaimName(), requiredClaim.getClaimValue()));
return parser.parse(token, new ConfigCheckingJwtHandler(config));
}
开发者ID:apiman,项目名称:apiman-plugins,代码行数:13,代码来源:JWTPolicy.java
示例14: require
import io.jsonwebtoken.JwtParser; //导入依赖的package包/类
@Override
public JwtParser require(String claimName, Object value) {
Assert.hasText(claimName, "claim name cannot be null or empty.");
Assert.notNull(value, "The value cannot be null for claim name: " + claimName);
expectedClaims.put(claimName, value);
return this;
}
开发者ID:jwtk,项目名称:jjwt,代码行数:8,代码来源:DefaultJwtParser.java
示例15: jwtParser
import io.jsonwebtoken.JwtParser; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(JwtParser.class)
public JwtParser jwtParser(@NotNull final Key apiKey) {
return Jwts.parser().setSigningKey(apiKey);
}
开发者ID:nus-ncl,项目名称:services-in-one,代码行数:6,代码来源:JwtAutoConfiguration.java
示例16: JwtAuthenticationProvider
import io.jsonwebtoken.JwtParser; //导入依赖的package包/类
JwtAuthenticationProvider(@NotNull final JwtParser jwtParser) {
this.jwtParser = jwtParser;
}
开发者ID:nus-ncl,项目名称:services-in-one,代码行数:4,代码来源:JwtAuthenticationProvider.java
示例17: create
import io.jsonwebtoken.JwtParser; //导入依赖的package包/类
@Override
public JwtParser create() {
return Jwts.parser();
}
开发者ID:shiver-me-timbers,项目名称:smt-spring-security-parent,代码行数:5,代码来源:JJwtParserFactory.java
示例18: JsonWebToken
import io.jsonwebtoken.JwtParser; //导入依赖的package包/类
public JsonWebToken(JwtParser jwtParser, String bearer) {
this.jwtParser = jwtParser;
this.bearer = bearer;
}
开发者ID:svenkubiak,项目名称:mangooio,代码行数:5,代码来源:JsonWebToken.java
示例19: must
import io.jsonwebtoken.JwtParser; //导入依赖的package包/类
public JwtParser must() {
return this.jwtParser;
}
开发者ID:svenkubiak,项目名称:mangooio,代码行数:4,代码来源:JsonWebToken.java
示例20: requireIssuedAt
import io.jsonwebtoken.JwtParser; //导入依赖的package包/类
@Override
public JwtParser requireIssuedAt(Date issuedAt) {
expectedClaims.setIssuedAt(issuedAt);
return this;
}
开发者ID:jwtk,项目名称:jjwt,代码行数:6,代码来源:DefaultJwtParser.java
注:本文中的io.jsonwebtoken.JwtParser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论