Search in sources :

Example 86 with JSONArray

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));
}
Also used : GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) JSONArray(net.sf.json.JSONArray) AttributeGetRequest(edu.uiuc.ncsa.myproxy.oa4mp.oauth2.cm.util.attributes.AttributeGetRequest)

Example 87 with JSONArray

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));
}
Also used : GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) AttributeRemoveRequest(edu.uiuc.ncsa.myproxy.oa4mp.oauth2.cm.util.attributes.AttributeRemoveRequest) JSONArray(net.sf.json.JSONArray)

Example 88 with JSONArray

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);
}
Also used : OA2Client(edu.uiuc.ncsa.security.oauth_2_0.OA2Client) JSONObject(net.sf.json.JSONObject) JSONArray(net.sf.json.JSONArray) PrintWriter(java.io.PrintWriter)

Example 89 with JSONArray

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);
}
Also used : JSONObject(net.sf.json.JSONObject) JSONArray(net.sf.json.JSONArray) AdminClient(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.adminClient.AdminClient) PrintWriter(java.io.PrintWriter)

Example 90 with JSONArray

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;
}
Also used : StringTokenizer(java.util.StringTokenizer) JSONObject(net.sf.json.JSONObject) OA2SE(edu.uiuc.ncsa.myproxy.oa4mp.oauth2.OA2SE) JSONArray(net.sf.json.JSONArray) JSONObject(net.sf.json.JSONObject)

Aggregations

JSONArray (net.sf.json.JSONArray)144 JSONObject (net.sf.json.JSONObject)109 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)22 HashMap (java.util.HashMap)20 File (java.io.File)16 Test (org.junit.Test)15 JSON (net.sf.json.JSON)14 Map (java.util.Map)12 JsonConfig (net.sf.json.JsonConfig)10 URISyntaxException (java.net.URISyntaxException)9 URL (java.net.URL)9 URI (java.net.URI)8 SimpleChartData (com.sohu.cache.web.chart.model.SimpleChartData)6 Date (java.util.Date)6 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)5 OutputStream (java.io.OutputStream)5 List (java.util.List)5 CAFunctorFactory (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.claims.CAFunctorFactory)4 OA2Client (edu.uiuc.ncsa.security.oauth_2_0.OA2Client)4