Search in sources :

Example 6 with CAFunctorFactory

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") + "\"";
}
Also used : JSONObject(net.sf.json.JSONObject) CAFunctorFactory(edu.uiuc.ncsa.myproxy.oa4mp.oauth2.claims.CAFunctorFactory) JSONArray(net.sf.json.JSONArray) edu.uiuc.ncsa.myproxy.oa4mp.oauth2.claims.jSet(edu.uiuc.ncsa.myproxy.oa4mp.oauth2.claims.jSet) JSONObject(net.sf.json.JSONObject) LogicBlock(edu.uiuc.ncsa.security.util.functor.LogicBlock) JFunctorTest(edu.uiuc.ncsa.security.util.JFunctorTest) Test(org.junit.Test)

Aggregations

CAFunctorFactory (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.claims.CAFunctorFactory)6 JFunctorTest (edu.uiuc.ncsa.security.util.JFunctorTest)5 JSONObject (net.sf.json.JSONObject)5 Test (org.junit.Test)5 JSONArray (net.sf.json.JSONArray)4 edu.uiuc.ncsa.myproxy.oa4mp.oauth2.claims.jSet (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.claims.jSet)3 LogicBlock (edu.uiuc.ncsa.security.util.functor.LogicBlock)3 edu.uiuc.ncsa.myproxy.oa4mp.oauth2.flows.jAccessToken (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.flows.jAccessToken)1 JFunctor (edu.uiuc.ncsa.security.util.functor.JFunctor)1