Search in sources :

Example 16 with Identifier

use of edu.uiuc.ncsa.security.core.Identifier in project OA4MP by ncsa.

the class OA2ATServlet method getClient.

/**
 * This finds the client identifier either as a parameter or in the authorization header and uses
 * that to get the client. It will also check if the client has been approved and throw an
 * exception if that is not the case. You must separately check the secret as needed.
 *
 * @param request
 * @return
 */
@Override
public Client getClient(HttpServletRequest request) {
    // Check is this is in the headers. If not, fall through to checking parameters.
    OA2Client client = null;
    Identifier paramID = HeaderUtils.getIDFromParameters(request);
    Identifier headerID = null;
    try {
        headerID = HeaderUtils.getIDFromHeaders(request);
    } catch (UnsupportedEncodingException e) {
        throw new NFWException("Error: internal use of UTF-8 encoding failed");
    }
    // cannot hijack the session
    if (paramID == null) {
        if (headerID == null) {
            throw new UnknownClientException("Error: no client identifier given");
        }
        client = (OA2Client) getClient(headerID);
    } else {
        if (headerID == null) {
            client = (OA2Client) getClient(paramID);
        } else {
            if (!paramID.equals(headerID)) {
                throw new UnknownClientException("Error: Too many client identifiers. Cannot resolve client");
            }
            // doesn't matter which id we use since they are equal.
            client = (OA2Client) getClient(paramID);
        }
    }
    checkClientApproval(client);
    return client;
}
Also used : BasicIdentifier(edu.uiuc.ncsa.security.core.util.BasicIdentifier) Identifier(edu.uiuc.ncsa.security.core.Identifier) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 17 with Identifier

use of edu.uiuc.ncsa.security.core.Identifier in project OA4MP by ncsa.

the class PermissionServerTest method testGetClients.

public void testGetClients(CMTestStoreProvider tp2) throws Exception {
    int clientCount = 4;
    CC cc = setupClients(tp2);
    List<OA2Client> clients = new LinkedList<>();
    for (int i = 0; i < clientCount; i++) {
        OA2Client client2 = getOa2Client(tp2.getClientStore());
        Permission p = tp2.getPermissionStore().create();
        p.setDelete(true);
        p.setRead(true);
        p.setApprove(true);
        p.setCreate(true);
        p.setWrite(true);
        p.setAdminID(cc.adminClient.getIdentifier());
        p.setClientID(client2.getIdentifier());
        tp2.getPermissionStore().save(p);
        clients.add(client2);
    }
    clients.add(cc.client);
    // need this list of identifiers later for checking that the returned result is correct.
    List<Identifier> clientIDs = new LinkedList<>();
    for (OA2Client ac : clients) {
        clientIDs.add(ac.getIdentifier());
    }
    PermissionServer permissionServer = new PermissionServer(tp2.getCOSE());
    ListClientsRequest req = (ListClientsRequest) RequestFactory.createRequest(cc.adminClient, new TypePermission(), new ActionList(), null, null);
    ListClientResponse resp = (ListClientResponse) permissionServer.process(req);
    // so add a bunch of admins for a single client and check that they all come back.
    List<OA2Client> returnedACs = resp.getClients();
    assert returnedACs.size() == clients.size();
    for (OA2Client x : returnedACs) {
        assert clientIDs.contains(x.getIdentifier());
    }
}
Also used : LinkedList(java.util.LinkedList) OA2Client(edu.uiuc.ncsa.security.oauth_2_0.OA2Client) Identifier(edu.uiuc.ncsa.security.core.Identifier) TypePermission(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypePermission) TypePermission(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypePermission) Permission(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.permissions.Permission) ActionList(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.actions.ActionList)

Example 18 with Identifier

use of edu.uiuc.ncsa.security.core.Identifier 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 19 with Identifier

use of edu.uiuc.ncsa.security.core.Identifier in project OA4MP by ncsa.

the class CAStoreTest method testApprovalCycle.

@Test
public void testApprovalCycle() throws Exception {
    assert !getApprovalStore().isApproved(BasicIdentifier.newID("foo:bar:baz://" + getRandomString(32)));
    Client client = getClientStore().create();
    Identifier identifier = client.getIdentifier();
    client.setHomeUri("urn:test:/home/uri/" + getRandomString(32));
    client.setSecret(getRandomString(256));
    client.setName("Test client" + getRandomString(32));
    client.setEmail(getRandomString(32) + "@email.foo.edu");
    client.setErrorUri("uri:test:/uh/oh/uri/" + getRandomString(32));
    getClientStore().save(client);
    ClientApproval ca = getApprovalStore().create();
    ca.setApprover("test-approver");
    ca.setApproved(false);
    ca.setApprovalTimestamp(new Date());
    ca.setIdentifier(identifier);
    getApprovalStore().save(ca);
    assert !getApprovalStore().get(client.getIdentifier()).isApproved();
    assert !getApprovalStore().isApproved(identifier);
    ca.setApproved(true);
    getApprovalStore().save(ca);
    // Regression test to be sure that identifiers are never changed.
    assert identifier.equals(ca.getIdentifier());
    assert identifier.equals(client.getIdentifier());
    assert getApprovalStore().get(client.getIdentifier()).isApproved();
    assert getApprovalStore().isApproved(identifier);
    getApprovalStore().remove(client.getIdentifier());
    getClientStore().remove(client.getIdentifier());
}
Also used : BasicIdentifier(edu.uiuc.ncsa.security.core.util.BasicIdentifier) Identifier(edu.uiuc.ncsa.security.core.Identifier) ClientApproval(edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval) Client(edu.uiuc.ncsa.security.delegation.storage.Client) Date(java.util.Date) Test(org.junit.Test)

Example 20 with Identifier

use of edu.uiuc.ncsa.security.core.Identifier in project OA4MP by ncsa.

the class NewCAStoreTest method testApprovalCycle.

public void testApprovalCycle(ClientStore clientStore, ClientApprovalStore caStore) throws Exception {
    assert !caStore.isApproved(BasicIdentifier.newID("foo:bar:baz://" + getRandomString(32)));
    Client client = (Client) clientStore.create();
    Identifier identifier = client.getIdentifier();
    client.setHomeUri("urn:test:/home/uri/" + getRandomString(32));
    client.setSecret(getRandomString(256));
    client.setName("Test client" + getRandomString(32));
    client.setEmail(getRandomString(32) + "@email.foo.edu");
    client.setErrorUri("uri:test:/uh/oh/uri/" + getRandomString(32));
    clientStore.save(client);
    ClientApproval ca = (ClientApproval) caStore.create();
    ca.setApprover("test-approver");
    ca.setApproved(false);
    ca.setApprovalTimestamp(new Date());
    ca.setIdentifier(identifier);
    caStore.save(ca);
    assert !((ClientApproval) caStore.get(client.getIdentifier())).isApproved();
    assert !caStore.isApproved(identifier);
    ca.setApproved(true);
    caStore.save(ca);
    // Regression test to be sure that identifiers are never changed.
    assert identifier.equals(ca.getIdentifier());
    assert identifier.equals(client.getIdentifier());
    assert ((ClientApproval) caStore.get(client.getIdentifier())).isApproved();
    assert caStore.isApproved(identifier);
    caStore.remove(client.getIdentifier());
    clientStore.remove(client.getIdentifier());
}
Also used : BasicIdentifier(edu.uiuc.ncsa.security.core.util.BasicIdentifier) Identifier(edu.uiuc.ncsa.security.core.Identifier) ClientApproval(edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval) Client(edu.uiuc.ncsa.security.delegation.storage.Client) Date(java.util.Date)

Aggregations

Identifier (edu.uiuc.ncsa.security.core.Identifier)33 BasicIdentifier (edu.uiuc.ncsa.security.core.util.BasicIdentifier)18 GeneralException (edu.uiuc.ncsa.security.core.exceptions.GeneralException)5 Client (edu.uiuc.ncsa.security.delegation.storage.Client)5 Asset (edu.uiuc.ncsa.myproxy.oa4mp.client.Asset)4 AdminClient (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.adminClient.AdminClient)4 Permission (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.permissions.Permission)4 OA2Client (edu.uiuc.ncsa.security.oauth_2_0.OA2Client)4 URI (java.net.URI)4 SQLException (java.sql.SQLException)4 LinkedList (java.util.LinkedList)4 OA4MPResponse (edu.uiuc.ncsa.myproxy.oa4mp.client.OA4MPResponse)3 TypePermission (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypePermission)3 ClientApproval (edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval)3 PrivateKey (java.security.PrivateKey)3 Date (java.util.Date)3 ActionList (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.actions.ActionList)2 ValidTimestampPolicy (edu.uiuc.ncsa.security.core.cache.ValidTimestampPolicy)2 UnknownClientException (edu.uiuc.ncsa.security.core.exceptions.UnknownClientException)2 MyLoggingFacade (edu.uiuc.ncsa.security.core.util.MyLoggingFacade)2