Search in sources :

Example 26 with OA2Client

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

the class PermissionServerTest method addClient.

/**
 * Adds a client to the permissions of an admin.
 *
 * @param tp2
 * @throws Exception
 */
public void addClient(CMTestStoreProvider tp2) throws Exception {
    AdminClient adminClient = getAdminClient(tp2.getAdminClientStore());
    OA2Client client = getOa2Client(tp2.getClientStore());
    PermissionServer permissionServer = new PermissionServer(tp2.getCOSE());
    AddClientRequest req = RequestFactory.createRequest(adminClient, new TypePermission(), new ActionAdd(), client, null);
    // AddClientRequest req = new AddClientRequest(adminClient, client);
    AddClientResponse response = (AddClientResponse) permissionServer.process(req);
    PermissionList permissionList = tp2.getPermissionStore().get(adminClient.getIdentifier(), client.getIdentifier());
    try {
        permissionList.canApprove();
        permissionList.canCreate();
        permissionList.canDelete();
        permissionList.canRead();
        permissionList.canWrite();
    } catch (Throwable t) {
        assert false : "failed to have correct permissions";
    }
}
Also used : OA2Client(edu.uiuc.ncsa.security.oauth_2_0.OA2Client) PermissionList(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.permissions.PermissionList) TypePermission(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypePermission) ActionAdd(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.actions.ActionAdd) AdminClient(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.adminClient.AdminClient)

Example 27 with OA2Client

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

the class PermissionTest method testPermission.

public void testPermission(PermissionsStore pStore, ClientStore clientStore, AdminClientStore acStore) throws Exception {
    AdminClient ac = (AdminClient) acStore.create();
    OA2Client c = (OA2Client) clientStore.create();
    Permission p = (Permission) pStore.create();
    p.setAdminID(ac.getIdentifier());
    p.setClientID(c.getIdentifier());
    pStore.save(p);
    assert pStore.hasEntry(ac.getIdentifier(), c.getIdentifier());
    List<Identifier> adminIds = pStore.getAdmins(c.getIdentifier());
    assert adminIds.contains(ac.getIdentifier());
    List<Identifier> clientIDs = pStore.getClients(ac.getIdentifier());
    assert clientIDs.contains(c.getIdentifier());
    // now to ttest for multiple additions
    pStore.save(p);
    pStore.save(p);
    assert pStore.getAdmins(c.getIdentifier()).size() == 1;
    assert pStore.getClients(ac.getIdentifier()).size() == 1;
    OA2Client c1 = (OA2Client) clientStore.create();
    Permission p1 = (Permission) pStore.create();
    p1.setApprove(false);
    p1.setAdminID(ac.getIdentifier());
    p1.setClientID(c1.getIdentifier());
    pStore.save(p1);
    assert pStore.getAdmins(c1.getIdentifier()).size() == 1;
    assert pStore.getClients(ac.getIdentifier()).size() == 2;
}
Also used : OA2Client(edu.uiuc.ncsa.security.oauth_2_0.OA2Client) Identifier(edu.uiuc.ncsa.security.core.Identifier) Permission(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.permissions.Permission) AdminClient(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.adminClient.AdminClient)

Example 28 with OA2Client

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

the class PermissionTest method testIDs.

public void testIDs(PermissionsStore pStore, ClientStore clientStore, AdminClientStore acStore) throws Exception {
    AdminClient ac = (AdminClient) acStore.create();
    AdminClient ac2 = (AdminClient) acStore.create();
    OA2Client c = (OA2Client) clientStore.create();
    Permission p = (Permission) pStore.create();
    p.setAdminID(ac.getIdentifier());
    p.setClientID(c.getIdentifier());
    pStore.save(p);
    p.setAdminID(ac2.getIdentifier());
    System.out.println(p);
    pStore.save(p);
    Permission p2 = (Permission) pStore.get(p.getIdentifier());
    assert p2.getAdminID().equals(ac2.getIdentifier());
    assert pStore.hasEntry(ac2.getIdentifier(), c.getIdentifier());
    assert !pStore.hasEntry(ac.getIdentifier(), c.getIdentifier());
}
Also used : OA2Client(edu.uiuc.ncsa.security.oauth_2_0.OA2Client) Permission(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.permissions.Permission) AdminClient(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.adminClient.AdminClient)

Example 29 with OA2Client

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

the class AttributeServerTest method testAttributeServerRemove.

public void testAttributeServerRemove(CMTestStoreProvider tp2) throws Exception {
    CC cc = setupClients(tp2);
    AttributeServer attributeServer = new AttributeServer(tp2.getCOSE());
    OA2ClientKeys keys = getClientKeys(tp2);
    JSONArray attributes = new JSONArray();
    attributes.add(keys.homeURL());
    attributes.add(keys.email());
    attributes.add(keys.rtLifetime());
    attributes.add(keys.scopes());
    AttributeRemoveRequest req = RequestFactory.createRequest(cc.adminClient, new TypeAttribute(), new ActionRemove(), cc.client, attributes);
    AttributeClientResponse resp = (AttributeClientResponse) attributeServer.process(req);
    OA2Client client = (OA2Client) resp.getClient();
    assert client.getScopes() == null || client.getScopes().isEmpty();
    assert client.getRtLifetime() == 0L;
    assert client.getHomeUri() == null;
    assert client.getEmail() == null;
}
Also used : OA2Client(edu.uiuc.ncsa.security.oauth_2_0.OA2Client) TypeAttribute(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypeAttribute) OA2ClientKeys(edu.uiuc.ncsa.security.oauth_2_0.OA2ClientKeys) JSONArray(net.sf.json.JSONArray) ActionRemove(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.actions.ActionRemove)

Example 30 with OA2Client

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

the class AttributeServerTest method testAttributeServerGet.

public void testAttributeServerGet(CMTestStoreProvider tp2) throws Exception {
    CC cc = setupClients(tp2);
    AttributeServer attributeServer = new AttributeServer(tp2.getCOSE());
    OA2ClientKeys keys = getClientKeys(tp2);
    JSONArray array = new JSONArray();
    array.add(keys.scopes());
    array.add(keys.callbackUri());
    array.add(keys.rtLifetime());
    array.add(keys.name());
    AttributeGetRequest req = RequestFactory.createRequest(cc.adminClient, new TypeAttribute(), new ActionGet(), cc.client, array);
    AttributeClientResponse r = (AttributeClientResponse) attributeServer.process(req);
    OA2Client reducedClient = (OA2Client) r.getClient();
    assert reducedClient.getIdentifier().equals(cc.client.getIdentifier());
    assert reducedClient.getScopes() != null;
    assert reducedClient.getCallbackURIs() != null;
    assert reducedClient.getRtLifetime() == cc.client.getRtLifetime();
    assert reducedClient.getName().equals(cc.client.getName());
    JSONObject json = new JSONObject();
    tp2.getClientStore().getACConverter().toJSON(r.getClient(), json);
    System.out.println(json);
}
Also used : OA2Client(edu.uiuc.ncsa.security.oauth_2_0.OA2Client) ActionGet(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.actions.ActionGet) TypeAttribute(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypeAttribute) JSONObject(net.sf.json.JSONObject) OA2ClientKeys(edu.uiuc.ncsa.security.oauth_2_0.OA2ClientKeys) JSONArray(net.sf.json.JSONArray)

Aggregations

OA2Client (edu.uiuc.ncsa.security.oauth_2_0.OA2Client)31 JSONObject (net.sf.json.JSONObject)10 OA2ClientKeys (edu.uiuc.ncsa.security.oauth_2_0.OA2ClientKeys)7 LinkedList (java.util.LinkedList)7 ColumnMap (edu.uiuc.ncsa.security.storage.sql.internals.ColumnMap)6 LDAPConfiguration (edu.uiuc.ncsa.security.oauth_2_0.server.config.LDAPConfiguration)5 AdminClient (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.adminClient.AdminClient)4 Permission (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.permissions.Permission)4 Identifier (edu.uiuc.ncsa.security.core.Identifier)4 OA2ClientConverter (edu.uiuc.ncsa.security.oauth_2_0.OA2ClientConverter)4 JSONArray (net.sf.json.JSONArray)4 TypeAttribute (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypeAttribute)3 TypePermission (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypePermission)3 ClientApproval (edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval)3 OA2GeneralError (edu.uiuc.ncsa.security.oauth_2_0.OA2GeneralError)3 LDAPEntry (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.cm.ldap.LDAPEntry)2 ActionAdd (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.actions.ActionAdd)2 TypeClient (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypeClient)2 GeneralException (edu.uiuc.ncsa.security.core.exceptions.GeneralException)2 ClaimSource (edu.uiuc.ncsa.security.oauth_2_0.server.ClaimSource)2