use of net.sf.json.JSONArray in project OA4MP by ncsa.
the class RequestFactory method createRequest.
/* ***** Attribute requests */
public static AttributeGetRequest createRequest(AdminClient aSubj, TypeAttribute typeAttribute, ActionGet actionGet, OA2Client cTarget, JSON content) {
// JSON content = SATFactory.getContent(json);
if (!content.isArray()) {
throw new GeneralException("Content must be a list of attributes to get");
}
JSONArray array = (JSONArray) content;
String[] arrayString = (String[]) array.toArray(new String[array.size()]);
return new AttributeGetRequest(aSubj, cTarget, Arrays.asList(arrayString));
}
use of net.sf.json.JSONArray in project OA4MP by ncsa.
the class RequestFactory method createRequest.
public static AttributeRemoveRequest createRequest(AdminClient aSubj, TypeAttribute typeAttribute, ActionRemove actionRemove, OA2Client cTarget, JSON content) {
// JSON content = SATFactory.getContent(json);
if (!content.isArray()) {
throw new GeneralException("Content must be a list of attributes to get");
}
JSONArray array = (JSONArray) content;
String[] arrayString = (String[]) array.toArray(new String[array.size()]);
return new AttributeRemoveRequest(aSubj, cTarget, Arrays.asList(arrayString));
}
use of net.sf.json.JSONArray in project OA4MP by ncsa.
the class ResponseSerializer method serialize.
protected void serialize(ListClientResponse response, HttpServletResponse servletResponse) throws IOException {
JSONArray clientIDs = new JSONArray();
if (response.getClients() != null) {
for (OA2Client client : response.getClients()) {
clientIDs.add(client.getIdentifierString());
}
}
PrintWriter pw = servletResponse.getWriter();
JSONObject json = new JSONObject();
json.put("status", 0);
json.put("content", clientIDs);
pw.println(json);
}
use of net.sf.json.JSONArray in project OA4MP by ncsa.
the class ResponseSerializer method serialize.
protected void serialize(ListAdminsResponse response, HttpServletResponse servletResponse) throws IOException {
JSONArray adminIDs = new JSONArray();
if (response.getAdmins() != null) {
for (AdminClient client : response.getAdmins()) {
adminIDs.add(client.getIdentifierString());
}
}
PrintWriter pw = servletResponse.getWriter();
JSONObject json = new JSONObject();
json.put("status", 0);
json.put("content", adminIDs);
pw.println(json);
}
use of net.sf.json.JSONArray in project OA4MP by ncsa.
the class OA2UtilServlet method doIt.
@Override
protected void doIt(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Throwable {
OA2SE oa2se = (OA2SE) getEnvironment();
if (!oa2se.isUtilServletEnabled()) {
return;
}
String action = getParameter(httpServletRequest, httpServletResponse, ACTION_KEY);
if (action == null) {
return;
}
if (!action.equals(ACTION_CHECK_CLAIM)) {
spitOutMessage(httpServletResponse, CODE_ERROR, "unknown action of \"" + action + "\" requested from util servlet");
return;
}
String claimName = getParameter(httpServletRequest, httpServletResponse, CLAIM_NAME_KEY);
if (claimName == null) {
return;
}
String claimValue = getParameter(httpServletRequest, httpServletResponse, CLAIM_VALUE_KEY);
if (claimValue == null) {
return;
}
String token = getParameter(httpServletRequest, httpServletResponse, TOKEN_KEY);
if (token == null) {
return;
}
JSONObject json = null;
// so we have everything and are ready to rock.
try {
json = JWTUtil.verifyAndReadJWT(token, oa2se.getJsonWebKeys());
} catch (Throwable t) {
spitOutMessage(httpServletResponse, CODE_ERROR, "Invalid token. Message=\"" + t.getMessage() + "\"");
return;
}
if (!json.containsKey(claimName)) {
spitOutMessage(httpServletResponse, CODE_ERROR, "claim named \"" + claimName + "\" not found.");
return;
}
// simple case is its just a string
Object rawClaims = json.get(claimName);
if (rawClaims instanceof JSONArray) {
JSONArray array = (JSONArray) rawClaims;
for (int i = 0; i < array.size(); i++) {
String nextString = array.getString(i);
// first cut, parse by , as delimiter.
StringTokenizer st = new StringTokenizer(nextString, ",", false);
while (st.hasMoreTokens()) {
String x = st.nextToken();
if (claimValue.equals(x)) {
spitOutMessage(httpServletResponse, CODE_OK, null);
}
}
}
spitOutMessage(httpServletResponse, CODE_NO, null);
return;
}
// Every other case (including JSONObject, which we don't know how to parse in general)
String claim = rawClaims.toString();
if (-1 < claim.indexOf(claimValue)) {
spitOutMessage(httpServletResponse, CODE_OK, null);
} else {
spitOutMessage(httpServletResponse, CODE_NO, null);
}
return;
}
Aggregations