Search in sources :

Example 1 with CAFunctorFactory

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);
}
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)

Example 2 with CAFunctorFactory

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

Example 3 with CAFunctorFactory

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();
}
Also used : JFunctor(edu.uiuc.ncsa.security.util.functor.JFunctor) CAFunctorFactory(edu.uiuc.ncsa.myproxy.oa4mp.oauth2.claims.CAFunctorFactory) JSONObject(net.sf.json.JSONObject) edu.uiuc.ncsa.myproxy.oa4mp.oauth2.flows.jAccessToken(edu.uiuc.ncsa.myproxy.oa4mp.oauth2.flows.jAccessToken) JFunctorTest(edu.uiuc.ncsa.security.util.JFunctorTest) Test(org.junit.Test)

Example 4 with CAFunctorFactory

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") + "\"";
}
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)

Example 5 with CAFunctorFactory

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);
}
Also used : CAFunctorFactory(edu.uiuc.ncsa.myproxy.oa4mp.oauth2.claims.CAFunctorFactory) JSONArray(net.sf.json.JSONArray)

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