本文整理汇总了Java中com.nimbusds.jwt.JWTClaimsSet.getAudience方法的典型用法代码示例。如果您正苦于以下问题:Java JWTClaimsSet.getAudience方法的具体用法?Java JWTClaimsSet.getAudience怎么用?Java JWTClaimsSet.getAudience使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.nimbusds.jwt.JWTClaimsSet
的用法示例。
在下文中一共展示了JWTClaimsSet.getAudience方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateTokenAudience
import com.nimbusds.jwt.JWTClaimsSet; //导入方法依赖的package包/类
/**
* Check whether the token has been released to the expected audience
*/
private boolean validateTokenAudience(JWTClaimsSet claims) {
List<String> audiences = claims.getAudience();
if (audiences == null) {
log.error("The authorization token doesn't have an audience (aud)");
return false;
}
if (audiences.contains(this.audience)) {
return true;
}
log.error("The authorization token audience `{}` doesn't match the expected audience `{}`",
audiences, this.audience);
return false;
}
示例2: getYourMicroserviceClaimsVerifier
import com.nimbusds.jwt.JWTClaimsSet; //导入方法依赖的package包/类
/**
* getYourMicroserviceClaimsVerifier
* Obtains our Standard Claims Verifier.
*
* @return JWTClaimsVerifier Claims Verifier to be performed against a Claims Set.
*/
protected JWTClaimsVerifier getYourMicroserviceClaimsVerifier() {
/**
* Default JWT claims verifier. This class is thread-safe.
*
* Performs the following checks:
*
* + If an expiration time (exp) claim is present, makes sure it is ahead of the current time, else the JWT claims set is rejected.
* + If a not-before-time (nbf) claim is present, makes sure it is before the current time, else the JWT claims set is rejected.
* This class may be extended to perform additional checks.
*/
return new DefaultJWTClaimsVerifier() {
@Override
public void verify(JWTClaimsSet claimsSet)
throws BadJWTException {
/**
* Verify the Expiration of the Token and Not Before Use.
*/
super.verify(claimsSet);
/**
* Ensure Correct Issuer is from our own Eco-System.
*/
String issuer = claimsSet.getIssuer();
if (issuer == null || !issuer.equals(YourMicroserviceToken.YOUR_ORGANIZATION_ISSUER)) {
throw new BadJWTException("Invalid Token issuer");
}
/**
* Ensure Subject Specified.
*/
String subject = claimsSet.getSubject();
if (subject == null || subject.isEmpty()) {
throw new BadJWTException("Invalid Token Subject");
}
/**
* Ensure Subject Specified.
*/
String jti = claimsSet.getJWTID();
if (!isUUIDValid(jti)) {
throw new BadJWTException("Invalid Token Identifier");
}
/**
* Validate Audience, we need at least Once Specified.
*/
if (claimsSet.getAudience() == null || claimsSet.getAudience().isEmpty()) {
throw new BadJWTException("Invalid Audience");
}
/**
* Ensure Your Microservice was Specified.
*/
JSONObject yms = (JSONObject) claimsSet.getClaim(CLAIM_NAME_YOUR_MICROSERVICE);
if (yms == null || yms.isEmpty()) {
throw new BadJWTException("Invalid Your Microservice Claim");
}
/**
* Add Additional Claims Verification Here if and when Applicable...
*/
}
};
}