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;
}
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());
}
}
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;
}
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());
}
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());
}
Aggregations