use of edu.uiuc.ncsa.myproxy.oa4mp.oauth2.claims.CAFunctorFactory in project OA4MP by ncsa.
the class FunctorTests method testLBClaimsIntegrity.
/**
* When a claims value is accessed in a set command, the old claims value is accessed.
* makes it hard to change a value and use the new one, but does allow for integrity of the
* claims object. Note that since the values are replaced in the factory, they should remain stable
* if the value is reset several times, such as here.
*
* @throws Exception
*/
@Test
public void testLBClaimsIntegrity() throws Exception {
Map<String, Object> claims = createClaims();
System.out.println("Before, claims = " + claims);
CAFunctorFactory functorFactory = new CAFunctorFactory(claims);
JSONObject jsonObject = new JSONObject();
JSONArray array = new JSONArray();
JSONObject ifBlock = new JSONObject();
jContains jContains = new jContains();
jContains.addArg("foo");
jContains.addArg("zfoo");
ifBlock.put("$if", jContains.toJSON());
// we won't process this, just use it's toJSON to get valid JSON
jSet set = new jSet(claims);
set.addArg("aud");
String newAudience = "new-aud-" + getRandomString();
String targetValue = claims.get("aud") + "--" + newAudience;
set.addArg("${aud}--" + newAudience);
JSONArray setCommands = new JSONArray();
setCommands.add(set.toJSON());
setCommands.add(set.toJSON());
setCommands.add(set.toJSON());
ifBlock.put("$then", setCommands);
array.add(ifBlock);
System.out.println(array.toString(2));
List<LogicBlock> bloxx = functorFactory.createLogicBlock(array);
assert bloxx.size() == 1;
bloxx.get(0).execute();
System.out.println("After, claims = " + claims);
assert claims.get("aud").toString().equals(targetValue) : "Should have been \"" + targetValue + "\" and got \"" + claims.get("aud") + "\"";
}
Aggregations