本文整理了Java中io.jsonwebtoken.Claims.getIssuer()
方法的一些代码示例,展示了Claims.getIssuer()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Claims.getIssuer()
方法的具体详情如下:
包路径:io.jsonwebtoken.Claims
类名称:Claims
方法名:getIssuer
[英]Returns the JWT iss
(issuer) value or null if not present.
[中]返回JWTiss
(issuer)值,如果不存在,则返回null。
代码示例来源:origin: apache/nifi
public String getAuthenticationFromToken(final String base64EncodedToken) throws JwtException {
// The library representations of the JWT should be kept internal to this service.
try {
final Jws<Claims> jws = parseTokenFromBase64EncodedString(base64EncodedToken);
if (jws == null) {
throw new JwtException("Unable to parse token");
}
// Additional validation that subject is present
if (StringUtils.isEmpty(jws.getBody().getSubject())) {
throw new JwtException("No subject available in token");
}
// TODO: Validate issuer against active registry?
if (StringUtils.isEmpty(jws.getBody().getIssuer())) {
throw new JwtException("No issuer available in token");
}
return jws.getBody().getSubject();
} catch (JwtException e) {
logger.debug("The Base64 encoded JWT: " + base64EncodedToken);
final String errorMessage = "There was an error validating the JWT";
logger.error(errorMessage, e);
throw e;
}
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void refresh_token() {
setSecretKey(A_SECRET_KEY);
underTest.start();
Date now = new Date();
Date createdAt = DateUtils.parseDate("2016-01-01");
// Expired in 10 minutes
Date expiredAt = new Date(now.getTime() + 10 * 60 * 1000);
Claims token = new DefaultClaims()
.setId("id")
.setSubject("subject")
.setIssuer("sonarqube")
.setIssuedAt(createdAt)
.setExpiration(expiredAt);
token.put("key", "value");
// Refresh the token with a higher expiration time
String encodedToken = underTest.refresh(token, 20 * 60);
Claims result = underTest.decode(encodedToken).get();
assertThat(result.getId()).isEqualTo("id");
assertThat(result.getSubject()).isEqualTo("subject");
assertThat(result.getIssuer()).isEqualTo("sonarqube");
assertThat(result.getIssuedAt()).isEqualTo(createdAt);
assertThat(result.get("key")).isEqualTo("value");
// Expiration date has been changed
assertThat(result.getExpiration()).isNotEqualTo(expiredAt)
.isAfterOrEqualsTo(new Date(now.getTime() + 19 * 1000));
}
代码示例来源:origin: trellis-ldp/trellis
/**
* Generate a Principal from a subject claim.
* @param claims the JWT claims
* @return a Principal, if one can be generated from standard claims
*/
public static Optional<Principal> withSubjectClaim(final Claims claims) {
return ofNullable(claims.getSubject()).flatMap(sub -> {
// use the sub claim if it looks like a webid
if (isUrl(sub)) {
LOGGER.debug("Using JWT claim with sub: {}", sub);
return of(sub).map(OAuthPrincipal::new);
}
final String iss = claims.getIssuer();
// combine the iss and sub fields if that appears possible
if (nonNull(iss) && isUrl(iss)) {
final String webid = iss.endsWith("/") ? iss + sub : iss + "/" + sub;
LOGGER.debug("Using JWT claim with generated webid: {}", webid);
return of(webid).map(OAuthPrincipal::new);
}
// Use an OIDC website claim, if one exists
if (claims.containsKey(WEBSITE)) {
final String site = claims.get(WEBSITE, String.class);
LOGGER.debug("Using JWT claim with website: {}", site);
return ofNullable(site).map(OAuthPrincipal::new);
}
return empty();
});
}
代码示例来源:origin: io.interface21/ameba-lib
.parse(splitToken[0] + "." + splitToken[1] + ".");
Issuer issuer = whiteList.getIssuer(jwt.getBody().getIssuer());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Issuer accepted [{}]", issuer.getIssuerId());
代码示例来源:origin: io.interface21/ameba-lib
String issuer = jws.getBody().getIssuer();
Optional<TenantEO> tenantEO = repository.findByHash(request.getHeader(HEADER_VALUE_X_TENANT));
代码示例来源:origin: lzh-boy/cskit
public static Claims parseJWT(String jwt) {
//This line will throw an exception if it is not a signed JWS (as expected)
JwsHeader claims1 = Jwts.parser()
.setSigningKey(DatatypeConverter.parseBase64Binary(SIGN))
.parseClaimsJws(jwt).getHeader();
Claims claims = Jwts.parser()
.setSigningKey(DatatypeConverter.parseBase64Binary(SIGN))
.parseClaimsJws(jwt).getBody();
// createJWT()
System.out.println("ID: " + claims.getId());
System.out.println("Subject: " + claims.getSubject());
System.out.println("Issuer: " + claims.getIssuer());
System.out.println("Expiration: " + claims.getExpiration());
return claims;
}
}
代码示例来源:origin: org.apache.nifi/nifi-web-security
public String getAuthenticationFromToken(final String base64EncodedToken) throws JwtException {
// The library representations of the JWT should be kept internal to this service.
try {
final Jws<Claims> jws = parseTokenFromBase64EncodedString(base64EncodedToken);
if (jws == null) {
throw new JwtException("Unable to parse token");
}
// Additional validation that subject is present
if (StringUtils.isEmpty(jws.getBody().getSubject())) {
throw new JwtException("No subject available in token");
}
// TODO: Validate issuer against active registry?
if (StringUtils.isEmpty(jws.getBody().getIssuer())) {
throw new JwtException("No issuer available in token");
}
return jws.getBody().getSubject();
} catch (JwtException e) {
logger.debug("The Base64 encoded JWT: " + base64EncodedToken);
final String errorMessage = "There was an error validating the JWT";
logger.error(errorMessage, e);
throw e;
}
}
代码示例来源:origin: stormpath/stormpath-sdk-java
.setSigningKey(apiKeySecret.getBytes("UTF-8"))
.parseClaimsJws(bearerRequest.getJwt()).getBody();
Assert.isTrue(claims.getIssuer().equals(application.getHref()));
代码示例来源:origin: com.stormpath.sdk/stormpath-sdk-impl
.setSigningKey(apiKeySecret.getBytes("UTF-8"))
.parseClaimsJws(bearerRequest.getJwt()).getBody();
Assert.isTrue(claims.getIssuer().equals(application.getHref()));
代码示例来源:origin: org.eclipse.che.multiuser/che-multiuser-keycloak-server
if (username == null) { // fallback to unique id promised by spec
username = claims.getIssuer() + ":" + claims.getSubject();
代码示例来源:origin: stormpath/stormpath-sdk-java
.parseClaimsJws(bearerRequest.getJwt()).getBody();
String issuer = claims.getIssuer();
Assert.isTrue(issuer.startsWith(dataStore.getBaseUrl()) || "stormpath-okta-client".equals(issuer));
代码示例来源:origin: com.stormpath.sdk/stormpath-sdk-impl
.parseClaimsJws(bearerRequest.getJwt()).getBody();
String issuer = claims.getIssuer();
Assert.isTrue(issuer.startsWith(dataStore.getBaseUrl()) || "stormpath-okta-client".equals(issuer));
代码示例来源:origin: tomsun28/bootshiro
/**
* 验签JWT
*
* @param jwt json web token
*/
public static JwtAccount parseJwt(String jwt, String appKey) throws ExpiredJwtException, UnsupportedJwtException, MalformedJwtException, SignatureException, IllegalArgumentException {
Claims claims = Jwts.parser()
.setSigningKey(DatatypeConverter.parseBase64Binary(appKey))
.parseClaimsJws(jwt)
.getBody();
JwtAccount jwtAccount = new JwtAccount();
jwtAccount.setTokenId(claims.getId());// 令牌ID
jwtAccount.setAppId(claims.getSubject());// 客户标识
jwtAccount.setIssuer(claims.getIssuer());// 签发者
jwtAccount.setIssuedAt(claims.getIssuedAt());// 签发时间
jwtAccount.setAudience(claims.getAudience());// 接收方
jwtAccount.setRoles(claims.get("roles", String.class));// 访问主张-角色
jwtAccount.setPerms(claims.get("perms", String.class));// 访问主张-权限
return jwtAccount;
}
代码示例来源:origin: com.holon-platform.core/holon-auth-jwt
String tokenIssuer = claims.getIssuer();
if (tokenIssuer == null) {
throw new InvalidTokenException("Missing required JWT Issuer");
代码示例来源:origin: line/line-sdk-android
@NonNull
private static LineIdToken buildIdToken(final Claims claims) {
return new LineIdToken.Builder()
.issuer(claims.getIssuer())
.subject(claims.getSubject())
.audience(claims.getAudience())
.expiresAt(claims.getExpiration())
.issuedAt(claims.getIssuedAt())
.authTime(claims.get("auth_time", Date.class))
.nonce(claims.get("nonce", String.class))
.name(claims.get("name", String.class))
.picture(claims.get("picture", String.class))
.phoneNumber(claims.get("phone_number", String.class))
.email(claims.get("email", String.class))
.gender(claims.get("gender", String.class))
.birthdate(claims.get("birthdate", String.class))
.address(buildAddress(claims))
.givenName(claims.get("given_name", String.class))
.givenNamePronunciation(claims.get("given_name_pronunciation", String.class))
.middleName(claims.get("middle_name", String.class))
.familyName(claims.get("family_name", String.class))
.familyNamePronunciation(claims.get("family_name_pronunciation", String.class))
.build();
}
内容来源于网络,如有侵权,请联系作者删除!