Search in sources :

Example 1 with JFunctor

use of edu.uiuc.ncsa.security.util.functor.JFunctor in project OA4MP by ncsa.

the class jSet method execute.

@Override
public Object execute() {
    String claim = String.valueOf(getArgs().get(0));
    if (!claims.containsKey(claim)) {
        return null;
    }
    Object obj = getArgs().get(1);
    String newValue = null;
    if (obj instanceof JFunctor) {
        JFunctor ff = (JFunctor) obj;
        ff.execute();
        newValue = String.valueOf(ff.getResult());
    } else {
        newValue = String.valueOf(obj);
    }
    claims.put(claim, newValue);
    return newValue;
}
Also used : JFunctor(edu.uiuc.ncsa.security.util.functor.JFunctor)

Example 2 with JFunctor

use of edu.uiuc.ncsa.security.util.functor.JFunctor 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 3 with JFunctor

use of edu.uiuc.ncsa.security.util.functor.JFunctor in project OA4MP by ncsa.

the class jExclude method execute.

@Override
public Object execute() {
    HashSet<String> newClaims = new HashSet<>();
    for (int i = 0; i < getArgs().size(); i++) {
        Object obj = getArgs().get(i);
        String newClaim = null;
        if (obj instanceof JFunctor) {
            JFunctor ff = (JFunctor) obj;
            ff.execute();
            newClaim = String.valueOf(ff.getResult());
        } else {
            newClaim = String.valueOf(obj);
        }
        if (newClaim != null) {
            newClaims.add(newClaim);
        }
    }
    for (String claim : newClaims) {
        claims.remove(claim);
    }
    result = null;
    return result;
}
Also used : JFunctor(edu.uiuc.ncsa.security.util.functor.JFunctor) HashSet(java.util.HashSet)

Example 4 with JFunctor

use of edu.uiuc.ncsa.security.util.functor.JFunctor in project OA4MP by ncsa.

the class jInclude method execute.

@Override
public Object execute() {
    HashSet<String> newClaims = new HashSet<>();
    for (int i = 0; i < getArgs().size(); i++) {
        Object obj = getArgs().get(i);
        String newClaim = null;
        if (obj instanceof JFunctor) {
            JFunctor ff = (JFunctor) obj;
            ff.execute();
            newClaim = String.valueOf(ff.getResult());
        } else {
            newClaim = String.valueOf(obj);
        }
        if (newClaim != null) {
            newClaims.add(newClaim);
        }
    }
    Set<String> currentClaims = new HashSet<>();
    // when you try to remove values.
    for (String x : claims.keySet()) {
        currentClaims.add(x);
    }
    for (String claim : currentClaims) {
        if (!newClaims.contains(claim)) {
            claims.remove(claim);
        }
    }
    result = null;
    return result;
}
Also used : JFunctor(edu.uiuc.ncsa.security.util.functor.JFunctor) HashSet(java.util.HashSet)

Aggregations

JFunctor (edu.uiuc.ncsa.security.util.functor.JFunctor)4 HashSet (java.util.HashSet)2 CAFunctorFactory (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.claims.CAFunctorFactory)1 edu.uiuc.ncsa.myproxy.oa4mp.oauth2.flows.jAccessToken (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.flows.jAccessToken)1 JFunctorTest (edu.uiuc.ncsa.security.util.JFunctorTest)1 JSONObject (net.sf.json.JSONObject)1 Test (org.junit.Test)1