Search in sources :

Example 1 with OA2ClientConverter

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

the class ClientManagerTest method testOA2Client.

@Test
public void testOA2Client() throws Exception {
    OA2ClientProvider clientProvider = new OA2ClientProvider(new OA4MPIdentifierProvider(OA4MPIdentifierProvider.CLIENT_ID));
    OA2ClientMemoryStore store = new OA2ClientMemoryStore(clientProvider);
    OA2ClientConverter converter = new OA2ClientConverter(clientProvider);
    OA2Client c = getOa2Client(store);
    JSONObject j = new JSONObject();
    converter.toJSON(c, j);
    System.out.println(j);
    Client c2 = converter.fromJSON(j);
    assert c2.equals(c);
}
Also used : OA2Client(edu.uiuc.ncsa.security.oauth_2_0.OA2Client) OA4MPIdentifierProvider(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.transactions.OA4MPIdentifierProvider) OA2ClientProvider(edu.uiuc.ncsa.security.oauth_2_0.OA2ClientProvider) JSONObject(net.sf.json.JSONObject) OA2ClientMemoryStore(edu.uiuc.ncsa.myproxy.oa4mp.oauth2.storage.OA2ClientMemoryStore) Client(edu.uiuc.ncsa.security.delegation.storage.Client) OA2Client(edu.uiuc.ncsa.security.oauth_2_0.OA2Client) OA2ClientConverter(edu.uiuc.ncsa.security.oauth_2_0.OA2ClientConverter) Test(org.junit.Test)

Example 2 with OA2ClientConverter

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

the class ClientManagerTest method testThing.

@Test
public void testThing(ClientStore clientStore) throws Exception {
    // create a request and use the SATFactory to pull it apart.
    JSONObject request = new JSONObject();
    JSONObject requestContent = new JSONObject();
    OA2ClientProvider clientProvider = new OA2ClientProvider(new OA4MPIdentifierProvider(OA4MPIdentifierProvider.CLIENT_ID));
    OA2ClientConverter converter = new OA2ClientConverter(clientProvider);
    JSONObject jsonClient = new JSONObject();
    converter.toJSON(getOa2Client(clientStore), jsonClient);
    requestContent.put(KEYS_SUBJECT, jsonClient);
    JSONObject action = new JSONObject();
    action.put("type", "client");
    action.put("method", ACTION_APPROVE);
    requestContent.put(KEYS_ACTION, action);
    JSONObject jsonClient2 = new JSONObject();
    converter.toJSON(getOa2Client(clientStore), jsonClient2);
    requestContent.put(KEYS_TARGET, jsonClient2);
    request.put(KEYS_API, requestContent);
    System.out.println(SATFactory.getSubject(request));
    System.out.println(SATFactory.getMethod(request));
    System.out.println(SATFactory.getType(request));
    System.out.println(SATFactory.getTarget(request));
    System.out.println(SATFactory.getContent(request));
}
Also used : OA4MPIdentifierProvider(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.transactions.OA4MPIdentifierProvider) JSONObject(net.sf.json.JSONObject) OA2ClientProvider(edu.uiuc.ncsa.security.oauth_2_0.OA2ClientProvider) OA2ClientConverter(edu.uiuc.ncsa.security.oauth_2_0.OA2ClientConverter) Test(org.junit.Test)

Example 3 with OA2ClientConverter

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

the class AttributeServer method setClientAttribute.

protected AttributeClientResponse setClientAttribute(AttributeSetClientRequest request) {
    canWrite(request);
    OA2Client client = (OA2Client) getClientStore().get(request.getClient().getIdentifier());
    OA2ClientConverter clientConverter = (OA2ClientConverter) getClientConverter();
    ColumnMap map = new ColumnMap();
    clientConverter.toMap(client, map);
    for (String key : request.getAttributes().keySet()) {
        // don't let anyone change the identifier.
        if (!key.equals(getClientConverter().getKeys().identifier())) {
            map.put(key, request.getAttributes().get(key));
        }
        if (key.equalsIgnoreCase(clientConverter.getCK2().secret())) {
            // they are changing the secret and we want a hash of this.
            String secret = DigestUtils.sha1Hex(String.valueOf(request.getAttributes().get(key)));
            map.put(key, secret);
        }
    }
    OA2Client updatedClient = getClientConverter().fromMap(map, null);
    getClientStore().save(updatedClient);
    AttributeClientResponse attributeClientResponse = new AttributeClientResponse(updatedClient);
    return attributeClientResponse;
}
Also used : ColumnMap(edu.uiuc.ncsa.security.storage.sql.internals.ColumnMap) OA2Client(edu.uiuc.ncsa.security.oauth_2_0.OA2Client) OA2ClientConverter(edu.uiuc.ncsa.security.oauth_2_0.OA2ClientConverter)

Example 4 with OA2ClientConverter

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

the class ClientManagerTest method testApproveSerialization.

@Test
public void testApproveSerialization(ClientStore clientStore) throws Exception {
    JSONObject request = new JSONObject();
    JSONObject requestContent = new JSONObject();
    OA2ClientProvider clientProvider = new OA2ClientProvider(new OA4MPIdentifierProvider(OA4MPIdentifierProvider.CLIENT_ID));
    OA2ClientConverter converter = new OA2ClientConverter(clientProvider);
    JSONObject jsonClient = new JSONObject();
    converter.toJSON(getOa2Client(clientStore), jsonClient);
    requestContent.put(KEYS_SUBJECT, jsonClient);
    JSONObject action = new JSONObject();
    action.put("type", "client");
    action.put("method", ACTION_APPROVE);
    requestContent.put(KEYS_ACTION, action);
    JSONObject jsonClient2 = new JSONObject();
    converter.toJSON(getOa2Client(clientStore), jsonClient2);
    requestContent.put(KEYS_TARGET, jsonClient2);
    request.put(KEYS_API, requestContent);
}
Also used : OA4MPIdentifierProvider(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.transactions.OA4MPIdentifierProvider) JSONObject(net.sf.json.JSONObject) OA2ClientProvider(edu.uiuc.ncsa.security.oauth_2_0.OA2ClientProvider) OA2ClientConverter(edu.uiuc.ncsa.security.oauth_2_0.OA2ClientConverter) Test(org.junit.Test)

Example 5 with OA2ClientConverter

use of edu.uiuc.ncsa.security.oauth_2_0.OA2ClientConverter 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)

Aggregations

OA2ClientConverter (edu.uiuc.ncsa.security.oauth_2_0.OA2ClientConverter)6 JSONObject (net.sf.json.JSONObject)5 OA2Client (edu.uiuc.ncsa.security.oauth_2_0.OA2Client)4 OA4MPIdentifierProvider (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.transactions.OA4MPIdentifierProvider)3 OA2ClientProvider (edu.uiuc.ncsa.security.oauth_2_0.OA2ClientProvider)3 ColumnMap (edu.uiuc.ncsa.security.storage.sql.internals.ColumnMap)3 Test (org.junit.Test)3 TypeClient (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypeClient)2 OA2ClientKeys (edu.uiuc.ncsa.security.oauth_2_0.OA2ClientKeys)2 OA2ClientMemoryStore (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.storage.OA2ClientMemoryStore)1 Client (edu.uiuc.ncsa.security.delegation.storage.Client)1