當前位置: 首頁>>代碼示例>>Java>>正文


Java JWTClaimsSet.getAudience方法代碼示例

本文整理匯總了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;
}
 
開發者ID:Azure,項目名稱:device-telemetry-java,代碼行數:21,代碼來源:OpenIdConnectJwtValidation.java

示例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...
             */
        }
    };
}
 
開發者ID:jaschenk,項目名稱:Your-Microservice,代碼行數:65,代碼來源:YourMicroserviceToken_nimbus_Impl.java


注:本文中的com.nimbusds.jwt.JWTClaimsSet.getAudience方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。