use of edu.uiuc.ncsa.security.util.functor.LogicBlock in project OA4MP by ncsa.
the class ClaimsProcessor method process.
public Map<String, Object> process(Map<String, Object> claims) {
ServletDebugUtil.dbg(this, "starting processing");
if (config == null || config.isEmpty()) {
ServletDebugUtil.dbg(this, "NO configuration, returning.");
return claims;
}
logicBlocks = createLogicBlocks(config, claims);
ServletDebugUtil.dbg(this, "created " + logicBlocks.size() + " logic blocks.");
for (LogicBlock logicBlock : logicBlocks) {
ServletDebugUtil.dbg(this, "currently evaluting logic block " + logicBlock.toString());
logicBlock.execute();
ServletDebugUtil.dbg(this, "logic block results = " + logicBlock.getResults());
}
executed = true;
ServletDebugUtil.dbg(this, "Finished processing, returned claims are");
ServletDebugUtil.dbg(this, claims.toString());
return claims;
}
use of edu.uiuc.ncsa.security.util.functor.LogicBlock in project OA4MP by ncsa.
the class FunctorTests method testLBCreation2.
/**
* This tests the logic block creation logic.
*
* @return
* @throws Exception
*/
@Test
public void testLBCreation2() throws Exception {
Map<String, Object> claims = createClaims();
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();
set.addArg(newAudience);
System.out.println("jSet=" + set.toJSON());
ifBlock.put("$then", set.toJSON());
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(bloxx.get(0).getResults());
assert claims.get("aud").toString().equals(newAudience);
}
use of edu.uiuc.ncsa.security.util.functor.LogicBlock in project OA4MP by ncsa.
the class FunctorTests method testLBClaimsReplacement.
/**
* This test creates and array of set command and executes them. This tests that the machinery for doing an
* in situ replacement works.
*
* @throws Exception
*/
@Test
public void testLBClaimsReplacement() throws Exception {
Map<String, Object> claims = createClaims();
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);
ifBlock.put("$then", set.toJSON());
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(bloxx.get(0).getResults());
assert claims.get("aud").toString().equals(targetValue) : "Should have been \"" + targetValue + "\" and got \"" + claims.get("aud") + "\"";
}
use of edu.uiuc.ncsa.security.util.functor.LogicBlock 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