/*
(non-Javadoc)

@see com.ibm.ws.security.jwt.internal.Builder#claimFrom(com.ibm.websphere.security.jwt.JwtToken)
353723
@Override
    public Builder claimFrom(JwtToken jwt) throws InvalidTokenException {
        if (jwt != null && !jwt.getClaims().isEmpty()) {
            claims.putAll(jwt.getClaims());
            // copyClaimsMap(jwt.getClaims());
        } else {
            String err = Tr.formatMessage(tc, "JWT_INVALID_TOKEN_ERR");// "JWT_INVALID_TOKEN_ERR";
            throw new InvalidTokenException(err);
        }
        return this;
    }
313163
@Override
    public Builder fetch(String name) throws InvalidClaimException {
        if (JwtUtils.isNullEmpty(name)) {
            String err = Tr.formatMessage(tc, "JWT_INVALID_CLAIM_ERR", new Object[] { name });
            throw new InvalidClaimException(err);
        }
        String sub = claims.getSubject();
        if (JwtUtils.isNullEmpty(sub)) {
            // TODO
            // Tr.warning
            // We can not really get to registry without valid user name
        } else {
            Object obj = null;
            try {
                obj = JwtUtils.fetch(name, sub);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                // Tr.warning
                // e.printStackTrace();
            }
            if (obj != null) {
                claims.put(name, obj);
            }
        }
        return this;
    }
157939
static Claim claimFromNode(JsonNode node, ObjectReader objectReader) {
        if (node == null || node.isNull() || node.isMissingNode()) {
            return new NullClaim();
        }
        return new JsonNodeClaim(node, objectReader);
    }
112789
def requestClaimDef(self, seqNo, signature, sender):
        
        operation = { TXN_TYPE: GET_CLAIM_DEF,
                      ORIGIN: sender,
                      REF : seqNo,
                      SIGNATURE_TYPE : signature
                    }

        req = Request(sender, operation=operation)
        return self.prepReq(req)
539100
public function setIslandoraClaims(JwtAuthGenerateEvent $event) {
    global $base_secure_url;

    // Standard claims, validated at JWT validation time.
    $event->addClaim('iat', time());
    $expiry_setting = \Drupal::config(IslandoraSettingsForm::CONFIG_NAME)
      ->get(IslandoraSettingsForm::JWT_EXPIRY);
    $expiry = $expiry_setting ? $expiry_setting : '+2 hour';
    $event->addClaim('exp', strtotime($expiry));
    $event->addClaim('webid', $this->currentUser->id());
    $event->addClaim('iss', $base_secure_url);

    // Islandora claims we need to validate.
    $event->addClaim('sub', $this->currentUser->getAccountName());
    $event->addClaim('roles', $this->currentUser->getRoles(FALSE));

  }
299001
public static Claims claims(Map<String, Object> claims) {
        return Classes.newInstance("io.jsonwebtoken.impl.DefaultClaims", MAP_ARG, claims);
    }
507534
static ClientAssertion buildJwt(final AsymmetricKeyCredential credential,
            final String jwtAudience) throws AuthenticationException {
        if (credential == null) {
            throw new IllegalArgumentException("credential is null");
        }

        final long time = System.currentTimeMillis();

        final JWTClaimsSet claimsSet = new JWTClaimsSet.Builder()
                .audience(Collections.singletonList(jwtAudience))
                .issuer(credential.getClientId())
                .jwtID(UUID.randomUUID().toString())
                .notBeforeTime(new Date(time))
                .expirationTime(new Date(time
                                + AuthenticationConstants.AAD_JWT_TOKEN_LIFETIME_SECONDS
                                * 1000))
                .subject(credential.getClientId())
                .build();

        SignedJWT jwt;
        try {
            JWSHeader.Builder builder = new Builder(JWSAlgorithm.RS256);
            List<Base64> certs = new ArrayList<Base64>();
            certs.add(new Base64(credential.getPublicCertificate()));
            builder.x509CertChain(certs);
            builder.x509CertThumbprint(new Base64URL(credential
                    .getPublicCertificateHash()));
            jwt = new SignedJWT(builder.build(), claimsSet);
            final RSASSASigner signer = new RSASSASigner(credential.getKey());

            jwt.sign(signer);
        }
        catch (final Exception e) {
            throw new AuthenticationException(e);
        }

        return new ClientAssertion(jwt.serialize());
    }
749070
static Claim extractClaim(String claimName, Map<String, JsonNode> tree, ObjectReader objectReader) {
        JsonNode node = tree.get(claimName);
        return claimFromNode(node, objectReader);
    }
230448
public Map<String, Object> validateTokenAndGetClaims(final String token) {
        final CommonProfile profile = validateToken(token);

        final Map<String, Object> claims = new HashMap<>(profile.getAttributes());
        claims.put(JwtClaims.SUBJECT, profile.getId());

        return claims;
    }
290139
def claim(task, force = false)
      raise UnauthorizedClaimAttempt unless has_role?(task.role)
      release!(task) if force
      task.claim(claim_token)
    end
125662
public static Map<String, Object> verify(String token, final RSAPublicKey pk) throws InvalidTokenException {
        // RS256签名验证器
        Verifier verifier = new Verifier() {
            @Override
            public boolean verifySignature(String content, String payload, String signature) {
                return JWT.verifySignature(content,signature,pk);
            }
        };
        return verify(token, verifier);
    }
1333369
public String getLoginNameFromToken(String token) {
        String username = null;
        try {
            final Claims claims = getClaimsFromToken(token);
            username = claims.getSubject();
        } catch (Exception e) {
            log.error("get username from jwt token error : {}", e.getMessage());
        }
        return username;
    }
617830
@Override
    public Builder audience(List<String> newaudiences) throws InvalidClaimException {
        // this.AUDIENCE
        if (newaudiences != null && !newaudiences.isEmpty()) {

            ArrayList<String> audiences = new ArrayList<String>();
            for (String aud : newaudiences) {
                if (aud != null && !aud.trim().isEmpty() && !audiences.contains(aud)) {
                    audiences.add(aud);
                }
            }
            if (audiences.isEmpty()) {
                String err = Tr.formatMessage(tc, "JWT_INVALID_CLAIM_VALUE_ERR", new Object[] { Claims.AUDIENCE, newaudiences });
                throw new InvalidClaimException(err);
            }
            // this.audiences = new ArrayList<String>(audiences);
            claims.put(Claims.AUDIENCE, audiences);
        } else {
            String err = Tr.formatMessage(tc, "JWT_INVALID_CLAIM_VALUE_ERR", new Object[] { Claims.AUDIENCE, newaudiences });
            throw new InvalidClaimException(err);
        }
        return this;
    }
569581
function validateAskPermission (token) {
  const header = jwt.decode(token)

  return validateToken(token) && header[ASK_CLAIM_KEY]
}
1181716
@Override
	// @FFDCIgnore(Exception.class)
	public void createJwtSSOToken(Subject subject) throws WSLoginFailedException {
		// TODO Auto-generated method stub
		if (subject != null) {
			if (isSubjectUnauthenticated(subject) || subjectHasJwtPrincipal(subject)) {
				return;
			}
			JwtSsoTokenUtils tokenUtil = getJwtSsoTokenBuilderUtils();
			if (tokenUtil != null) {
				JsonWebToken ssotoken = null;
				try {
					ssotoken = tokenUtil.buildTokenFromSecuritySubject(subject);
				} catch (Exception e) {
					// TODO ffdc
					throw new WSLoginFailedException(e.getLocalizedMessage());
				}
				updateSubject(subject, ssotoken);
			} else {
				String msg = Tr.formatMessage(tc, "JWTSSO_CONFIG_INVALID", new Object[] {});				
				throw new WSLoginFailedException(msg);
			}
		}
	}
704554
public JwtToken build(JwtAuth userDetails) {
        Date expireTime = generateExpirationDate();
        Map<String, Object> claims = new HashMap<>(16);
        claims.put(CLAIM_KEY_LOGIN_NAME, userDetails.getLoginName());
        claims.put(CLAIM_KEY_ID, userDetails.getId());
        claims.put(CLAIM_KEY_MICK_NAME, userDetails.getNickName());
        claims.put(CLAIM_KEY_CREATED, expireTime.getTime());
        claims.put(CLAIM_KEY_ROLE, userDetails.getRoles());
        claims.put(CLAIM_KEY_AVATAR,userDetails.getAvatar());
        return new JwtToken(build(claims, expireTime), expireTime.getTime());
    }
1259652
private Builder issueTime(long iat) throws InvalidClaimException {

        if (iat > 0) {
            claims.put(Claims.ISSUED_AT, Long.valueOf(iat));
        } else {
            // String msg = "The exp claim must be a positive number.";
            String err = Tr.formatMessage(tc, "JWT_INVALID_TIME_CLAIM_ERR", new Object[] { Claims.ISSUED_AT });
            throw new InvalidClaimException(err);
        }
        return this;
    }