use of edu.uiuc.ncsa.myproxy.oa4mp.oauth2.claims.CAFunctorFactory 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.myproxy.oa4mp.oauth2.claims.CAFunctorFactory in project OA4MP by ncsa.
the class FunctorTests method testClaims.
@Test
public void testClaims() throws Exception {
Map<String, Object> claims = createClaims();
CAFunctorFactory factory = new CAFunctorFactory(claims);
// create some functors, turn into JSON then have the factory re-create them and do the
// replacements
jExists jExists = new jExists();
jExists.addArg("${issuer}");
JSONObject rawExists = jExists.toJSON();
jExists jExists1 = (jExists) factory.fromJSON(rawExists);
assert jExists1.getArgs().get(0).equals(claims.get("issuer"));
jMatch jMatch = new jMatch();
jMatch.addArg("${aud}");
jMatch.addArg(claims.get("aud").toString());
jMatch jMatch1 = (jMatch) factory.fromJSON(jMatch.toJSON());
jMatch1.execute();
assert jMatch1.getBooleanResult();
jContains jContains = new jContains();
// needle;
jContains.addArg("${sub}");
// haystack
jContains.addArg("$sub${sub}@fnord.org");
jContains jContains1 = (jContains) factory.fromJSON(jContains.toJSON());
jContains1.execute();
assert jContains1.getBooleanResult();
}
use of edu.uiuc.ncsa.myproxy.oa4mp.oauth2.claims.CAFunctorFactory in project OA4MP by ncsa.
the class FunctorTests method testAccessToken.
@Test
public void testAccessToken() throws Exception {
Map<String, Object> claims = createClaims();
CAFunctorFactory ff = new CAFunctorFactory(claims);
String rawJson = "{\"$access_token\":[\"$true\"]}";
JFunctor jf = ff.fromJSON(JSONObject.fromObject(rawJson));
assert jf instanceof jAccessToken;
jf.execute();
assert ((jAccessToken) jf).getBooleanResult();
}
use of edu.uiuc.ncsa.myproxy.oa4mp.oauth2.claims.CAFunctorFactory 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.myproxy.oa4mp.oauth2.claims.CAFunctorFactory in project OA4MP by ncsa.
the class ClaimsProcessor method createLogicBlocks.
/**
* create the logic blocks for this configuration. It also configures the factory
* @param configuration
* @return
*/
protected List<LogicBlock> createLogicBlocks(JSONObject configuration, Map<String, Object> claims) {
ServletDebugUtil.dbg(this, "config:\n\n" + config.toString(2));
CAFunctorFactory functorFactory = new CAFunctorFactory(claims);
JSONArray jsonArray = new JSONArray();
jsonArray.add(config);
ServletDebugUtil.dbg(this, "created JSON array:\n\n" + jsonArray.toString(2));
return functorFactory.createLogicBlock(jsonArray);
}
Aggregations