Search in sources :

Example 1 with OA2ClientKeys

use of edu.uiuc.ncsa.security.oauth_2_0.OA2ClientKeys in project OA4MP by ncsa.

the class ResponseSerializer method clientToJSON.

private JSONObject clientToJSON(OA2Client client) {
    JSONObject json = new JSONObject();
    json.put("status", 0);
    OA2ClientKeys keys = (OA2ClientKeys) cose.getClientStore().getACConverter().getKeys();
    List<String> allKeys = keys.allKeys();
    allKeys.remove(keys.secret());
    OA2Client newClient = (OA2Client) cose.getClientStore().getACConverter().subset(client, allKeys);
    JSONObject jsonClient = new JSONObject();
    cose.getClientStore().getACConverter().toJSON(newClient, jsonClient);
    json.put("content", jsonClient);
    return json;
}
Also used : OA2Client(edu.uiuc.ncsa.security.oauth_2_0.OA2Client) JSONObject(net.sf.json.JSONObject) OA2ClientKeys(edu.uiuc.ncsa.security.oauth_2_0.OA2ClientKeys)

Example 2 with OA2ClientKeys

use of edu.uiuc.ncsa.security.oauth_2_0.OA2ClientKeys in project OA4MP by ncsa.

the class AttributeServerTest method testAttributeServerSet.

public void testAttributeServerSet(CMTestStoreProvider tp2) throws Exception {
    CC cc = setupClients(tp2);
    OA2ClientKeys keys = getClientKeys(tp2);
    AttributeServer attributeServer = new AttributeServer(tp2.getCOSE());
    JSONObject map = new JSONObject();
    String random = getRandom(8);
    LinkedList<String> scopes = new LinkedList<>();
    scopes.add(OA2Scopes.SCOPE_PROFILE);
    scopes.add(OA2Scopes.SCOPE_OPENID);
    map.put(keys.name(), "new name " + random);
    map.put(keys.homeURL(), "https://" + random + "/client");
    map.put(keys.scopes(), scopes);
    AttributeSetClientRequest req = RequestFactory.createRequest(cc.adminClient, new TypeAttribute(), new ActionSet(), cc.client, map);
    AttributeClientResponse resp = (AttributeClientResponse) attributeServer.process(req);
    OA2Client client = (OA2Client) resp.getClient();
    assert client.getName().equals(map.get(keys.name()));
    assert client.getIdentifier().equals(cc.client.getIdentifier());
    assert client.getHomeUri().equals(map.get(keys.homeURL()));
    assert client.getScopes().size() == scopes.size();
    for (String scope : scopes) {
        assert client.getScopes().contains(scope) : "returned scopes failed to contain " + scope;
    }
}
Also used : OA2Client(edu.uiuc.ncsa.security.oauth_2_0.OA2Client) JSONObject(net.sf.json.JSONObject) TypeAttribute(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypeAttribute) OA2ClientKeys(edu.uiuc.ncsa.security.oauth_2_0.OA2ClientKeys) LinkedList(java.util.LinkedList) ActionSet(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.actions.ActionSet)

Example 3 with OA2ClientKeys

use of edu.uiuc.ncsa.security.oauth_2_0.OA2ClientKeys in project OA4MP by ncsa.

the class ResponseSerializer method serialize.

protected void serialize(AttributeGetClientResponse response, HttpServletResponse servletResponse) throws IOException {
    PrintWriter pw = servletResponse.getWriter();
    JSONObject json = new JSONObject();
    json.put("status", 0);
    OA2ClientKeys keys = (OA2ClientKeys) cose.getClientStore().getACConverter().getKeys();
    List<String> allKeys = keys.allKeys();
    allKeys.remove(keys.secret());
    OA2Client newClient = (OA2Client) cose.getClientStore().getACConverter().subset(response.getClient(), response.getAttributes());
    JSONObject jsonClient = new JSONObject();
    cose.getClientStore().getACConverter().toJSON(newClient, jsonClient);
    json.put("content", jsonClient);
    // return json;
    pw.println(json);
}
Also used : OA2Client(edu.uiuc.ncsa.security.oauth_2_0.OA2Client) JSONObject(net.sf.json.JSONObject) OA2ClientKeys(edu.uiuc.ncsa.security.oauth_2_0.OA2ClientKeys) PrintWriter(java.io.PrintWriter)

Example 4 with OA2ClientKeys

use of edu.uiuc.ncsa.security.oauth_2_0.OA2ClientKeys in project OA4MP by ncsa.

the class ClientServerTest method testCreatePublicClient.

public void testCreatePublicClient(CMTestStoreProvider tp2) throws Exception {
    // only needs an admin client and map.
    CC cc = setupClients(tp2);
    cc.client.setPublicClient(true);
    tp2.getClientStore().save(cc.client);
    OA2ClientConverter converter = getClientConverter(tp2);
    ColumnMap values = new ColumnMap();
    converter.toMap(cc.client, values);
    tp2.getClientStore().remove(cc.client.getIdentifier());
    assert !tp2.getClientStore().containsKey(cc.client.getIdentifier());
    // remove the identifier and create it
    OA2ClientKeys clientKeys = getClientKeys(tp2);
    values.remove(clientKeys.identifier());
    values.remove(clientKeys.creationTS());
    JSONObject json = new JSONObject();
    json.putAll(values);
    CreateRequest req = RequestFactory.createRequest(cc.adminClient, new TypeClient(), new ActionCreate(), null, json);
    ClientServer server = new ClientServer(tp2.getCOSE());
    CreateResponse resp = (CreateResponse) server.process(req);
    OA2Client newClient = resp.getClient();
    assert tp2.getClientStore().containsKey(newClient.getIdentifier());
    // quick and dirty check
    OA2Client oldClient = (OA2Client) cc.client;
    oldClient.setIdentifier(newClient.getIdentifier());
    oldClient.setSecret(newClient.getSecret());
    assert oldClient.equals(newClient);
}
Also used : ColumnMap(edu.uiuc.ncsa.security.storage.sql.internals.ColumnMap) OA2Client(edu.uiuc.ncsa.security.oauth_2_0.OA2Client) JSONObject(net.sf.json.JSONObject) OA2ClientKeys(edu.uiuc.ncsa.security.oauth_2_0.OA2ClientKeys) TypeClient(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypeClient) OA2ClientConverter(edu.uiuc.ncsa.security.oauth_2_0.OA2ClientConverter)

Example 5 with OA2ClientKeys

use of edu.uiuc.ncsa.security.oauth_2_0.OA2ClientKeys in project OA4MP by ncsa.

the class ClientServerTest method testCreate.

public void testCreate(CMTestStoreProvider tp2) throws Exception {
    // only needs an admin client and map.
    CC cc = setupClients(tp2);
    OA2ClientConverter converter = getClientConverter(tp2);
    ColumnMap values = new ColumnMap();
    converter.toMap(cc.client, values);
    tp2.getClientStore().remove(cc.client.getIdentifier());
    assert !tp2.getClientStore().containsKey(cc.client.getIdentifier());
    // remove the identifier and create it
    OA2ClientKeys clientKeys = getClientKeys(tp2);
    values.remove(clientKeys.identifier());
    values.remove(clientKeys.creationTS());
    JSONObject json = new JSONObject();
    json.putAll(values);
    CreateRequest req = RequestFactory.createRequest(cc.adminClient, new TypeClient(), new ActionCreate(), null, json);
    ClientServer server = new ClientServer(tp2.getCOSE());
    CreateResponse resp = (CreateResponse) server.process(req);
    OA2Client newClient = resp.getClient();
    assert tp2.getClientStore().containsKey(newClient.getIdentifier());
    // quick and dirty check
    OA2Client oldClient = (OA2Client) cc.client;
    oldClient.setIdentifier(newClient.getIdentifier());
    oldClient.setSecret(newClient.getSecret());
    assert oldClient.equals(newClient);
}
Also used : ColumnMap(edu.uiuc.ncsa.security.storage.sql.internals.ColumnMap) OA2Client(edu.uiuc.ncsa.security.oauth_2_0.OA2Client) JSONObject(net.sf.json.JSONObject) OA2ClientKeys(edu.uiuc.ncsa.security.oauth_2_0.OA2ClientKeys) TypeClient(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypeClient) OA2ClientConverter(edu.uiuc.ncsa.security.oauth_2_0.OA2ClientConverter)

Aggregations

OA2ClientKeys (edu.uiuc.ncsa.security.oauth_2_0.OA2ClientKeys)8 OA2Client (edu.uiuc.ncsa.security.oauth_2_0.OA2Client)7 JSONObject (net.sf.json.JSONObject)6 TypeAttribute (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypeAttribute)3 TypeClient (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypeClient)2 OA2ClientConverter (edu.uiuc.ncsa.security.oauth_2_0.OA2ClientConverter)2 ColumnMap (edu.uiuc.ncsa.security.storage.sql.internals.ColumnMap)2 JSONArray (net.sf.json.JSONArray)2 ActionGet (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.actions.ActionGet)1 ActionRemove (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.actions.ActionRemove)1 ActionSet (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.actions.ActionSet)1 ColumnDescriptorEntry (edu.uiuc.ncsa.security.storage.sql.internals.ColumnDescriptorEntry)1 PrintWriter (java.io.PrintWriter)1 LinkedList (java.util.LinkedList)1