use of net.sf.json.JSONArray 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);
}
use of net.sf.json.JSONArray in project OA4MP by ncsa.
the class LDAPClaimsSource method toJSON.
/**
* This takes the result of the search as a {@link NamingEnumeration} and set of attributes (from the
* configuration file) and returns a JSON object. The default is that singletons are returned as simple
* values while lists are recorded as arrays.
*
* @param attributes
* @param e
* @return
* @throws NamingException
*/
protected JSONObject toJSON(Map<String, LDAPConfigurationUtil.AttributeEntry> attributes, NamingEnumeration e) throws NamingException {
DebugUtil.dbg(this, "starting to convert search results to JSON. " + attributes.size() + " results found.");
JSONObject json = new JSONObject();
while (e.hasMore()) {
SearchResult entry = (SearchResult) e.next();
Attributes a = entry.getAttributes();
for (String attribID : attributes.keySet()) {
Attribute attribute = a.get(attribID);
DebugUtil.dbg(this, "returned LDAP attribute=" + attribute);
if (attribute == null) {
continue;
}
if (attributes.get(attribID).isGroup) {
JSONArray jsonAttribs = new JSONArray();
for (int i = 0; i < attribute.size(); i++) {
jsonAttribs.add(attribute.get(i));
}
GroupHandler gg = null;
if (isNCSA()) {
gg = new NCSAGroupHandler(this);
} else {
gg = getGroupHandler();
}
Groups groups = gg.parse(jsonAttribs);
json.put(attributes.get(attribID).targetName, groups.toJSON());
} else {
if (attribute.size() == 1) {
// Single-valued attributes are recorded as simple values
if (attributes.get(attribID).isList) {
JSONArray jsonAttribs = new JSONArray();
jsonAttribs.add(attribute.get(0));
json.put(attributes.get(attribID).targetName, jsonAttribs);
} else {
json.put(attributes.get(attribID).targetName, attribute.get(0));
}
} else {
// Multi-valued attributes are recorded as arrays.
JSONArray jsonAttribs = new JSONArray();
for (int i = 0; i < attribute.size(); i++) {
jsonAttribs.add(attribute.get(i));
}
json.put(attributes.get(attribID).targetName, jsonAttribs);
}
}
}
}
DebugUtil.dbg(this, "LDAP search results=" + json);
return json;
}
use of net.sf.json.JSONArray 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") + "\"";
}
use of net.sf.json.JSONArray in project OA4MP by ncsa.
the class ThingTester method getResponse.
public static void getResponse() {
JSONObject resp = new JSONObject();
resp.put("status", 0);
JSONObject client = new JSONObject();
JSONObject contentItems = new JSONObject();
contentItems.put("id", "777");
JSONArray cbs = new JSONArray();
cbs.add("https://a.b.c/client/ready1");
cbs.add("https://a.b.c/client/ready2");
contentItems.put("callbacks", cbs);
contentItems.put("limited_proxies", false);
client.put("client", contentItems);
resp.put("content", client);
prettyPrint(resp);
}
use of net.sf.json.JSONArray in project OA4MP by ncsa.
the class ThingTester method setExample.
public static JSONObject setExample() {
JSONObject admin = new JSONObject();
JSONObject adminSecrets = new JSONObject();
adminSecrets.put("id", "123");
adminSecrets.put("secret", "456");
admin.put("admin", adminSecrets);
JSONObject client = new JSONObject();
JSONObject clientSecret = new JSONObject();
clientSecret.put("id", "777");
client.put("client", clientSecret);
JSONObject actionItems = new JSONObject();
actionItems.put("method", "set");
actionItems.put("type", "attribute");
JSONObject contentItems = new JSONObject();
JSONArray cbs = new JSONArray();
cbs.add("https://a.b.c/client/ready1");
cbs.add("https://a.b.c/client/ready2");
contentItems.put("callbacks", cbs);
JSONArray scopes = new JSONArray();
scopes.add("openid");
scopes.add("profile");
scopes.add("email");
contentItems.put("scopes", scopes);
contentItems.put("home_uri", "https://a.b.c/client");
contentItems.put("error_uri", "https://a.b.c/client/error");
contentItems.put("limited_proxies", true);
JSONObject api = new JSONObject();
JSONObject apiItems = new JSONObject();
apiItems.put("subject", admin);
apiItems.put("action", actionItems);
apiItems.put("object", client);
apiItems.put("content", contentItems);
api.put("api", apiItems);
prettyPrint(api);
return api;
}
Aggregations