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