本文整理匯總了Java中net.minidev.json.JSONArray.forEach方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONArray.forEach方法的具體用法?Java JSONArray.forEach怎麽用?Java JSONArray.forEach使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.minidev.json.JSONArray
的用法示例。
在下文中一共展示了JSONArray.forEach方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: hello
import net.minidev.json.JSONArray; //導入方法依賴的package包/類
@Test
public void hello() throws URISyntaxException, IOException {
String jsonString = FileUtils.readFirstLine("general/test.json");
Object jsonDocument = Configuration.defaultConfiguration().jsonProvider().parse(jsonString);
for (JsonBranch collectionBranch : schema.getCollectionPaths()) {
Object rawCollection = null;
try {
rawCollection = JsonPath.read(jsonDocument, collectionBranch.getJsonPath());
} catch (PathNotFoundException e) {}
if (rawCollection != null) {
if (rawCollection instanceof JSONArray) {
JSONArray collection = (JSONArray)rawCollection;
collection.forEach(
node -> {
processNode(node, collectionBranch.getChildren());
}
);
} else {
processNode(rawCollection, collectionBranch.getChildren());
}
}
}
}
示例2: retrieveCredential
import net.minidev.json.JSONArray; //導入方法依賴的package包/類
@Override
public JWTCredential retrieveCredential(String token) {
JWTCredential result = null;
try {
JWSObject jws = JWSObject.parse(token);
String apiKey = jws.getHeader().getKeyID();
if (apiKey != null && keys.contains(apiKey)) {
RSAKey rsaKey = (RSAKey) jwkSet.getKeyByKeyId(apiKey).toPublicJWK();
JWSVerifier verifier = new RSASSAVerifier(rsaKey);
if (jws.verify(verifier)) {
JWTClaimsSet claimsSet = JWTClaimsSet.parse(jws.getPayload().toJSONObject());
// Verify time validity of token.
Date creationTime = claimsSet.getIssueTime();
Date expirationTime = claimsSet.getExpirationTime();
Date now = new Date();
long validityPeriod = expirationTime.getTime() - creationTime.getTime();
if (creationTime.before(now) && now.before(expirationTime) && validityPeriod < 120000 /*2 minutes*/) {
JSONObject realmAccess = (JSONObject) claimsSet.getClaim("realm_access");
JSONArray rolesArray = (JSONArray) realmAccess.get("roles");
Set<String> roles = new HashSet<>();
rolesArray.forEach(r -> roles.add(r.toString()));
result = new JWTCredential(claimsSet.getSubject(), roles);
}
}
}
} catch (ParseException | JOSEException e) {
; // Token is not valid
}
return result;
}
示例3: retrieveCredential
import net.minidev.json.JSONArray; //導入方法依賴的package包/類
@Override
public JWTCredential retrieveCredential(String token) {
JWTCredential result = null;
try {
JWSObject jws = JWSObject.parse(token);
String apiKey = jws.getHeader().getKeyID();
if (apiKey != null && keys.containsKey(apiKey)) {
byte[] sharedSecret = keys.get(apiKey);
JWSVerifier verifier = new MACVerifier(sharedSecret);
if (jws.verify(verifier)) {
JWTClaimsSet claimsSet = JWTClaimsSet.parse(jws.getPayload().toJSONObject());
// Verify time validity of token.
Date creationTime = claimsSet.getIssueTime();
Date expirationTime = claimsSet.getExpirationTime();
Date now = new Date();
long validityPeriod = expirationTime.getTime() - creationTime.getTime();
if (creationTime.before(now) && now.before(expirationTime) && validityPeriod < 120000 /*2 minutes*/) {
JSONObject realmAccess = (JSONObject) claimsSet.getClaim("realm_access");
JSONArray rolesArray = (JSONArray) realmAccess.get("roles");
Set<String> roles = new HashSet<>();
rolesArray.forEach(r -> roles.add(r.toString()));
result = new JWTCredential(claimsSet.getSubject(), roles);
result.addInfo(API_KEY, apiKey);
}
}
}
} catch (ParseException | JOSEException e) {
; // Token is not valid
}
return result;
}
示例4: retrieveCredential
import net.minidev.json.JSONArray; //導入方法依賴的package包/類
@Override
public JWTCredential retrieveCredential(String token) {
JWTCredential result = null;
try {
// Parse the JWE string
JWEObject jweObject = JWEObject.parse(token);
String apiKey = jweObject.getHeader().getKeyID();
// Use this apiKey to select the correct privateKey
RSAKey privateKey = (RSAKey) jwkSet.getKeyByKeyId(apiKey);
// Decrypt with shared key
jweObject.decrypt(new RSADecrypter(privateKey));
// Extract payload
SignedJWT signedJWT = jweObject.getPayload().toSignedJWT();
// Check the HMAC, Optional
signedJWT.verify(new MACVerifier(apiKey));
// Retrieve the JWT claims...
JWTClaimsSet claimsSet = signedJWT.getJWTClaimsSet();
// Verify time validity of token.
Date creationTime = claimsSet.getIssueTime();
Date expirationTime = claimsSet.getExpirationTime();
Date now = new Date();
long validityPeriod = expirationTime.getTime() - creationTime.getTime();
if (creationTime.before(now) && now.before(expirationTime) && validityPeriod < 120000 /*2 minutes*/) {
JSONObject realmAccess = (JSONObject) claimsSet.getClaim("realm_access");
JSONArray rolesArray = (JSONArray) realmAccess.get("roles");
Set<String> roles = new HashSet<>();
rolesArray.forEach(r -> roles.add(r.toString()));
result = new JWTCredential(claimsSet.getSubject(), roles);
result.addInfo(API_KEY, apiKey);
result.addInfo(API_KEY, apiKey);
}
} catch (ParseException | JOSEException e) {
; // Token is not valid
}
return result;
}